Lexington High School Mathematics Math Dept. Front Page  | Student Links  | Family Links 
Introduction to C++, Kevin Kelly Kelly Front Page  | C++ Course Guide | C++ Assignments | C++ Info

Assignment 26: Dr. Seuss in a file

due Monday 5/6

For this assignment you have to write two short programs, 26A and 26B. Hand in both programs at once, along with a run of the programs (as described below).

Program 26A: Rewrite Assignment 1 so that the output is sent to a data file named seuss.txt instead of to the screen.

Program 26B: Write a program that reads in the contents of the file seuss.txt and prints its contents on the screen.

Running the programs: You must show that your two programs work correctly, using a sequence of commands like the following.

[yourname@neon yourname]$ rm seuss.txt
[yourname@neon yourname]$ assign26a
[yourname@neon yourname]$ assign26b
The first command removes any pre-existing file called seuss.txt (if you get a "no such file" error message, that's OK). The second command should output nothing, and the third command should output the Dr. Seuss passage.

Extension

Program 26A should additionally prompt the user to type his/her full name. For the first two lines of the seuss.txt file, output "Here is some Dr. Seuss for [the user's name]." followed by a blank line. The run sequence will now look like this:
[yourname@neon yourname]$ rm seuss.txt
[yourname@neon yourname]$ assign26a
What is your full name? Jo Smith
[yourname@neon yourname]$ assign26b
Here is some Dr. Seuss for Jo Smith.

When a fox is in the bottle
   (etc.)