-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ3.cpp
More file actions
69 lines (50 loc) · 1.92 KB
/
Copy pathQ3.cpp
File metadata and controls
69 lines (50 loc) · 1.92 KB
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
#include <iostream>
#include <string>
#include <map>
using namespace std;
int main() {
string string_of_characters,n;
//1)Accept string from user
cout<<"Enter set of meaninful or non-meaningful characters :";
getline(cin,string_of_characters);
cout<<"\n"<<"You entered : "<<string_of_characters<<endl;
cout<<"Length of your entered string : "<<string_of_characters.length()<<endl;
string m=string_of_characters;
//2)Checking for palindrome or not
for (int i=m.length()-1;i>=0;i=i-1) {
n=n+string_of_characters[i];
}
cout<<"Entered string in reverse order : "<<n<<endl;
for(int i=0;i<m.length();i=i+1) {
m[i]=toupper(m[i]);
n[i]=toupper(n[i]);
}
cout<<"Coversion of forward string to upper case letters : "<<m<<endl;
cout<<"Coversion of reverse string to upper case letters : "<<n<<endl;
if (n==m) {
cout<<"Palindrome"<<endl;
}
else {
cout<<"Not Palindrome"<<endl;
}
//3)Frequency of each word
map<char, int> charFreq;
for (char c : string_of_characters) {
c = tolower(c);
if (isalpha(c)) {
++charFreq[c];
}
}
for (const auto&pair : charFreq) {
cout<<pair.first<<": "<<pair.second <<endl;
}
//4)Replace all vowels with a character
for(int i=0;i<string_of_characters.length();i=i+1) {
if (string_of_characters[i]=='a' || string_of_characters[i]=='e' || string_of_characters[i]=='i' || string_of_characters[i]=='o' || string_of_characters[i]=='u'
|| string_of_characters[i]=='A' || string_of_characters[i]=='E' || string_of_characters[i]=='I' || string_of_characters[i]=='O' || string_of_characters[i]=='U' ) {
string_of_characters[i]='*';
}
}
cout<<"Entered string after replacing all vowels by * : "<<string_of_characters;
return 0;
}