-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathoperation_on_strings.cpp
110 lines (99 loc) · 2.87 KB
/
operation_on_strings.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>
#include<string.h>
using namespace std;
int main()
{
int n;
char a[100],b[100];
cout<<"::::::::::::::::::::: MENU DRIVEN PROGRAM :::::::::::::::::::::\n\n";
cout<<" Program to perform following operations on String :-\n\n";
cout<<"\t 1.)Concatenate two Strings. \n";
cout<<"\t 2.)Compare two strings. \n";
cout<<"\t 3.)Calaulate the lenght of the strings. \n";
cout<<"\t 4.)Convert lowercase to uppercase. \n";
cout<<"\t 5.)Convert uppercase to lower case. \n";
cout<<"\t 6.)Calculate number of Vowels. \n";
cout<<"\t 7.)Find a substring in a given string. \n\n";
cout<<"\t\t CHOOSE THE OPERATION :-- ";
cin>>n;
cout<<"\n===================================================================\n\n";
if(n==1)
{
cout<<"ENTER FIRST STRING:--";
cin>>a;
cout<<"ENTER SECOND STRING:--";
cin>>b;
strcat(a,b);
cout<<"\n\t After Concatinating above strings :--"<<a;
}
else if(n==2)
{
cout<<"ENTER FIRST STRING:--";
cin>>a;
cout<<"ENTER SECOND STRING:--";
cin>>b;
if(strcmp(a,b)==0)
{
cout<<"\n\t STRINGS ARE EQUAL \n";
}else
{
cout<<"\n\t STRINGS ARE NOT EQUAL \n";
}
}
else if(n==3)
{
cout<<"ENTER THE STRING:--";
cin>>a;
int len;
len=strlen(a);
cout<<"\n\tTHE LENGHT OF GIVEN STRING IS :-- "<<len;
}
else if(n==4)
{
cout<<"Enter the String :-- ";
cin>>a;
for(int i=0;i<=strlen(a);i++)
{
if(a[i]>=97 && a[i]<=122)
{
a[i]=a[i]-32;
}
}
cout<<"\n The entered string in uppercase: "<<a;
}
else if(n==5)
{
cout<<"Enter the String :-- ";
cin>>a;
for(int i=0;i<=strlen(a);i++)
{
if(a[i]>=65 && a[i]<=92)
{
a[i]=a[i]+32;
}
} cout<<"\n The entered string in lowercase: "<<a;
}
else if(n==6)
{
int n,s=0;
cout<<"Enter the String :-- ";
cin>>a;
n=strlen(a);
for(int i=0;i<n;++i)
{
if(a[i]=='a'||a[i]=='e'||a[i]=='i'||a[i]=='o'||a[i]=='u')
{
s=s+1;
}
}
cout<<"Number of Vowels in the given String is :--"<<s;
}
else if(n==7)
{
}
else
{
cout<<"\n ERROR !!! ENTER THE NUMBER BETWEEN GIVEN CHOICES \n";
}
cout<<"\n\n__________________________________________________________________________________________\n\n";
}