Latest Revision: Sept 5, 2013

Directions for Lab #1

You Must Be Out Of Your Mind - The Magnetic Fields

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.

Your responsibility is to perform all the steps and to make notes on what happens. You will get familiar with how printing works in the lab when you print your notes. You will turn in your printouts after completing the lab.

You will have to perform similar steps many times again during the semester. As you work in the lab, 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:

    1. Did the output change? In other words, was the output different this time from the first time you ran the program?

    2. Why or why not? Be specific.

    Open a new editor file for your notes and type each of the questions above into that file. After each question, write the answer. You will be required to turn in a copy of your note file as part of this lab assignment.

    One way to create a file for notes and to work with it would be to create another terminal window by selecting the first "New Window" option from the "Shell" menu of the Terminal program. You could then start up a jove session in the new window with a command like
    jove my_notes.txt
    and then just keep typing your notes there and saving the file, and later print the file.

    You could also start up the TextEdit program from the Dock and use the file buffer you get to make and save a file of notes. If you do that, when you first save the file, make sure to save it in your home directory. You may have to 'expand' the window you get when you try to save, and 'navigate' to your home directory (folder). If you want help with that step, just ask.

  4. Change the first line of the header comment so it says the following:
    Program to print song lyrics "You Must Be Out Of Your Mind"
    Re-run the program - as you did before: save, compile, and execute.


    1. Did the output change this time?

    2. Why or why not? Be specific.


    As you did before, put the two questions and your answers in your note file.

  5. In the first output statement in the program, change
    "Hugh, think hill run not wok to you?\n" 
    to
    "You think I'll run not walk to you.\n"

    In the second output statement, change
    "Why you'd eye wand dew tock too yew." 
    to
    "Why would I want to talk to you?"

    In the third output statement, change
    "I warned you calling bag to me,\n" 
    to
    "I want you crawling back to me,\n"

    In the fourth output statement, change
    "down dawn two needs, yeah.\n" 
    to
    "down on your knees, yeah -\n"
    In the fifth output statement, change
    "like an app can ache to me\n" 
    to
    "like an appendectomy\n"
    In the sixth output statement, change
    "Sands, Anna thee see ya" 
    to
    "sans anesthesia."
    Re-run the program again.


    1. Did the output change this time?

    2. Why or why not? Be specific.


    Again, put the two questions and your answers in your note file.

  6. Make a new 'cout statement' at the beginning of the series that displays the song title:
       You Must Be Out Of Your Mind
    Make sure to indent the output statement properly - with three blank space characters - like the lines of code that are already in the program.

    Write the new output statement so that a few blank spaces will be printed before the title, and a blank line before the words of the song. This will require you to think about the differences between indenting to make your program easier to read, placing indentation in the strings that the program prints, to make the output of the program neater and easier to read, and modifying the program to make it move the cursor to a new line.

    Re-run the program and verify that your changes make the program do what it is supposed to do. If not, fix the program, and test again.

  7. Add other output statements so that when you run the program the display will be:
       You Must Be Out Of Your Mind
    
    You think I'll run not walk to you.
    Why would I want to talk to you?
    I want you crawling back to me,
    down on your knees, yeah -
    like an appendectomy
    sans anesthesia.
    
    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 C++ statement this way:

    cout << "You think I'll run
    not walk to you.\n" ;

    Because it would break the quoted string
    "You think I'll run not walk to you.\n"
    across two lines in the C++ program.

  8. Add more output statements to make the program display these remaining verses, separated as shown by blank lines:
    If you think you can leave the past behind 
    you must be out of your mind.
    If you think you can simply press rewind 
    you must be out of your mind, son,
    you must be out of your mind. 
    
    (You might save time by doing some copy/paste operations.)

  9. Re-run the program. The output should look like this:
       You Must Be Out Of Your Mind
    
    You think I'll run not walk to you.
    Why would I want to talk to you?
    I want you crawling back to me,
    down on your knees, yeah -
    like an appendectomy
    sans anesthesia.
    
    If you think you can leave the past behind 
    you must be out of your mind.
    If you think you can simply press rewind 
    you must be out of your mind, son,
    you must be out of your mind.
    
    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.