Question

In: Computer Science

(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 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)"; 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.

This will be a long program that requires a good deal of patience. Your program should not replace the string "he" when it occurs inside another word, such as "here". A word is any string consisting of the letters of the alphabet and delimited at each end by a blank, the end of the line, or any other character that is not a letter. Allow your sentences to be up to 100 characters long.

Solutions

Expert Solution

#include <iostream>

#include <string>

#include <cctype>

using namespace std;

int main()

{

char ans = 'y';

string aString,fString;

//do{

cout << "Enter a line : ";

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 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...
Using only core C++ (no special libraries, except STL vector or string if you want), write...
Using only core C++ (no special libraries, except STL vector or string if you want), write a C++ program that allows a user to input a string and (a) Checks if the expression is a valid polynomial. Parentheses or negation are not allowed. Spaces should be ignored. E.g., the following are valid i. n^2+2*n+5 ii. 2*n + 4.54* n^5 +4 +5*n and the following are invalid iii. n^3n iv. n^4.2 v. 5n vi. n^3 -3*n if an input is given...
All the answer need to be in C++ 1) Write a class for a "Vector". The...
All the answer need to be in C++ 1) Write a class for a "Vector". The members of the class will be: Data: int data[100]; methods: void inserts(int element); int remove(); int getsize(); bool is empty(): ------------------------------------------------------------------------------------------------------- 2) Using your vector class, create an object using a regular instantiation and a pointer instantiation. What are the advantages and disadvantages of both approaches? ------------------------------------------------------------------------------------------------------- 3) What does the following function do and write a program that uses the function: int foo(int...
Write a function in c++, called afterAll that takes two parameters, a vector of string and...
Write a function in c++, called afterAll that takes two parameters, a vector of string and a string. The function returns true if the 2nd parameter comes after all of the strings in the vector, order-wise, false if not. As an example, "zoo" comes after "yuzu".
C++ ONLY! Implement the find function for the List class. It takes a string as an...
C++ ONLY! Implement the find function for the List class. It takes a string as an argument and returns an iterator to a matching node. If no matching node, it returns a null iterator. #include <iostream> #include <cstddef> #include <string> using Item = std::string; class List { private: class ListNode { public: Item item; ListNode * next; ListNode(Item i, ListNode *n=nullptr) { item = i; next = n; } };    ListNode * head; ListNode * tail;    public: class...
Please write code in java and comment . thanks Item class A constructor, with a String...
Please write code in java and comment . thanks Item class A constructor, with a String parameter representing the name of the item. A name() method and a toString() method, both of which are identical and which return the name of the item. BadAmountException Class It must be a RuntimeException. A RuntimeException is a subclass of Exception which has the special property that we wouldn't need to declare it if we need to use it. It must have a default...
Java - Write an abstract class called Shape with a string data field called colour. Write...
Java - Write an abstract class called Shape with a string data field called colour. Write a getter and setter for colour. Write a constructor that takes colour as the only argument. Write an abstract method called getArea()
Please, write this code in c++. Using iostream and cstring library. Write a function that will...
Please, write this code in c++. Using iostream and cstring library. Write a function that will delete all words in the given text that meets more that one time. Also note than WORD is sequence of letters sepereated by whitespace. Note. The program have to use pointer. Input: First line contains one line that is not longer than 1000 symbols with whitespaces. Each word is not longer than 30 symbols. Output: Formatted text. example: input: Can you can the can...
Please, write code in c++. Using iostream and cstring library Use pointers! You given a text.Your...
Please, write code in c++. Using iostream and cstring library Use pointers! You given a text.Your task is to write a function that will find the longest sequence of digits inside. Note that the output have to be presened just like in sample. Note. The program have to use pointer. Input: First line contains one line that is not longer than 1000. Output: The longest sequence of numbers.All numbers are positive and integers. Samples: № INPUT OUTPUT 1 This is...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT