Latest Revision: September 06, 2016
[Sep 6, 2016: error corrected - save, don't print, the questions & answers] [Sep 3, 2016: added link to John Prine's story]

Directions for Lab #1

Cluck Old Hen - Toubab Krewe
Cluck Old Hen - Earl Brothers
Aubrey Atwater and Cluck Old Hen
John Prine's Story About Mis-Hearing Song Lyrics


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 save 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 the text between the lines 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. (Include the names of all the partners on your team.)

    Next, re-run the program -- in other words:


    Open a new editor file for your notes. For example, you could do the command "jove notes.txt" at the command line to create a new file for notes. At the top of the file, type your name and the name(s) of your lab partner(s). Then type the two questions above, and the answers.

    Remember to put each question in the file first, then the answer. You can do it quickly by pasting the question into the file from the directions.

    You will be required to turn in (e-mail) 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 "Cluck Old Hen"
    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 variable declaration (int legCount = 0), change
    legCount
    to
    eggCount

  6. In the first output statement, change
    "My ole den is a group's ole den.\n" 
    to
    "My old hen is a good old hen.\n"

    If you have the lab directions on screen in a browser, how can you use your ability to select, copy, and paste to quickly change what is in the C++ program you are editing? Please make full use of those features in ways that help you finish the editing quickly and accurately.

    In the second output statement, change
    "Sea legs, Greg for travail ya then." 
    to
    "She lays eggs for the railroad men."

    In the third output statement, change
    "Sun tynes bake an son lines Len,\n" 
    to
    "Sometimes eight and sometimes ten,\n"

    In the next line of the program, change
    legCount 
    to
    eggCount
    In the fourth output statement, change
    "Pat sees nought for their ale/grog name." 
    to
    "That's enough for the railroad men."

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

  7. Add another output statement at the begining of main that displays the title:
    Cluck Old Hen
    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.

  8. Add other output statements so that when you run the program the display will be:
            Cluck Old Hen
    
    My old hen is a good old hen.
    She lays eggs for the railroad men.
    Sometimes eight and sometimes ten,
    That's enough for the railroad men.
    
    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 << "My old hen is
    a good old hen\n" ;

    Because it would break the quoted string "My old hen is a good old hen.\n" across two lines in the C++ program.

  9. Add two more cout statements to make the output of the program look like this:
            Cluck Old Hen
    
    My old hen is a good old hen.
    She lays eggs for the railroad men.
    Sometimes eight and sometimes ten,
    That's enough for the railroad men.
    
    Cluck old hen, cluck in the lot.
    Next time you cackle you'll cackle in the pot.
    
  10. Add more output statements to display another verse and chorus, having blank lines exactly as shown. (Take some care with that -- it's part of the lab exercise to get all the blank space right.)
    Cluck old hen, cluck and sing.
    You ain't laid an egg since late last spring.
    Cluck old hen, cluck and squall,
    Ain't laid an egg since late last fall.
    
    Cluck old hen, cluck in the lot.
    Next time you cackle you'll cackle in the pot.
    
    (Remember: you can save a lot of time and be more accurate by doing some select/copy/paste operations.)

  11. Re-run the program. The output should look like this:
    
            Cluck Old Hen
    
    My old hen is a good old hen.
    She lays eggs for the railroad men.
    Sometimes eight and sometimes ten,
    That's enough for the railroad men.
    
    Cluck old hen, cluck in the lot.
    Next time you cackle you'll cackle in the pot.
    
    Cluck old hen, cluck and sing.
    You ain't laid an egg since late last spring.
    Cluck old hen, cluck and squall,
    Ain't laid an egg since late last fall.
    
    Cluck old hen, cluck in the lot.
    Next time you cackle you'll cackle in the pot.


    The output shown above has one blank line before the title (Cluck Old Hen) and one blank line after the last line of text. Your program must make those blank lines. If necessary debug the program until it is working properly. If you don't know what to do, ask.

  12. Add one more line of code. Insert this line of code:
     cout << "Egg total: " << eggCount << endl << endl ;
    right before the line that says "return 0 ;"

  13. Re-run the program. The final output should look like this:
    
            Cluck Old Hen
    
    My old hen is a good old hen.
    She lays eggs for the railroad men.
    Sometimes eight and sometimes ten,
    That's enough for the railroad men.
    
    Cluck old hen, cluck in the lot.
    Next time you cackle you'll cackle in the pot.
    
    Cluck old hen, cluck and sing.
    You ain't laid an egg since late last spring.
    Cluck old hen, cluck and squall,
    Ain't laid an egg since late last fall.
    
    Cluck old hen, cluck in the lot.
    Next time you cackle you'll cackle in the pot.
    
    Egg total: 18
    
    


  14. Utilizing the terminal application, enter this command to e-mail me a copy of your source code:
    mail -s "Lab #01 Source Code" john@ishi.csustan.edu < lab01.cpp
  15. 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.

  16. E-mail me a copy of your script, using an e-mail command similar to the one above (with the necessary changes made, of course). Use this subject line:
    Lab #01 Script
    Remember that when you build the command, you have to put quotes around the subject line.

  17. Also e-mail me a copy of your lab notes, using this subject line:
    Lab #01 Notes
  18. That's all for now. If you've done all the steps above, you can leave.
    Have a good day.