Latest Revision: February 06, 2013

Directions for Lab #1

Baneasa's Green Glade - Andy Irvine

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 print the notes and turn them in after completing the lab.

You will have to perform similar 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 file.

  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 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:


    Open a new editor file for your notes and type the two questions above, and the answers, in that note file. (You will have to turn in a copy of your note file as part of this assignment.)

  4. Change the first line of the header comment so it says the following:
    Program to print song lyrics "Baneasa's Green Glade"
    Re-run the program (as defined above). Did the output change? Why or why not? Like you did before, put the two questions and your answers in your note file.

  5. In the first output statement, change
    "In banana's great harvest over the seas\n" 
    to
    "In Baneasa's green forest out under the trees\n"

    In the second output statement, change
    "We'd hide by the tracks from exorbitant fees." 
    to
    "We'd lie on our backs, we'd live at our ease."

    In the third output statement, change
    "We'd bake while adorning our earlobes with clay\n" 
    to
    "We'd wake in the morning at the first shafts of day\n"

    In the fourth output statement, change
    "and hatch lots of spiders in campers each day." 
    to
    "And watch the shy deer as they scampered away."

    Re-run the program. Did the output change? How? Like you did before, put the two questions and your answers in your note file.

  6. Add another output statement at the begining of main that displays the title:
    Baneasa's Green Glade
    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:
                Baneasa's Green Glade
    
    In Baneasa's green forest out under the trees
    We'd lie on our backs, we'd live at our ease.
    We'd wake in the morning at the first shafts of day
    And watch the shy deer as they scampered away.
    
    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 << "In Baneasa's green forest
    out under the trees\n" ;

    Because it would break the quoted string "In Baneasa's green forest out under the trees,\n" across two lines in the C++ program.

  8. Add more output statements to display the remaining verses, separated as shown by blank lines:
    We'd rise from our warm beds as the sun it got higher
    And cook up our breakfast on a sweet scented fire.
    
    In the still early morning, a cool gentle breeze,
    The echo of woodpeckers rings through the trees.
    We'd sit in our glade till the heat of the day,
    Walk down to the zoo to sing and to play.
    
    Well the money rolled in and the people looked on
    When the hat was quite full we'd up and be gone.
    In Dimbovitsas tavern we spent money free
    And drank to our friends where'er they may be.
    
    We'd talk of old times and fond memories we'd trade,
    And at dusk we'd walk home to Baneasa's Green Glade.
    
    (Notice that you can save a lot of time by doing some copy/paste operations.)

  9. Re-run the program. The output should look like this:
                Baneasa's Green Glade
    
    In Baneasa's green forest out under the trees
    We'd lie on our backs, we'd live at our ease.
    We'd wake in the morning at the first shafts of day
    And watch the shy deer as they scampered away.
    
    We'd rise from our warm beds as the sun it got higher
    And cook up our breakfast on a sweet scented fire.
    
    In the still early morning, a cool gentle breeze,
    The echo of woodpeckers rings through the trees.
    We'd sit in our glade till the heat of the day,
    Walk down to the zoo to sing and to play.
    
    Well the money rolled in and the people looked on
    When the hat was quite full we'd up and be gone.
    In Dimbovitsas tavern we spent money free
    And drank to our friends where'er they may be.
    
    We'd talk of old times and fond memories we'd trade,
    And at dusk we'd walk home to Baneasa's Green Glade.
    
    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!

    After removing your output from the printer, separate the sides from the paper along the perforations. This is called bursting.

    photo of paper edges

    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.