CS 1500-5, Fall 2010
Lab 1

Do all the steps described here.

The goal of this exercise is to examine various components of a program. We make additions and changes to the program and observe the effects of the changes.

Perform all the steps and make notes on what happens. You will have to perform the same kinds of steps many times again during the semester. Raise your hand if you need help with any of the steps.

Individual steps

  1. 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 character before the '1' is ZERO, not the upper-case letter O.) 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 window.

  2. 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.

  3. 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:
    Meg Miller & Jacinto Rivera
    Date: July 4, 2010
    */
    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:
    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.)

  4. 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.

  5. 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.

  6. 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
  7. 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.

  8. 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.
  9. 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.

  10. By adding instances of \n or the endl manipulator in the right places, change the program so that it prints a blank line before the last line of each verse.

  11. 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 lab01.cpp 
    Above,
    Next make a script of a run of the program.

    Remember to perform the steps to filter the "weird" characters out of the script.

    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. Be especially careful to read and follow the directions on the printer.

    Write the names of both lab team members in the comments. Turn in your printout to me before you leave the lab on the due date. Check the class schedule for the due date.
          Upload all three files to the Homework Submission System (one set only, but make sure both names are
          in the comments and that you each end up with a copy in your account).

          Files you should be uploading:
lab01.cpp
lab01.notes
lab01.script

Make a copy of your source cope file before you make your script:
cp lab01.cpp lab01_final.cpp