CPS 6: Lab #2

Functions and Errors

6 points

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

In order to do this lab, you need to copy some files using the following "cp" command (don't forget the trailing period, or dot): "cp ~ola/cps6/lab2/* ."

This command will copy all the files in the directory ~ola/cps6/lab2 into your directory for you to use.

If you type "ls" you should see the following files: Makefile, parts.cc and winner.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.

To compile these programs, you will NOT use the g++ command explicitly, but rather implicitly. The file Makefile will make it easier to use the g++ command. To compile the program called winner.cc, type " make winner"

This will automatically use the g++ command and link to libraries that you'll need for this assignment. If your program compiles correctly, the executable file called "winner" will be created. Then you can type "winner" to run your program.

Problems

  1. The program winner.cc should produce the following output.

    > winner
    Enter the amount of the lottery: 100000
    Enter first and last name: Susan Rodger
    The lottery is worth $100000
    Congratulations Susan Rodger
    You have a winning lottery ticket!
    
    Enter number of winners: 7
    Ticket is divided by 7 winners, so Susan Rodger
    your share of the winnings is $14285.7
    

    This program has both syntax errors (found by the compiler) and a logic error (not found by the compiler). Load the file using "emacs" and then type C-x c (hold the control key down, type x once, let go of control key, and type c) to compile, followed by typing "make winner" in the mini-buffer.

    Correct all syntax and logic errors so the program runs correctly. DO NOT rewrite the program, but rather make as few changes as possible to correct the program.

  2. The parts.cc file contains the face drawing program on pages 36-37 of your textbook. Add to this program any "two" of the following as functions: drawing a beard, drawing a hat, drawing eyeglasses, or drawing lots of curly hair. Then modify the main function to draw a new face that uses both of your functions.

    For example, your face might look something like the following (feel free to design your own glasses and beards):

      ||||||||||||||||  
      |              |  
      |  ____  ____  |  
      |--| o |-| o|--|  
      |  ----  ----  |  
     _|              |_ 
    |_                _|
      |   |______|   |  
      |              |  
      |||          |||  
        |||      |||    
           \\\///       
    
    

    "CAUTION:" The "\" (backslash) character is a special character. To print one backslash, you must put two backslashes inside of the double quotes. For example, to print three backslashes, you must put six inside the double quotes. For

             cout << "\\\\\\" << endl;
    

    the output will be:

      \\\ 

Submission of programs:

When both of your programs for problems 1 and 2 compile and produce the correct output, create a README file. This file should include your name, how long you worked on these programs, and anyone you received significant help from. You can then turn everything in by typing (where N is your section number (1, 2, 3, 4, or 5):

            submit6 lab2secN winner.cc parts.cc README

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