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".
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()
In c++ Write a function that: accepts a string and an integer as it's only arguments...
In c++ Write a function that: accepts a string and an integer as it's only arguments uses the argument to open a file for writing writes the integer to the file if it fails to open the file, returns -1 if it succeeds in opening the file, returns 0 does not interact with the user in any way does not use global variables
In Java, Here is a basic Name class. class Name { private String first; private String...
In Java, Here is a basic Name class. class Name { private String first; private String last; public Name(String first, String last) { this.first = first; this.last = last; } public boolean equals(Name other) { return this.first.equals(other.first) && this.last.equals(other.last); } } Assume we have a program (in another file) that uses this class. As part of the program, we need to write a method with the following header: public static boolean exists(Name[] names, int numNames, Name name) The goal of...
Code in C++ Objectives Use STL vector to create a wrapper class. Create Class: Planet Planet...
Code in C++ Objectives Use STL vector to create a wrapper class. Create Class: Planet Planet will be a simple class consisting of three fields: name: string representing the name of a planet, such as “Mars” madeOf: string representing the main element of the planet alienPopulation: int representing if the number of aliens living on the planet Your Planet class should have the following methods: Planet(name, madeOf, alienPopulation) // Constructor getName(): string // Returns a planet’s name getMadeOf(): String //...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT