- Save a copy of the file lab01.cpp.html which is available here. Save it as a file in your home
directory. Give the file this name: lab01.cpp. Be sure
to give it exactly that name -- it's important. (In "lab01" the
characters "01" are the digits for zero and one.) To make a copy of the
file, you just display it in the web browser, copy it to the clipboard,
paste it into an editor window, and then save the file.
- Compile, link, and execute lab01.cpp. For help with this step
you may refer to the example commands and discussion under "Compiling and
Linking" and "Checking for Errors and Executing the Program" in the
"Hello World!"
assignment.
- The comment:
// Program to print song lyrics
at the beginning of your program is called a program
header comment. Add your name(s) and the date to that
header comment and re-format it like this header comment is
formatted:
/*
Program to print song lyrics
Programmers: Donny Dunn & Brenda Brady
Date: December 6, 1971
*/
Please Note: I'm asking that you duplicate the form above, but use your
real name(s) and the actual date.
Next, re-run the program -- in other words:
- Save the file.
- Compile and link the program again.
- Execute the program again.
- Did the output change? In other words, was the output different this
time from the first time you ran the program?
- Why or why not? Be specific.
Open a new editor file for your notes and type each of the questions above
into that file. After each question, write the answer. You will be required
to turn in a copy of your note file as part of this lab assignment.
One way to create a file for notes and to work with it would be to create another
terminal window by selecting the first "New Window" option from the "Shell"
menu of the Terminal program. You could then start up a jove session in the
new window with a command like
jove my_notes.txt
and then just keep typing your notes there and saving the file,
and later print the file.
You could also start up the TextEdit program from the Dock and use the file
buffer you get to make and save a file of notes. If you do that, when you
first save the file, make sure to save it in your home directory. You may
have to 'expand' the window you get when you try to save, and 'navigate' to
your home directory (folder). If you want help with that step, just ask.
- Change the first line of the header comment so it says the
following:
Program to print song lyrics "You Must Be Out Of Your Mind"
Re-run the program - as you did before: save, compile, and execute.
- Did the output change this time?
- Why or why not? Be specific.
As you did before, put the two questions and your answers in
your note file.
- In the first output statement in the program, change
"Hugh, think hill run not wok to you?\n"
to
"You think I'll run not walk to you.\n"
In the second output statement, change
"Why you'd eye wand dew tock too yew."
to
"Why would I want to talk to you?"
In the third output statement, change
"I warned you calling bag to me,\n"
to
"I want you crawling back to me,\n"
In the fourth output statement, change
"down dawn two needs, yeah.\n"
to
"down on your knees, yeah -\n"
In the fifth output statement, change
"like an app can ache to me\n"
to
"like an appendectomy\n"
In the sixth output statement, change
"Sands, Anna thee see ya"
to
"sans anesthesia."
Re-run the program again.
- Did the output change this time?
- Why or why not? Be specific.
Again, put the two questions and your answers in your note file.
- Make a new 'cout statement' at the beginning of the series that
displays the song title:
You Must Be Out Of Your Mind
Make sure to indent the output statement properly - with three blank
space characters - like the lines of code that are already in the program.
Write the new output statement so that a few blank spaces will be printed
before the title, and a blank line before the words of the song. This
will require you to think about the differences between indenting to
make your program easier to read, placing indentation in the
strings that the program prints, to make the output of the program
neater and easier to read, and modifying the program to make it
move the cursor to a new line.
Re-run the program and verify that your changes make the program do
what it is supposed to do. If not, fix the program, and test again.
- Add other output statements so that when you run the program
the display will be:
You Must Be Out Of Your Mind
You think I'll run not walk to you.
Why would I want to talk to you?
I want you crawling back to me,
down on your knees, yeah -
like an appendectomy
sans anesthesia.
As you are formatting your program statements, continue to preserve the
proper indentation pattern. Also, keep in mind this piece of advice
from our text:
"You should not break a quoted string across two lines ...."
For example, you should not write a C++ statement this way:
cout << "You think I'll run
not walk to you.\n" ;
Because it would break the quoted string
"You think I'll run not walk to you.\n"
across two lines in the C++ program.
- Add more output statements to make the program
display these remaining verses, separated as
shown by blank lines:
If you think you can leave the past behind
you must be out of your mind.
If you think you can simply press rewind
you must be out of your mind, son,
you must be out of your mind.
(You might save time by doing some copy/paste operations.)
- Re-run the program. The output should look like this:
You Must Be Out Of Your Mind
You think I'll run not walk to you.
Why would I want to talk to you?
I want you crawling back to me,
down on your knees, yeah -
like an appendectomy
sans anesthesia.
If you think you can leave the past behind
you must be out of your mind.
If you think you can simply press rewind
you must be out of your mind, son,
you must be out of your mind.
The output must include a blank line before the title, and a
blank line after the last line of text. If necessary debug the program
until it is working properly. Print the code of the program (this is
called a listing) with the command:
lp lab01.cpp
Above,
- lp is the print command -- lp stands for line printer.
- The string lab01.cpp is the name of the file you are printing.
Next make a script of a run of the program. Make the script in the
manner you did in the step entitled "Making a Record of a Program Run" in
the
"Hello World!"
assignment.
Remember to perform the steps to filter the "weird" characters out of the
script. The procedure for filtering a script is described in the directions for the
"Hello World!"
assignment.
Print the script with an lp command similar to the one illustrated
above. (It's an exercise for you to figure out the exact form the
command should have.)
Also print a copy of your lab notes with an lp command.
(Figure out the
exact form the command should have.)
Retrieve your printouts from the printer. To avoid damaging the
printer, be especially careful to read and follow the
directions on the printer!
After removing your output from the printer, separate the sides from the
paper along the perforations. This is called bursting.
Write the names of both (all) lab team members on each
printout. Bring the printouts to me on the due date. Check
the class schedule
for the due date.