Latest Revision: August, 2001

Directions for Lab #1

Follow these amplified instructions for Laboratory 1 on page 49 of Shiflet. 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 final version of the program in Example 1.1 and observe their effects.

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 lab011.cpp.html which is available here. Save it as a file in your home directory. Give the file this name: lab011.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.

  2. Compile, link, and execute lab011.cpp. For help with this step you may refer to the example commands under "Compiling and Linking" and "Checking for Errors and Executing the Program" in the "Hello World!"assignment. Understand, however, that you must use the correct file name after the g++ command.

  3. Into your copy of lab011.cpp, insert a comment after the header comment that gives your name and the date. Rerun the program -- in other words: Did the output change? Why or why not? Put the answer in your notes.

  4. Change the header comment to state the following:
    Program to print part of "Don't Fence Me In"
    Rerun the program (as defined above). Did the output change? Why or why not? Put the answer in your notes.

  5. In the second output statement, change "And the" to "Under" and the ellipses (three continuation dots) to a period. Rerun the program. Describe any change in the output. Put the information in your notes.

  6. Add another output statement before return that displays:
    Don't Fence Me In.
  7. Add another output statement at the begining of main that displays the title:
    Don't Fence Me In
    Have the computer print a few spaces before the title and a blank line before the words of the song.

  8. Add other output statements to display another verse after a blank line. Do not retype the last line, but use your editor to make a copy of this line from the first verse.
    Let me roam in the wide
    Open country that I love.
    Don't Fence Me In
  9. By removing the proper \n for each verse, make changes so that the computer prints the first two lines of each verse on one line with the proper capitalization as follows:
                Don't Fence Me In
    
    Give me land, lots of land under starry skies above.
    Don't fence me in.
    
    Let me roam in the wide open country that I love.
    Don't fence me in.
    
  10. Rerun the program and debug it if necessary until it is working properly. Print the code of the program (this is called a listing) with the command:
    lp -d csok1 lab011.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.

    Print the script with an "lp" command similar to the one illustrated above.

    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. Your grade on this lab assignment will be based mostly on what is on the printouts. Bring the printouts to lecture on the due date. Give them to me at the beginning of the class. Check the class schedule for the due date.