- 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.) To make a copy of the file you just
display it in the browser, copy it to the clipboard, paste
it into an editor window, and then save the window.
- 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 part of a song
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 part of a song
Programmers: Davey Drover & Meg Miller
Date: July 4, 2010
*/
Note: I'm asking that you duplcate 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? Why or why not? Open a new editor
file for your notes and put the questions above and the
answers in your notes. (You will have to turn in a copy of
your notes as part of this assignment.)
- Change the first line of the header comment so it says the
following:
Program to print part of the song "Sweet Betsy from Pike"
Re-run the program (as defined above). Did the output
change? Why or why not? Put the questions and answer in
your notes.
- In the second output statement, change "high prairies" to
"wide mountains". In the last output statement, change the
question mark to a comma. Re-run the program. Did the
output change? How? Put the questions and answers in your
notes.
- Add another output statement just prior to this line in the
program:
return 0 ;
Write the new line so it will display:
Singing too-ra-li-oo-ra-li-oo-ra-li-ay
- Add another output statement at the begining of main that
displays the title:
Sweet Betsy from Pike
Have the computer print a few spaces before the title and a
blank line before the words of the song. Re-run the program
to make sure your changes do what they are supposed to
do.
- Add other output statements so that when you run the program
the display will be:
Sweet Betsy from Pike
Did you ever hear tell of Sweet Betsy from Pike,
Who crossed the wide mountains with her lover Ike,
Two yoke of oxen, a big yeller dog,
A tall Shanghai rooster, a one-spotted hog.
Singing too-ra-li-oo-ra-li-oo-ra-li-ay.
- Add other output statements to display another verse after a blank line:
They swam the wide rivers and crossed the tall peaks,
And camped on the prairie for weeks upon weeks.
Starvation and cholera, hard work and slaughter
They reached California 'spite of hell and high water.
Singing too-ra-li-oo-ra-li-oo-ra-li-ay.
Do not retype the last line, but use your editor to make a copy of this
line from the first verse.
- By adding instances of the endl manipulator in the
right places, change the program so that it prints a blank
line before the last line of each verse.
- Re-run the program. The output should look like this:
Sweet Betsy from Pike
Did you ever hear tell of Sweet Betsy from Pike,
Who crossed the wide mountains with her lover Ike,
Two yoke of oxen, a big yeller dog,
A tall Shanghai rooster, a one-spotted hog.
Singing too-ra-li-oo-ra-li-oo-ra-li-ay.
They swam the wide rivers and crossed the tall peaks,
And camped on the prairie for weeks upon weeks.
Starvation and cholera, hard work and slaughter
They reached California 'spite of hell and high water.
Singing too-ra-li-oo-ra-li-oo-ra-li-ay.
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 -d csok1 lab01.cpp
Above,
- lp is the print command -- lp stands for "line printer."
- The -d csok1 specifies the destination -- the
kind of printer you want to print the file.
- The 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 filter the "weird" characters out.
Print the script with an "lp" command similar to the one illustrated
above.
Also print a copy of your lab notes with an "lp" command.
Retrieve your printouts from the printer. Be careful to read and follow
the directions on the printer.
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.