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...
SOLVE IN C: 6.31 LAB: Print string in reverse Write a program that takes in a...
SOLVE IN C: 6.31 LAB: Print string in reverse Write a program that takes in a line of text as input, and outputs that line of text in reverse. You may assume that each line of text will not exceed 50 characters.The program repeats, ending when the user enters "Quit", "quit", or "q" for the line of text. Ex: If the input is: Hello there Hey quit then the output is: ereht olleH yeH Hint: Use the fgets function to...
(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.
please use python to solve this problem. Math and String operations Write a script to perform...
please use python to solve this problem. Math and String operations Write a script to perform various basic math and string operations. Use some functions from Python's math module. Generate formatted output. Basic math and string operations Calculate and print the final value of each variable. a equals 3 to the power of 2.5 b equals 2 b equals b + 3 (use +=) c equals 12 c = c divided by 4 (use /=) d equals the remainder of...
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...
Use C++ to write a program that reads in a binary string from the command line...
Use C++ to write a program that reads in a binary string from the command line and applies the following (00, 1101) tag-system: if the first bit is 0, deletes the first three bits and append 00; if the first bit is 1, delete the first three bits and append 1101. Repeat as long as the string has at least 3 bits. Try to determine whether the following inputs will halt or go into an infinite loop: 10010, 100100100100100100. Use...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT