Latest Revision: February 08, 2015

Directions for Lab #1

Til I Kissed You - The Everly Brothers

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. We also practice printing on the lab printers.

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. Select the text between the white lines, and 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.

    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. (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 "Til I Kissed You"
    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
    "Nept turve eltlight dishin dill-like vista.\n" 
    to
    "Never felt like this until I kissed ya\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
    "Owdi dye-ex istantilk lye kvista?" 
    to
    "How did I exist until I kissed ya?"

    In the third output statement, change
    "Nept turve aduon mime ined\n" 
    to
    "Never had you on my mind\n"

    In the fourth output statement, change
    "Mowerdara latadime" 
    to
    "Now you're there all the time"

    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 beginning of main that displays the title:
    Til I Kissed You
    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:
            Till I Kissed You
    
    Never felt like this until I kissed ya
    How did I exist until I kissed ya?
    Never had you on my mind
    Now you're there all the time.
    
    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 << "Never felt like this
    until I kissed you\n" ;

    Because it would break the quoted string "Never felt like this until I kissed ya\n" across two lines in the C++ program.

  8. Add two more cout statements to make the output of the program look like this:
            Till I Kissed You
    
    Never felt like this until I kissed ya
    How did I exist until I kissed ya?
    Never had you on my mind
    Now you're there all the time.
    
    Never knew what I missed 'til I kissed ya, uh-huh
    I kissed ya, oh yeah
    
  9. 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.)
    Things have really changed since I kissed ya, uh-huh
    My life's not the same now that I kissed ya, oh yeah
    Mmm, ya got a way about ya
    Now I can't live without ya
    
    Never knew what I missed 'til I kissed ya, uh-huh
    I kissed ya, oh yeah
    
    (Remember: you can save a lot of time and be more accurate by doing some select/copy/paste operations.)

  10. Re-run the program. The output should look like this:
    
            Till I Kissed You
    
    Never felt like this until I kissed ya
    How did I exist until I kissed ya?
    Never had you on my mind
    Now you're there all the time
    
    Never knew what I missed 'til I kissed ya, uh-huh
    I kissed ya, oh yeah
    
    Things have really changed since I kissed ya, uh-huh
    My life's not the same now that I kissed ya, oh yeah
    Mmm, ya got a way about ya
    Now I can't live without ya
    
    Never knew what I missed 'til I kissed ya, uh-huh
    I kissed ya, oh yeah


    The output shown above has one blank line before the title (Til I Kissed You) 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.



  11. Print the code of the program (this is called a listing) with the command:
    lp lab01.cpp 
    Above,
  12. 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.

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

  14. That's all for now. If you've done all the steps above, you can leave.
    Have a good day.