Latest Revision: August 31, 2011

Directions for Lab #1

Pretty Boy Floyd

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 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 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: Billy Barrow & Polly Parker
              Date: May 22, 1934
    */ 
    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? In other words, was the output different this time from the first time you ran the program? 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 "Pretty Boy Floyd"
    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 "A tale I will relate" to "A story I will tell". In the last output statement, change "known throughout this state." to "Oklahoma knew him well." Re-run the program. Did the output change? How? Put the questions and answers in your notes.

  6. Add another output statement at the begining of main that displays the title:
    Pretty Boy Floyd
    Make sure to indent the output statement properly - like the lines of code that are already in the program.

    Write the output statement so that a few blank spaces will be printed 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.

  7. Add other output statements so that when you run the program the display will be:
              Pretty Boy Floyd
    
    If you'll gather 'round me, children,
    A story I will tell
    'Bout Pretty Boy Floyd, an outlaw,
    Oklahoma knew him well.
    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 statement this way:

    cout << "There a deputy
    sheriff approached him\n" ;

    Because it would break the quoted string "There a deputy sheriff approached him\n" across two lines in the C++ program.

  8. Add more output statements to display another three verses separated by blank lines:
    It was in the town of Shawnee,
    It was Saturday afternoon,
    His wife beside him in his wagon
    As into town they rode.
    
    There a deputy sheriff approached him
    In a manner rather rude,
    Using vulgar words of language,
    And his wife she overheard.
    
    Pretty Boy grabbed a log chain,
    And the deputy grabbed his gun;
    And in the fight that followed
    He laid that deputy down.
    
  9. Re-run the program. The output should look like this:
              Pretty Boy Floyd
    
    If you'll gather 'round me, children,
    A story I will tell
    'Bout Pretty Boy Floyd, an outlaw,
    Oklahoma knew him well.
    
    It was in the town of Shawnee,
    It was Saturday afternoon,
    His wife beside him in his wagon
    As into town they rode.
    
    There a deputy sheriff approached him
    In a manner rather rude,
    Using vulgar words of language,
    And his wife she overheard.
    
    Pretty Boy grabbed a log chain,
    And the deputy grabbed his gun;
    And in the fight that followed
    He laid that deputy down.
    
    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,
    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!

    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.