Question: Write a program ( lab7.cpp ) that gives and takes advice on program writing. The program starts by writing a piece of advice to the

Write a program ( lab7.cpp ) that gives and takes advice on program writing. The program starts by writing a piece of advice to the screen and asking the user to type in a different piece of advice. The program then ends. The next person to run the program receives the advice given by the person who last ran the program. The advice is kept in a file, and the contents of the file change after each run of the program. You can use your editor to enter the initial piece of advice in the file so that the first person who runs the program receives some advice. Allow the user to type in advice of any length so that it can be any number of lines long. The user is told to end his or her advice by pressing the Return key two times. Your program can then test to see that it has reached the end of the input by checking to see when it reads two consecutive occurrences of the character . An example run of the program is shown below:

Write a program ( lab7.cpp ) that gives and takes advice on

Hints: - You need to look at each character as it is read to see if it is . So you need to use cin.get() . And you should then use out.put() to match, where out is a stream connected to the file. - Be sure to open the file as an ifstream, read it and print it to the display, then close it; then reopen the same file as an ofstream so you can write the new advice to the same file.

mingliemonster: / Desktop\$ . /1ab7 Previous advice: Hello korld! ? \$>Your advice to next user. Hitting ENTER twice to exit: Welcome to CS141! Thanks for your advice. mingliemonster: / Desktop\$ . /lab7 \$>Previous advice: Welcome to c5141! \$>Your advice to next user. Hitting ENTER twice to exit: Hope you can learn something useful from this course. Thanks for your advice. minglifmonster: / Desktops. /1ab7 Previous advice: Hope you can learn something useful from this course. >>Your advice to next user. Hitting ENTER twice to exit: A minglifmonster: m/ Desktops

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!