-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstring_operations
68 lines (68 loc) · 1.25 KB
/
string_operations
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
#include<iostream>
using namespace std;
int length(string s1)
{
int i=0;
while(s1[i]!='\0')
i++;
cout<<"length of the string is "<<i<<"\n";
return i;
}
void string_con(string s1)
{
string s2;
cout<< "enter the second string to concat ";
cin>>s2;
s2=s1+s2;
cout<<s2<<"\n";
}
void string_copy(string s1)
{
string s2;
s2=s1;
cout<<"s1 is copied to s2 \n ITS VALUE IS = "<<s2<<"\n";
}
void string_reverse(string s1,int len)
{
int i;
for(i=len-1;i>=0;i--)
cout<<s1[i];
}
int main(){
int len;
string s1;
cout<<"enter the string ";
cin>>s1;
int choice;
while(1){
cout<<"\nChoose the string operation,\n";
cout<<"1. length\n";
cout<<"2. concatination\n";
cout<<"3. copy\n";
cout<<"4. reversing\n";
cout<<"5. Exit\n";
cout<<"Enter your choice: ";
cin>>choice;
switch (choice) {
case 1:
len=length(s1);
break;
case 2:
string_con(s1);
break;
case 3:
string_copy(s1);
break;
case 4:
string_reverse(s1,len);
break;
case 5:
cout<<"Thank You.\n";
exit(0);
default:
cout<<"Invalid input.\n";
cout<<"Please enter the correct input.\n";
}
}
return 0;
}