CPS 6: Assignment #2

Party Time: Pizza, Balloons, and Names

Due: Monday, Sept. 18

15 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 "assign2" using the "mkdir" command. 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):

 ~ola/cps6/assign2/Makefile  .

This command will copy the Makefile in the directory

~ola/cps6/assign2
into your directory for you to use. If you type "ls" you should see "Makefile".

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" to run your program.

Part 1

Write a C++ program called "name.cc" that asks for a name (first and last name), and prints out a C++ program that when compiled and run, prints out the name.

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

> name
Enter first and last name: Susan Rodger
#include 
main() { cout << "Susan Rodger" << endl; }   

Part 2

Did you ever go to a pizza store and wonder which size pizza is the better value for your buck? Wonder no more, for you are now going to solve this problem. Write a C++ program called "pizza.cc" that asks for the radius (in inches) and prices of two pizzas, and then determines and prints which pizza is the better value. Your program must include a function called SqInchPrice that returns the price per square inch of a pizza. You may write additional functions if you want. To help you get started, look at the pizza program on page 83 of your textbook.

Here is a sample run:

> pizza
Enter radius and price of first pizza: 5 11.00
Enter radius and price of second pizza: 6 12.00
The first pizza costs $0.140056 per square inch.
The second pizza costs $0.106103 per square inch.
The second pizza is the better value. 
> 

Part 3

See the Balloon class in section 3.4.2 on page 84 of your textbook. Write a program called "fly.cc" that uses a variable of type balloon that performs the following sequence of actions:

  1. Prompt the user for an initial altitude and a number of time steps.
  2. Cause the balloon to ascend to one third of the specified altitude, then cruise for 1/4 of the time steps.
  3. Repeat step 2 twice more (ascend one-third, cruise 1/4, ascend one-third, cruise 1/4).
  4. Descend halfway to the ground, cruise for the remaining time steps, and then descend back to the ground.

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, 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

    submit6 assign2 pizza.cc fly.cc name.cc README

You should receive a message telling you that the programs were submitted correctly. If it doesn't work try typing

~ola/bin/submit6
in place of
 submit6
above.