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

(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 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 <...
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; }
#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;...
Write the following questions as queries in SQL. Use only the operators discussed in class (no...
Write the following questions as queries in SQL. Use only the operators discussed in class (no outer joins) Consider the following database schema: INGREDIENT(ingredient-id,name,price-ounce) RECIPE(recipe-id,name,country,time) USES(rid,iid,quantity) where INGREDIENT lists ingredient information (id, name, and the price per ounce); RECIPE lists recipe information (id, name, country of origin, and time it takes to cook it); and USES tells us which ingredients (and how much of each) a recipe uses. The primary key of each table is underlined; rid is a foreign...
Debug please. It's in C++ #include<iostream> #include<string> using namespace std; class Prescription {    friend ostream&...
Debug please. It's in C++ #include<iostream> #include<string> using namespace std; class Prescription {    friend ostream& operator<<(ostream&, const Prescription&);    friend istream& operator>>(istream&, Prescription&);    private: int idNum; int numPills; double price;    public: Prescription(const int = 0, const int = 0, const double = 0.0); }; Prescription::Prescription(const int id, const int pills, const double p) {    id = id;    numPills = pills;    price = p; } ostream& operator<<(ostream& out, const Prescription pre) {    out <<...
#include <iostream> #include <string> #include <iomanip> #include <cstdlib> #include "Contact.h" using namespace std; class Contact {...
#include <iostream> #include <string> #include <iomanip> #include <cstdlib> #include "Contact.h" using namespace std; class Contact { public: Contact(string init_name = "", string init_phone = "000-000-0000"); void setName(string name); void setPhone(string phone); string getName()const; string getPhone()const; friend ostream& operator << (ostream& os, const Contact& c); friend bool operator == (const Contact& c1, const Contact& c2); friend bool operator != (const Contact& c1, const Contact& c2); private: string name, phone; }; Contact::Contact(string init_name, string init_phone) { name = init_name; phone = init_phone;...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT