2-D Shape | Inputs | Perimeter | Area |
---|---|---|---|
Circle | radius | 2*PI*r | PI*r2 |
Triangle | side a side b side c | a+b+c | First calculate the Semiperimeter: s = (a+b+c)/2
Now calculate the area: |
Rectangle | length width | 2l+2w | lw |
3-D Shape | Inputs | Surface Area | Volume |
Cylinder | radius height | 2PIr2 + 2PIrh | PIr2h |
Triangular Prism | side a side b side c height | (a+b+c)*h + 2(area of the triangle base) | (area of the triangle base)*h |
Box | length width height | 2lw+2lh+2wh | lwh |
Cone | radius height | PIr2 + PIr*SQRT(r2 + h2) | 1/3PIr2h |
Sphere | radius | 4 PI r2 | 4/3PIr3 = 4/3 r * PI r2 |
Your program is to be written using functions. You must write one function for each Geometric shape. These functions should prompt for and read in the needed inputs for the shape, calculate the two results for the shape and output these results in some readable format. This readable format must include the name of the shape and the values read in for the inputs as well as the results. When reading in the values for a 3-D shape always read the height value (if needed) last. This uniformity will help in testing your program.
Your function is to have have another function that will output a menu to allow the user to select which geometric shape the user wishes to use. This prompt is to have the user enter an integer value from 1 to 8 to specify the shape (see the order for the shapes in the first list on this page: 1=circle, 2=triangle, ..., 8=sphere) and to enter the value of 9 to quit the program. This function should read in the user's input and should make sure that the user enters a value from 1 to 9. Any other input should result in an error message followed by the menu being reprinted.
Your program will need to loop until the user enters a value of 9 and will need to call the proper function for the geometric shape based on the input. These two actions will most-likely occur in the same function. One logical place is to put these in main(). Inside of a loop, main() calls the function to display the menu and get the user's input. This function returns a valid value to main() which uses this value in a set of selection statements to call the appropriate function for the geometric shape (or quit the program).
The functions may call other functions. In fact, the table has bolded all places were a calculation uses the expression PI*r2. This is to highlight how you could write one function to calculate the area of a circle and call it whenever needed. A function to calculate the area of a triangle and rectangle could also be helpful.
Your program must be written using good programming style. This includes (but is not limitted to) such items as:
Your program will be submitted electronically on the icarus system using the turnin command. The project name for this will be mp3. Your program will graded based on how it executes on the icarus system using the g++ compiler. Getting a program to work on another system or using another compiler does NOT mean it will work on the icarus system using the g++ compiler. Programs that do not work properly on the icarus system using the g++ compiler will lose points. Also programs that are not submitted via the turnin command will also lose points. Emailing a program is not an acceptable form of electronic submission.