CPS 006, Lab 2, Jan 2000

Week: Jan. 25-27
6 points

Setup for Prelab

For the prelab problems, you should type them in, compile them and make sure they run. Bring a printout of them to hand in at the beginning of class.

In your cps006 directory, you should create a lab2 directory to work in. You will then copy several files into your lab2 directory to help you get started. Type the following unix commands from your account after you login (don't forget the trailing dot on the last line).

   cd cps006
   mkdir lab2
   cd lab2
   cp ~ola/cps006/lab2/*  .
If you did these commands correctly, typing pwd should show that you are in your lab2 directory, and typing ls should show the files Makefile, parts.cpp and pizza.cpp in that directory.

You might want to refer to lab1 for information on editing, compiling and running programs.

Prelab

Bring a printout of running results of parts.cpp and pizza.cpp and hand them in at the beginning of class.
Bring a printout of your solutions of prelab problems to the beginning of lab.

  Prelab Problems

  1. Create a new function called EyesIn in the parts.cpp program to pass in two string parameters of one character each representing the two eyes. For example, the call EyesIn("0", "^") should print the line below.
  2.  |    0    ^    |
    You can make a copy of the Eyes function in the file parts.cpp (don't destroy the old Eyes function). Here is the current Eyes function.
    void Eyes()
    // prints eyes of a head (corresponding to distance in Sides)     
    {
        cout << "  |    o    o    |  " << endl;
    }
  3. Create a new function called NoseIn in the parts.cpp program to pass in one string parameter of three characters representing a nose.

  4. For example, the call NoseIn("oUo") should print the line below

     |      oUo      |
  5. Modify the program pizza.cpp for the following inputs and outputs (modify the function SlicePrice as well as main.)

  6. The user should be prompted for and input the width, height, and thickness in inches for a rectangular pizza (note that pizza.cpp currently applies to a round pizza).

    Output the price per cubic centimeter for the entire pizza and the volume of one slice. Note that the current SlicePrice function calculates statistics for a slice and for the entire pizza based on area, not on volume. You are to calculate a price based on volume. Assume that all rectangular pizzas have 16 slices. 2.54 cm = 1 in

In Lab

You must have done the prelab first before attempting these problems. The
parts.cpp file would have been copied during the prelab.

Problems

 1.The parts.cpp file contains the face drawing program given in lecture.
   Add to this program any TWO of the following functions: drawing a
   beard, drawing a hat, drawing eyeglasses, or drawing a bow tie. Then
   modify the main function to draw a new face that uses the two
   functions.

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

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

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

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

   the output will be:

     \\\

 2. Make a copy of the program parts.cpp called totem.cpp by using the
   unix copy command, type:

         cp parts.cpp totem.cpp

   Modify totem.cpp to print a totem pole of SIX heads of which at least
   three of the heads must be different. Here is an example of a totem pole
   of two heads. NOTE that your program must have a totem pole of SIX
   heads.

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

Each lab is worth six points. A TA must check each of the points. It is your responsibility to ensure that a TA awards each point. After a lab is over you cannot receive credit for the first two points.