Question

In: Computer Science

(Use the string class to solve the problem) Write a program (in c++) that can be...

(Use the string class to solve the problem)

Write a program (in c++) 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”.

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

Solutions

Expert Solution

#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);

                //My algorithm : Find the h,take 3 letter,check 2 whitespaces,correct

                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]!='\n' && aString[i+2]!='\n'))

                                {

                                                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;

}


Related Solutions

(Use the String Class to Solve This (and only the iostream, string and cctype libraries)) Write...
(Use the String Class to Solve This (and only the iostream, string and cctype libraries)) 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...
(USE C ++ AND class STRING ONLY!!!! No java, No cstring and No vector) Write a...
(USE C ++ AND class STRING ONLY!!!! No java, No cstring and No vector) 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 genderneutral pronouns. For example, it will replace "he" with "she or he". Thus, the input sentence See an...
Can you solve this C program by using Function? Q1. Write a C program to ring...
Can you solve this C program by using Function? Q1. Write a C program to ring the computer bell at any number of times you specify. Use the system clock as a delay, you need to include the time header file.
Write a C++ Program Write a program that prompts the user to input a string. The...
Write a C++ Program Write a program that prompts the user to input a string. The program then uses the function substr to remove all the vowels from the string. For example, if str=”There”, then after removing all the vowels, str=”Thr”. After removing all the vowels, output the string. Your program must contain a function to remove all the vowels and a function to determine whether a character is a vowel. You must insert the following comments at the beginning...
use C++ Write a program to calculate the frequency of every letter in an input string...
use C++ Write a program to calculate the frequency of every letter in an input string s. Your program should be able to input a string. Calculate the frequency of each element in the string and store the results Your program should be able to print each letter and its respective frequency. Identify the letter with the highest frequency in your message. Your message should be constructed from at least 50 letters. Example of Output: letters frequency a 10 b...
Write a C program that can search for a string within a text file, replace it...
Write a C program that can search for a string within a text file, replace it with another string and put results in a new file.
Write a C program that will read a character string and then encrypt the string based...
Write a C program that will read a character string and then encrypt the string based on one of the 3 different encryption methods. The type of encryption is to be selected by the user. Encryption method 1: Swapping by position. Characters in the array are swapped with the opposite characters based on their position in the string. Example: Input string – apple. Encrypted string – elppa Method: The first character ‘a’ and the last character ‘e’ – swap their...
C++ code Write a program to illustrate how to use the temporary class. Your program must...
C++ code Write a program to illustrate how to use the temporary class. Your program must contain statements that would ask the user to enter data of an object and use the setters to initialize the object. Use three header files named main.cpp, temporary.h, and temporaryImp.cpp An example of the program is shown below: Enter object name (rectangle, circle, sphere, or cylinder: circle Enter object's dimensions: rectangle (length and width) circle (radius and 0) sphere (radius and 0) rectangle (base...
Write a case you can use PCR to solve the problem and also write a case...
Write a case you can use PCR to solve the problem and also write a case you cannot use PCR to solve to problem
Write a program that inputs a string that represents a binary number. The string can contain...
Write a program that inputs a string that represents a binary number. The string can contain only 0s and 1s and no other characters, not even spaces. Validate that the entered number meets these requirements. If it does not, display an error message. If it is a valid binary number, determine the number of 1s that it contains. If it has exactly two 1s, display "Accepted". Otherwise, display "Rejected". All input and output should be from the console. Examples of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT