PROGRAM NEEDS TO MATCH EXAMPLE PHOTO Write a program ( lab6.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 ‘\n’. Hints: - You need to look at each character as it is read to see if it is ‘\n’, 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 An example run of the program is shown below:

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

PROGRAM NEEDS TO MATCH EXAMPLE PHOTO

Write a program ( lab6.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 ‘\n’.

Hints:
- You need to look at each character as it is read to see if it is ‘\n’, 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

An example run of the program is shown below:

[mingli@polaris:~/TA]$ ./lab6
>>>Previous advice:
First advice:
Practice makes perfect!
>>>Your advice to next user. Hitting ENTER twice to exit:
Second advice:
Never give up!
Thanks for your advice.
(mingli@polaris:~/TA]$ ./lab6
>>>Previous advice:
Second advice:
Never give up!
>>>Your advice to next user. Hitting ENTER twice to exit:
Third advice:
Stay safe!
Thanks for your advice.
[mingli@polaris:~/TA]$ |
Transcribed Image Text:[mingli@polaris:~/TA]$ ./lab6 >>>Previous advice: First advice: Practice makes perfect! >>>Your advice to next user. Hitting ENTER twice to exit: Second advice: Never give up! Thanks for your advice. (mingli@polaris:~/TA]$ ./lab6 >>>Previous advice: Second advice: Never give up! >>>Your advice to next user. Hitting ENTER twice to exit: Third advice: Stay safe! Thanks for your advice. [mingli@polaris:~/TA]$ |
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY