Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(Use the string class to solve the problem) Write a program that can be used to

ID: 3837470 • Letter: #

Question

(Use the string class to solve the problem)

Write a program that can be used to train the user to use less sexist language by suggesting alternative versions of sentences given by the user. The program will ask for a sentence, read the sentence into a string variable, and replace all occurrences of masculine pronouns with gender-neutral pronouns. For example, it will replace “he” with “she or he”, and “him” with “her or him”. Thus, the input sentence

See an adviser, talk to him, and listen to him.

should produce the following suggested changed version of the sentence:

See an adviser, talk to her or him, and listen to her or him.

Be sure to preserve uppercase letters for the first word of the sentence. The pronoun “his” can be replaced by “her(s) or his”; your program need not decide between “her” and “hers”. Allow the user to repeat this for more sentences until the user says she or he is done.

You need to take care of the following string replacements:

he/she -> she or he

him/her -> her or him

his/her(s) -> her(s) or his

Explanation / Answer

#include <iostream>

#include <string>

#include <cctype>

#include <vector>

using namespace std;

int main()

{

char ans = 'y';

string aString,fString;

cout << "AntiSexist - By Kudy" << endl;

do{

cout << "Enter a line,I'll censor : ";

getline(cin,aString);

int aLength = aString.length();

for(int j=0;j<aLength;j++)

aString[j]=tolower(aString[j]);

if(aLength <= 3 && aLength >0)

{

cout << "Length <= 3,unable to convert -> may be grammatically incorrect !" << endl;

for(int k=0;k<aLength;k++)

fString += aString[k];

};

for(int i=0;i<aLength && aLength>3;i++)

if((aString[i]=='h') && (aString[i+1]!=' ' && aString[i+2]!=' '))

{

fString += "h";

if(i==0)

{

string test = aString.substr(i,4);

if((test[1]=='i'&&test[2]=='m')||(test[1]=='e'&&test[2]=='r'))

if(test[3]==' ')

{

fString += "im or her";

i+=2;

}

}else{

string test = aString.substr(i-1,5);

if((test[2]=='i'&&test[3]=='m')||(test[2]=='e'&&test[3]=='r'))

if(test[0]==' ' && test[0]==' ')

{

fString += "im or her";

i+=2;

}

};

}else

fString += aString[i];

cout << fString << endl;

cout << "Again (Y/N) ?";cin >> ans;

}while(ans=='y'|| ans=='Y');

return 0;

}

E

#include <iostream>

#include <string>

#include <cctype>

#include <vector>

using namespace std;

int main()

{

char ans = 'y';

string aString,fString;

cout << "AntiSexist - By Kudy" << endl;

do{

cout << "Enter a line,I'll censor : ";

getline(cin,aString);

int aLength = aString.length();

for(int j=0;j<aLength;j++)

aString[j]=tolower(aString[j]);

if(aLength <= 3 && aLength >0)

{

cout << "Length <= 3,unable to convert -> may be grammatically incorrect !" << endl;

for(int k=0;k<aLength;k++)

fString += aString[k];

};

for(int i=0;i<aLength && aLength>3;i++)

if((aString[i]=='h') && (aString[i+1]!=' ' && aString[i+2]!=' '))

{

fString += "h";

if(i==0)

{

string test = aString.substr(i,4);

if((test[1]=='i'&&test[2]=='m')||(test[1]=='e'&&test[2]=='r'))

if(test[3]==' ')

{

fString += "im or her";

i+=2;

}

}else{

string test = aString.substr(i-1,5);

if((test[2]=='i'&&test[3]=='m')||(test[2]=='e'&&test[3]=='r'))

if(test[0]==' ' && test[0]==' ')

{

fString += "im or her";

i+=2;

}

};

}else

fString += aString[i];

cout << fString << endl;

cout << "Again (Y/N) ?";cin >> ans;

}while(ans=='y'|| ans=='Y');

return 0;

}

E