Question

In: Computer Science

(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 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

Solutions

Expert Solution

#include <iostream>
#include <stdio.h>
#include <string>
#include <cctype>
#include <vector>

using namespace std;


int main()
{
   char ans='y';
   while(1)
   {
   string str1,str2;
   cout << "Enter a string: ";
   getline(cin,str1);
       int len = str1.length();
   for(int j=0;j<len;j++)
       str1[j]=tolower(str1[j]);
   if(len <= 3 && len >0)
   {
       cout << "Length of string is too short!!!!" << endl;
       for(int k=0;k<len;k++)
           str2 += str1[k];
   };
   for(int i=0;i<len && len>3;i++)
       if((str1[i]=='h') && (str1[i+1]!='\n' && str1[i+2]!='\n'))
       {
           if(i==0)
           {
               string s = str1.substr(i,4);
               if((s[1]=='i'&&s[2]=='m')||(s[1]=='e'&&s[2]=='r'))
                   if(s[3]==' ')
                   {
                   str2 += "her or him";
                       i+=2;
                   }
           }
           else
           {
               string s = str1.substr(i-1,5);
               if((s[2]=='i'&&s[3]=='m')||(s[2]=='e'&&s[3]=='r'))
                   if(s[0]==' ' && s[0]==' ')
                   {
                       str2 += "her or him";
                       i+=2;
                   }
                   if((s[2]=='i'&&s[3]=='s'))
                   if(s[0]==' ' && s[0]==' ')
                   {
                       str2 += "her(s) or his";
                       i+=2;
                   }
                   if((s[2]=='e'))
                   if(s[0]==' ' && s[0]==' ')
                   {
                       str2 += "she or he";
                       i+=1;
                   }
           };
       }
       else str2 += str1[i];
       str2[0]=toupper(str2[0]);
   cout << str2 << endl;
   cout << "Again (Y/N) ?";
   cin >> ans;
   cin.ignore();
   if(ans=='n'|| ans=='N') break;
   }
   return 0;
}


Related Solutions

Complete the following task in C++. You may use the following libraries cstdlib, string, iostream. 1...
Complete the following task in C++. You may use the following libraries cstdlib, string, iostream. 1 dLL The class is described according to the simple UML diagram below: dLL<T> -head: item<T>* -tail: item<T>* -size: int ---------------------------- +dLL() +~dLL() +getHead(): item<T>* +getTail(): item<T>* +push(newItem:item<T>*):void +pop():item<T>* +getItem(i:int):item<T>* +minNode():T +getSize():int +printList():void The class variables are as follows: head: The head pointer of the doubly linked list. tail: The tail pointer of the doubly linked list. size: The current size of the doubly linked...
(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...
(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...
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...
Please write code in c++. Use iostream (and any string library if you need it). Create...
Please write code in c++. Use iostream (and any string library if you need it). Create s structure plane : First line contains n(0 < n < 1001). Then n lines inputed in given format:   First - ID[int type]   Second - FromLocation[char*]   Third - ToLocation[char*]   Fourth - DepartureTime[char*] Output: Sorted list of planes should be in UPPER CASE. Example of input:(it's just one of an examples, you need to write code generally) 10 40 Shuch Satp 05:47 89 Kyzy Taldy  07:00...
Please solve in C++ only class is not templated You need to write a class called...
Please solve in C++ only class is not templated You need to write a class called LinkedList that implements the following List operations: public void add(int index, Object item); // adds an item to the list at the given index, that index may be at start, end or after or before the // specific element 2.public void remove(int index); // removes the item from the list that has the given index 3.public void remove(Object item); // finds the item from...
In C++ Please, using only the libraries given in this homework prompt, Write a program that...
In C++ Please, using only the libraries given in this homework prompt, Write a program that (1) prompts for two integers, (2) prints out their sum, (3) prints out the first divided by the second, and (4) prints out the natural log of the first number raised to the power of the second number. #include <iostream> #include <iomanip> using namespace std; int main() { <your answer goes here> return 0; }
Please write code in c++ using iostream library. Also you can use any string library. Create...
Please write code in c++ using iostream library. Also you can use any string library. Create structure plane with the following: 1)plane's ID[int type] 2) location[char*] 3) departure time[char*] Your task is to find the plane with the smallest departure time for the selected city. Pointer, dynamic array and structures have to be used in this code. Input: NOTE: It's just an example of input, you should write code generally for any inputs. First line contains n(0 < n <...
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...
#include <iostream> #include <string> #include <vector> using namespace std; class Song{ public: Song(); //default constructor Song(string...
#include <iostream> #include <string> #include <vector> using namespace std; class Song{ public: Song(); //default constructor Song(string t, string a, double d); //parametrized constructor string getTitle()const; // return title string getAuthor()const; // return author double getDurationMin() const; // return duration in minutes double getDurationSec() const; // return song's duration in seconds void setTitle(string t); //set title to t void setAuthor(string a); //set author to a void setDurationMin(double d); //set durationMin to d private: string title; //title of the song string author;...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT