-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPQ4.cpp
110 lines (93 loc) · 3.28 KB
/
PQ4.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include<iostream>
using namespace std ;
int main(){
char i='\0';
while(1){
cout<<" ****** MAIN MENUE ****** "<<endl;
cout<<"A. show address of each character of string "<<endl;
cout<<"B. add two string "<<endl;
cout<<"C. comparision of string "<<endl;
cout<<"D. length of string "<<endl;
cout<<"E. convert into uppercase "<<endl;
cout<<"F. revese of string "<<endl;
cout<<"G. EXIT"<< endl;
cin>>i;
switch(i){
case 'a':{
string str,lock;
cout<<"Enter the string: ";
getline(cin,lock);
getline(cin,str);
int n= str.size();
for (int i=0; i<n; i++){
cout<<"Address of "<<str[i]<<" is "<<static_cast<void*>(&str[i])<<endl;
}
break;}
case 'b':{
string str1, str2,lock;
cout<<"Enter 1st string: "<<endl;
getline(cin,lock);
getline(cin,str1);
cout<<"Enter 2nd string: "<<endl;
getline(cin,str2);
cout<<"Concatenated string is "<<str1+" "+str2<<endl;
break;}
case 'c':{
string str1, str2,lock;
cout<<"Enter the first string: "<<endl;
getline(cin,lock);
getline(cin,str1);
cout<<"Enter the second string: "<<endl;
getline(cin,str2);
int n1= str1.size();
int n2= str2.size();
if (n1 > n2){
cout<<"First string is greater \n\n";
}else if(n2 > n1){
cout<<"Second string is greater \n\n";
}else{
cout<<"Both strings are equal \n\n";
}
break;}
case 'd': {
string str,lock;
cout<<"Enter the string: ";
getline(cin,lock);
getline(cin,str);
cout<<"The size of string is "<<str.size()<<endl;
break;}
case 'e': {
string str1,lock;
cout << "\nPlease Enter the String to Convert into Uppercase = ";
getline(cin,lock);
getline(cin, str1);
for (int i = 0; i < str1.length(); i++)
{
str1[i] = toupper(str1[i]);
}
cout<< "\nThe Given String in Uppercase = " << str1 <<"\n\n";
break;}
case 'f': {
string str,lock;
cout<<"Enter the string: "<<endl;
getline(cin,lock);
getline(cin,str);
string s="";
int n= str.size()-1;
for (int i=0; i<str.size(); i++){
s= s + str[n];
n--;
}
cout<<"Reverse string of "<<str<<" is "<<s<<endl;
break;}
case 'g': {
return 0;
break;
}
default: {
cout<<"Invalid option";
}
}
}
return 0;
}