Question

In: Computer Science

modify this program to either simulate a teacher or used car salesperson. #include <iostream> #include <string>...

modify this program to either simulate a teacher or used car salesperson.

#include <iostream>
#include <string>
using namespace std;
int Menu(string a, string b, string c)
{ int choice =-1;
cout<<" 1)"<<a<<endl;
cout<<" 2)"<<b<<endl;
cout<<" 3)"<<c<<endl;
cout<<" 4) I don't want to talk to you!!"<<endl;
cin>>choice;
return choice;
}
int Money(int x)
{ int c=-1;
cout<<"\n Are you that materialistic? \n";
c = Menu(" No.", " Yes.", " Can we talk about something else?");
if(c == 1|| c ==2 )
c=-1;
else if (c == 3 )
c =3;
return c;
}
int Relationship(int x)
{ int c=-1;
cout<<"\n What is your relationship like with this person?\n";
c = Menu(" Like, my best friend.", " We are not really that close.", " Can we talk about something else?");
if(c == 1|| c ==2 )
c=-1;
else if (c == 3 )
c =3;
return c;
}
int Work(int x)
{ int choice=-1;
cout<<"\n What is going on at your job? \n";
choice = Menu(" The boss is a great!", " I just got a raise.", " There is this really cute collegue.");
if(choice == 1|| choice ==3 )
choice = Relationship(choice);
else if (choice == 2 )
choice = Money(choice);
return choice;
}
int main()
{ int answer=-1;
cout<<"\n Hi! How are you feeling today? \n";
answer = Menu(" Excellent!", " OK.", " Bad.");
do {
if(answer == 1 )
{ cout<<"\n What makes things so good? \n";
answer = Menu(" Your Job?", " Your friend", " Your sister or Brother?");
if(answer == 1 )
answer = Work(answer);
else if (answer == 2 || answer ==3 )
answer = Relationship(answer);
}
else if (answer == 2)
{ cout<<"\n Did something happen? \n";
answer = Menu(" No.", " Yes.", " Can we talk about something else?");
if(answer == 1)
{ cout<<" \n\n I think we need to talk about it. \n\n\n";
answer = -1;
}
else if (answer == 2)
{ cout<<"\n Did I do something to upset you?\n";
answer =Menu(" No.", " Yes.", " Let's talk about something else?");
if(answer == 1)
answer =2;
else if (answer == 2)
answer =3;
else if (answer==3)
answer =-1;
}
else if (answer==3)
answer =-1;
}
else if (answer == 3)
{ cout<<"\n I am sorry to hear that. Can you tell me more? \n";
answer = Menu(" No.", " Yes.", " Let's talk about something else?");
if(answer == 1)
{ cout<<" \n\n I think we need to talk about it. \n\n\n";
answer = -1;
}
else if (answer == 2)
answer =2;
else if (answer==3)
answer =-1;
}
else if (answer == 4)
cout<<"OK. Have a nice day.\n\n\n";
else
{ cout<<"\n How do you feel about that?"<<endl<<endl;
answer = Menu( " Very happy."," Terrible.", " Let's talk about something else?");
}
} while (answer != 4);
cout<<" Bye!\n\n\n\n";
system("PAUSE");
return 0;
}

Solutions

Expert Solution


Related Solutions

Modify the program to double each number in the vector. #include <iostream> #include <vector> using namespace...
Modify the program to double each number in the vector. #include <iostream> #include <vector> using namespace std; int main() { const int N=8; vector<int> nums(N); // User numbers int i=0; // Loop index cout << "\nEnter " << N << " numbers...\n"; for (i = 0; i < N; ++i) { cout << i+1 << ": "; cin >> nums.at(i); } // Convert negatives to 0 for (i = 0; i < N; ++i) { if (nums.at(i) < 0) {...
this is cahce memory related c program....and not working or running properly??????? #include <iostream> #include <string>...
this is cahce memory related c program....and not working or running properly??????? #include <iostream> #include <string> #include <vector> #include <iomanip> #include <cmath> #include <cstdlib> #include <ctime> using namespace std; int cash_type, block_size, cash_size,number_of_blocks=0;; int compulsry_misses=0, capcity_misses=0, conflict_misses=0; #define DRAM_SIZE (64*1024*1024) unsigned int m_w = 0xABABAB55; /* must not be zero, nor 0x464fffff */ unsigned int m_z = 0x05080902; /* must not be zero, nor 0x9068ffff */ unsigned int rand_() { m_z = 36969 * (m_z & 65535) + (m_z >>...
A used car salesperson claims that the probability of he selling a used car to an...
A used car salesperson claims that the probability of he selling a used car to an individual looking to purchase a used car is 70% and this probability does not vary from individual to individual. Suppose 5 individuals come to speak to this salesperson one day. If his belief is correct, The probability (to 4 decimal places) that he will sell a car to the first individual he speaks to is ______ The probability (to 4 decimal places) that he...
#include <iostream> #include <string> #include <sstream> using namespace std; int main() { string userInput; getline(cin, userInput);...
#include <iostream> #include <string> #include <sstream> using namespace std; int main() { string userInput; getline(cin, userInput); // Declaring base int N = 30; if (userInput.length() > 10) { cout << 0 << endl; } else { int finalTotal = 0; //Iterates through userInput for(int i = 0; i < 10; i++){ char convertedInput = userInput[i]; // ASCII decimal value of each character int asciiDec = int(convertedInput); //Casts char value from input to int value stringstream chr; chr << convertedInput; int...
Complete the following TODO: parts of the code in C++ #include <iostream> #include <string> #include <limits>...
Complete the following TODO: parts of the code in C++ #include <iostream> #include <string> #include <limits> #include <vector> using namespace std; // // CLASS: NODE // class Node{ public: int value = 0; // our node holds an integer Node *next = nullptr; // our node has a pointer to the next Node Node(int i){ // contructor for our Node class value = i; // store a copy of argument "i" in "value" next = nullptr; // be sure next...
Are my codes correct? #include <iostream> #include <string> #include <cassert> #include <cctype> #include <cstring> #include <stdio.h>...
Are my codes correct? #include <iostream> #include <string> #include <cassert> #include <cctype> #include <cstring> #include <stdio.h> #include <ctype.h> #include<fstream> int locateMinimum( const std::string array[ ], int n ){    if(n <= 0){    return -1;    }    else{    int minInd = 0;    for(int i = 0; i < n; ++i){    if(array[i] < array[minInd]){    minInd = i;    }    }    return minInd;    } } int countPunctuation( const std::string array[], int n) { int...
--- TURN this Code into Java Language --- #include <iostream> #include <string> using namespace std; //...
--- TURN this Code into Java Language --- #include <iostream> #include <string> using namespace std; // constants const int FINAL_POSITION = 43; const int INITIAL_POSITION = -1; const int NUM_PLAYERS = 2; const string BLUE = "BLUE"; const string GREEN = "GREEN"; const string ORANGE = "ORANGE"; const string PURPLE = "PURPLE"; const string RED = "RED"; const string YELLOW = "YELLOW"; const string COLORS [] = {BLUE, GREEN, ORANGE, PURPLE, RED, YELLOW}; const int NUM_COLORS = 6; // names...
#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;...
C++ code Why my code is not compiling? :( #include <iostream> #include <iomanip> #include <string> using...
C++ code Why my code is not compiling? :( #include <iostream> #include <iomanip> #include <string> using namespace std; const int CWIDTH = 26; int main() {    int choice;    double convertFoC, converCtoF;    double starting, endvalue, incrementvalue;    const int CWIDTH = 13;    do {       cin >> choice;    switch (choice)    {        cin >> starting;    if (starting == 28){       cout << "Invalid range. Try again.";    }    while (!(cin >> starting)){       string  garbage;       cin.clear();       getline(cin, garbage);       cout << "Invalid data Type, must be a number....
#include <iostream> #include <string> #include <fstream> #include <vector> #include <sstream> using namespace std; int main() {...
#include <iostream> #include <string> #include <fstream> #include <vector> #include <sstream> using namespace std; int main() { ifstream infile("worldpop.txt"); vector<pair<string, int>> population_directory; string line; while(getline(infile, line)){ if(line.size()>0){ stringstream ss(line); string country; int population; ss>>country; ss>>population; population_directory.push_back(make_pair(country, population)); } } cout<<"Task 1"<<endl; cout<<"Names of countries with population>=1000,000,000"<<endl; for(int i=0;i<population_directory.size();i++){ if(population_directory[i].second>=1000000000){ cout<<population_directory[i].first<<endl; } } cout<<"Names of countries with population<=1000,000"<<endl; for(int i=0;i<population_directory.size();i++){ if(population_directory[i].second<=1000000){ cout<<population_directory[i].first<<endl; } } } can u pls explain the logic behind this code up to 10 lines pls, many thanks
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT