Project 3 - Boxes
Due Dates
Section 0201: Wednesday, 12/6 by midnight
Section 0601: Friday, 12/1 by midnight
NO LATE PROJECTS WILL BE ACCEPTED!
Point Value
This assignment is worth 100 points.
Objectives
- To use a switch statement
- To implement error checking on input data
- To use functions
- To practice using the
char
data type
- To implement nested
for
loops
- To further practice using loops
Assignment
Your program will prompt the user to enter the width, height, and depth of a
box. It will allow the user to enter only positive integers as the dimensions
of the box by error checking each dimension as it is entered. The program should make the user keep entering a value until he/she enters a positive integer. You MAY assume that the user will enter only integers (i.e., no real numbers or characters will be entered). See the Sample Program Run below.
Once the user has entered valid values for width, height, and depth, the program will ask the user for a character with which to draw the different surfaces of the box.
Next, the program will present the user with a menu of options. The options are shown in the Sample Program Run below.
The functions you will write, in addition to the main function, are:
- int computeSurfaceArea(int width, int height, int depth), which returns the surface area of the box
- int computeVolume(int width, int height, int depth), which returns the volume of the box
- void displayTopBottom(int width, int depth), which displays the top/bottom of the box
- void displayFrontBack(int width, int height), which displays the front/backof the box
- void displaySide(int depth, int height), which displays the depth of the box
Each function corresponds to a menu option. The menu should continue to
display until the user enters a Q for quit. You should only allow the user to enter UPPERCASE menu options.
Sample Program Run
Here is a sample run of the program.
Enter the width: 0
Please enter a positive integer: -2
Please enter a positive integer: 5
Enter the height: -1
Please enter a positive integer: 7
Enter the depth: 0
Please enter a positive integer: 4
Enter a character to be used to draw: #
Menu
A -- Calculate the Surface Area of the Box
V -- Calculate the Volume of the Box
F -- Display the Front/Back of the Box
T -- Display the Top/Bottom of the Box
S -- Display the Side of the Box
Q -- Quit
Selection: B
B is an invalid menu option.
Menu
A -- Calculate the Surface Area of the Box
V -- Calculate the Volume of the Box
F -- Display the Front/Back of the Box
T -- Display the Top/Bottom of the Box
S -- Display the Side of the Box
Q -- Quit
Selection: a
a is an invalid menu option.
Menu
A -- Calculate the Surface Area of the Box
V -- Calculate the Volume of the Box
F -- Display the Front/Back of the Box
T -- Display the Top/Bottom of the Box
S -- Display the Side of the Box
Q -- Quit
Selection: A
The surface area is: 166
Menu
A -- Calculate the Surface Area of the Box
V -- Calculate the Volume of the Box
F -- Display the Front/Back of the Box
T -- Display the Top/Bottom of the Box
S -- Display the Side of the Box
Q -- Quit
Selection: V
The volume is: 140
Menu
A -- Calculate the Surface Area of the Box
V -- Calculate the Volume of the Box
F -- Display the Front/Back of the Box
T -- Display the Top/Bottom of the Box
S -- Display the Side of the Box
Q -- Quit
Selection: F
#####
#####
#####
#####
#####
#####
#####
Menu
A -- Calculate the Surface Area of the Box
V -- Calculate the Volume of the Box
F -- Display the Front/Back of the Box
T -- Display the Top/Bottom of the Box
S -- Display the Side of the Box
Q -- Quit
Selection: T
#####
#####
#####
#####
Menu
A -- Calculate the Surface Area of the Box
V -- Calculate the Volume of the Box
F -- Display the Front/Back of the Box
T -- Display the Top/Bottom of the Box
S -- Display the Side of the Box
Q -- Quit
Selection: S
####
####
####
####
####
####
####
Menu
A -- Calculate the Surface Area of the Box
V -- Calculate the Volume of the Box
F -- Display the Front/Back of the Box
T -- Display the Top/Bottom of the Box
S -- Display the Side of the Box
Q -- Quit
Selection: Q
Your program's output should follow this EXACT formatting.
Coding Standards and Indentation
Make sure that you follow the "C Coding Standards" and "Indentation Styles" given on the Projects web page. Your program will be graded not only on whether or not it produces the correct results, but also on whether or not you follow these standards and styles.
Project Submission
Submit your project by e-mailing your source code (proj3.c) to Evelyn (cwang3@cs.umbc.edu) as an attachment. Make the Subject of the e-mail Project 3 so that Evelyn knows what it is. Do NOT send your executable file (a.out).