Respuesta :
Answer
//include header files
#include<iostream>
#include<string>
#include<cstdlib>
#include<cmath>
using namespace std;
string sWord[]={"he", "him","his"};
string sword1[]={"she or he","her or him", "hers or his"};
//Return true if ch is alphabet
bool IsAlphabet(char ch)
{
if(((ch>='A') &&( ch<='Z'))||((ch>='a') && (ch<='z')))
return true;
return false;
}
//replace gender word
string replaceStrWord(string word)
{
string rep="";
for(int kk=0;kk<3;kk++)
{
if(sWord[kk]==word)
{
rep=sword1[kk];
}
}
if(rep.compare("")==0)
rep=word;
return rep;
}
//main()
int main()
{
string output="";
char next_symbol;
string word="";
//Repeat until user done;
while(true)
{
output="";
//Loop to get entire sentence
do
{
word="";
//Loop to get word
while(true)
{
cin.get(next_symbol);
if(IsAlphabet(next_symbol))
{
word+=next_symbol;
}
else
{
break;
}
};
if(word.compare("done")==0)
break;
output=output+replaceStrWord(word);
output=output+next_symbol;
}while(next_symbol!='\n');
cout<<"Replaced String:"<<output<<endl;
string userdone="";
cout<<"Do u wantto continue:";
cin>>userdone;
if(userdone=="no")
break;
cin.ignore();
}
return 0;
}