CIS 122: Assignment #2

Due at the start of class,
Tuesday, July 26 2004


The Kiwi Cylinder Glass Company manufactures only one product: a perfectly cylindrical drinking glass. All glasses are custom-made, according to a customer's individual preferences in size and thickness.

In the past few months, however, KCG Com. has been losing money due to flaws in their manufacturing process. It seems they just can't manage to produce the right of amount of glass to properly fill an order. It's always either too much glass or too little, and both of these cost money.

RCGC has hired you to solve this problem. Your job is to write a program, glassvol, which prints out the amount of glass, in cubic inches, necessary to fill a given order. Each time a user runs your software, she should be prompted for the height, width, and wall-thickness of each glass (given in inches, to the nearest 1/100th of an inch), and the number of glasses in the order (an integer, obviously). After calculation, you provide the total amount of glass needed, and the price the customer should pay. The unit price for the glass is $0.35 per cubic inch.

For example (user input is in italics and underlined),

How many glasses in this order? 1000
How tall is each glass, in inch? 8.2
How wide is it? 2.2
How thick? 0.1
Dear Customer, you will need 5723.98 cubic inches of glass to fill this order.
And the total cost for them is 2003.39 dollars.

Standards:

Your program will be judged primarily on its correctness. In particular, the program must compile. Programs that do not will receive a severe grade penalty. Over and above this is the requirement of correct behavior: the cubic volume reported must be correct.

Third, there is presentation: prompts should be formatted neatly (exactly matching the example here is good). Both of the two output numbers provided should have two decimal places, which means, they have a precision of two digits after the decimal point.

Finally, your program will be judged on elegance and adherence to the principles of good programming style. Elegance means that there should be nothing there that isn't necessary for the computation: all variables should have a use, as should all assignments to those variables. Style refers to the proper use of indentation, information variable names, documentation with comments, and other matters of readability.

Extra credits: (15 points)

To make the glasses more attractive, the company comes out with an idea - to print the customer' initials on the glasses. To accomplish this, you need to prompt for the customer's first and last names. The initials should be provided in your output.

For example (user input is in italics and underlined),

Hi, Welcome to KiWi Cylinder Glass Company!
Please input your first name: Patricia
Please input your last name: Marx
How many glasses in this order? 1000
How tall is each glass, in inch? 8.2
How wide is it? 2.2
How thick? 0.1
Dear Patricia Marx, you will need 5723.98 cubic inches of glass to fill this order.
And the total cost for them is 2003.39 dollars. You initials "P.M." will be printed on the
glasses.
Thank you for your business!

Turn in:

Helpful Hints

  1. To get you started, observe that once we know the height, width, and wall-thickness of the glass, we can compute:

    Even discounting input and output, this already identifies three subproblems into which we can decompose the larger one. (They are closely related, of course, and we shall see in a few days how to capitalize on this for code re-use.) See any geometry textbook for the necessary formulae.

  2. The fourth sub-problem is I/O. While we will have covered everything you need by the end of Thursday's class, you might also look at the file guessAge.cpp, available in the CIS 122 Code directory at

    
    http://www.cs.uoregon.edu/classes/05U/cis122/code/guessAge.cpp
    
    This gives an example of the kind of I/O you'll need to master for this assignment.

  3. You might find it useful to define the value of as a constant:
    const double PI = 3.141593;
    
  4. Be careful what types you choose for each variable: the results can be a bit random. For example, if you attempt the following assignment,
    int x = 0;
    x = 3.99;
    
    the decimal portion will simply be truncated. x will have the value 3, not 3.99 nor 4.

Other answers to FAQs as they appear. I'll post announcements if anything new shows up.


Dan Rao
Last modified: Wed Jun 20 23:22:34 PDT 2005