Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
36 views8 pages

Problem Set 8

The document contains code for multiple C++ programs that analyze strings. The first program checks if a string is a palindrome. The second counts the characters in a string. The third extracts words from a string. The fourth replaces vowels in a string with asterisks.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views8 pages

Problem Set 8

The document contains code for multiple C++ programs that analyze strings. The first program checks if a string is a palindrome. The second counts the characters in a string. The third extracts words from a string. The fourth replaces vowels in a string with asterisks.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Problem set 8

#include <iostream>
#include <cstdlib>
using namespace std;

string reverse1 (string str){

string s ="";
int size = str.size();
for (int i=size-1; i>=0; i--){

s = s+ str[i];
}

return s;

int main (){

string s ;
cout<<"enter a word"<<endl;
getline(cin,s);

if((reverse1(s))== s) {cout<<"palindrome";}

else{cout<<"not"<<endl;}

return 0;
}

#include <iostream>
#include <string>

using namespace std;

int counts (string str){


string s ="";
int c =0;
int size = str.size();
for (int i=0; i<size; i++){
if (!(str[i] == ' ')) {c++;}

return c ;

int main()
{
string s;
getline (cin,s);
cout<<s<<endl;

cout<< counts(s)<<endl;

}
#include <iostream>
#include <string>

using namespace std;

int counts (string str){


string s ="";
int c =0;
int size = str.size();
for (int i=0; i<size; i++){

if (!(str[i] == ' ')) {c++;}

return c ;

}
int main()
{
string s;
getline (cin,s);
cout<<s<<endl;

cout<< counts(s)<<endl;

#include <iostream>
#include <string>

using namespace std;

string getword (string str, int a, int b){


string s = " ";
for (int i=a; i<b ;i++){

s = s+ str[i];
}
return s;

void name (string str){


string s ="";
int size = str.size();
int j=size;
for (int i=size; i>=0;i--){

if (str[i]==' ') {cout<<getword(str,i,j);}

}
}

int main()
{
string s;
getline(cin,s);
name(s);
cout<<","<<s[0]<<"."<<endl;
}

3
#include <iostream>
#include <string>

using namespace std;

void getvowels (string str){

string s = "";
int size = str.size();

for (int i=0; i<size; i++){

if ((str[i] == 'a')|| (str[i] =='e')|| (str[i] == 'i') || (str[i] == 'o')|| (str[i]=='u') ) {


str [i] = '*s';
}

cout<<str[i];
}
}

int main()
{
string s;
getline (cin,s);

getvowels(s);
}

You might also like