CPS 6 Summer 1999
Assignment 2: Names, Buses and more Buses

Due: Monday, May 31, 11:59pm

15 points

In lab 1 you should have created a directory called cps6. Change into that directory using the "cd" command by typing "cd cps6" and create another directory called "assign2" using the "mkdir" command by typing "mkdir assign2". Change into the "assign2" directory. If you did this correctly, when you type "pwd" you should see a long path name that ends with "/cps6/assign2"

In order to do this assignment, you need to copy a Makefile using the following "cp" command (don't forget the trailing period, or dot):

 cp  ~dr/cps6/assign2/*  .

This command will copy the Makefile in the directory

~dr/cps6/assign2
into your directory for you to use. If you type "ls" you should see "Makefile" and "bus.cc".

For each of the programming problems that follow, you should use the style rules discussed in class, which includes meaningful variable names, indentation, and comments at the top of the file and for each function.

The file Makefile will make it easier to compile as it automatically invokes the g++ compiler and links to libraries you'll need for this assignment. To compile the program called name.cc, type "make name"

If your program compiles correctly, the executable file called "name" will be created. Then you can type "name" in your xterm window to run your program.

  1. A program to write a program

    Write a C++ program called "name.cc" that asks for a first name and last name, and outputs a C++ program that when compiled and run, prints out the last name followed by a comma, space and first name.

    Here is a sample run (your outputted program should be properly indented):

            > name
            Enter first and last name: Dietolf Ramm
            #include <iostream.h>
            main()
            {
               cout << "Ramm, Dietolf" << endl;
            }   
    

  2. The Bus Song

    Consider the following song.

       The wipers on the bus go swish swish swish
       swishity swishity swishity
       swishity swishity swishity
       The wipers on the bus go swish swish swish
       All through the town
    

    Write a program called bus.cc to print one arbitary verse for this song. Your program should ask for two input items, an object and a sound, and be composed of at least three useful functions besides the main function. The object wipers should be replaceable by any object, and the sound swish should be replaceable by any sound. Note the ity must be added to the sound in the 2nd and 3rd lines. Use the skeleton program bus.cc as a starting point, and make sure each function has a comment.

    Here is a sample run of what your progam might look like when it runs.

       > bus
       Enter object:  headlights 
       Enter sound:  blink
    
       The headlights on the bus go blink blink blink
       blinkity blinkity blinkity
       blinkity blinkity blinkity
       The headlights on the bus go blink blink blink
       All through the town
    
  3. Four verses

    Make a copy of your program bus.cc to busfour.cc by using the unix copy command cp, type:

                 cp bus.cc busfour.cc
    

    Modify this program to print four numbered verses of the bus song. We'll assume the user has already created several verses of the bus song and wants to add new verses. Ask the user for the verse number of the first new verse, followed by objects and sounds for four verses. Use an integer (type int) for the verse number. Do not ask for the verse numbers of the last three verses, but rather number them consecutively based on the number of the first new verse.

    Here is a partial sample run of what your program might look like. Italized words are what the user types.

       > busfour
       Enter verse number:  16 
       Enter object:  man 
       Enter sound:  cough
    
       Verse 16:
       The man on the bus go cough cough cough
       coughity coughity coughity
       coughity coughity coughity
       The man on the bus go cough cough cough
       All through the town
    
       Enter object:  headlights 
       Enter sound:  blink
    
       Verse 17:
       The headlights on the bus go blink blink blink
       blinkity blinkity blinkity
       blinkity blinkity blinkity
       The headlights on the bus go blink blink blink
       All through the town
    
       <two more groups of input and verses should appear numbered 18 and 19>
    

Submitting Programs

When all your programs for Parts 1, 2, and 3 compile and produce the correct output, create a "README" file (please use all capital letters). Include your name, section number, the date, and an estimate of how long you worked on the assignment in the "README" file. You must also include a list of names of all those people with whom you collaborated on the assignment.

To submit your programs electronically type

    ~dr/bin/submit6 assign2 name.cc bus.cc busfour.cc README

You should receive a message telling you that the programs were submitted correctly.