Question: Introduction to C++ Write a C++ program that repeatedly accepts single word commands and then sentences until the user tells the program to stop. You
Introduction to C++
Write a C++ program that repeatedly accepts single word commands and then sentences until the user tells the program to stop. You should create a text file called out.txt from these commands. There are four commands you need to handle: new will create a new blank file with just the following sentence in it. append will add the sentence to the end of the file. prepend will add the sentence to the start of the file. exit will cease asking questions and stop the program. In this case, there will not be a sentence following the command. Your program should be able to handle any combination of these commands. You can create temporary text files if you think this would be useful, but the final out.txt needs to follow the commands as described. You can assume the new command will always be run first. Make the out.txt in the current directory with the cpp file (i.e. do not assume any directory structure).
Example 1 (user input is bold and italics): Command? new Hello Command? append there Command? prepend asdf Command? exit
>>>>>Resulting out.txt for example 1:
asdf Hello there
Example 2 (user input is bold and italics): Command? new this is a worthless sentence Command? new i like apples Command? prepend i like berries Command? prepend i like carrots Command? append i like danishes Command? prepend i like eggs Command? exit
Resulting out.txt for example 2: i like eggs i like carrots i like berries i like apples i like danishes
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
