Question: Using C++ Update the program by removing the system function , implement a quit function and have the program wait for the user to enter

Using C++

Update the program by removing the system function, implement a quit function and have the program wait for the user to enter the first command and second one rather than having the program ask for them. Make sure all the functions work correctly in linux.

#include #include #include

using namespace std;

int main(int argc, char* argv[]) {

char choice; //Declare a variable

std::string line1, line2, command;

std::string line;

do

{

cout << "enter first string ";

getline(std::cin, line1); //get the first input from user

cout << "enter second string ";

getline(std::cin, line2); // get the second input from the user

string toCompare = "quit"; // declare a quit statement

if (line1 == "quit" || line2 == "quit") // conditonal statemet {

break; // to break if quit stement is executed

}

command = line1 + "|" + line2;

const char *finalCommand = command.c_str(); //system takes only const char *, c_str is used for conversion

system(finalCommand);

std::cout << line << std::endl;

cout << "do you want to do it again ? Y/N "; // repeat statement

cin >> choice;

} while (choice == 'Y');

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!