| CSCI 240 | Fall 2025 |
For this part of the assignment, write a set of functions that will be used by a program that calculates the surface area of various shapes. A menu of different shapes will be shown to a user at the beginning of the program (and again after each surface area calculation). The user will select a shape and the program will then prompt for additional information that is specific to the shape. The surface area will be calculated and then displayed. This process will continue until the user decides to quit.
As noted above, the only requirement is to write functions for this assignment. A driver program that contains the code necessary for int main() can be found on Blackboard and at the URL: http://faculty.cs.niu.edu/~byrnes/csci240/pgms/assign6_pt2.cpp. Download the driver program and add the prototypes at the top and the functions to the end.
The following functions are required for this assignment:
This function displays a menu and gets a choice from the user.
It takes no arguments and returns an integer: the user's menu choice.
After displaying the menu, the function should accept the user's choice (as an integer) and check it for validity - that is did the user enter a value between 1 and 5, inclusive? If not, an error message should be displayed and the user should be given another chance to make a choice - this should continue until the user enters a valid choice. Once a valid choice is made, the integer should be returned.
The menu should resemble the following:
Surface Area Calculator 1) Sphere 2) Cone 3) Rectangular Prism 4) Pyramid 5) Quit Enter your choice:
This function will get an integer value from the user that is within a specified range.
It takes three arguments: a string that holds the prompt that is displayed to the user, an integer that holds the lowerbound for the specified range, and an integer that holds the upperbound for the specified range. It returns an integer: the user's value that is within the specified range.
The function should display a prompt to the user and accept a value. If the value is invalid, display an error message and ask the user to to re-enter a value - this should be repeated until a valid value is entered.
Once a valid value is entered, it should be returned.
A calling statement like:
value = getValue( "Enter the radius for the sphere", 1, 10 );
should produce the following prompt to the user:
Enter the radius for the sphere (1 - 10):
This function will calculate the surface area of a sphere.
It takes one argument: an integer that holds the radius of the sphere. It returns a floating point value: the calculated surface area.
The formula for calculating the surface area of a sphere is:
Surface Area of Sphere = 4 * pi * radius2
This function will calculate the surface area of a rectangular prism.
It takes three arguments: an integer that holds the length of the side of the prism, an integer that holds the width of the side of the prism, and an integer that holds the height of the side of the prism. It returns a floating point value: the calculated surface area.
The formula for calculating the surface area of a rectangular prism is:
Surface Area of Rectangular Prism = ( 2 * length * width ) + ( 2 * width * height ) + ( 2 * length * height )
This function will calculate the surface area of a cone.
It takes two arguments: an integer that holds the radius of the base of the cone, and an integer that holds the length of the side of the cone. It returns a floating point value: the calculated surface area.
The formula for calculating the surface area of a cone is:
Surface Area of Cone = ( pi * radius * length ) + ( pi * radius2 )
This function will calculate the surface area of pyramid.
It takes two arguments: an integer that holds the length of the base of the pyramid, and an integer that holds the slant height of the pyramid. It returns a floating point value: the calculated surface area.
The formula for calculating the surface area of a pyramid is:
Surface Area of Pyramid = ( 2 * length * height ) + length2
At the top of the C++ source code, include a documentation box like normal.
As with the previous assignments and the assignments until the end of the semester, complete program documentation is required. For this assignment, that means that line documentation (in main and the functions) AND function documentation boxes are needed. In regards to line documentation, there is no need to document every single line, but logical "chunks" of code should be preceded by a line or two that describes what the "chunk" of code does.
Each function must have a documentation box explaining:
/*************************************************************** * Function Name * * A brief description of what the function does * * @param arg_name_1 brief description of the first argument * @param arg_name_2 brief description of the second argument * @param arg_name_3 brief description of the third argument * * @return a brief description of the possible return value(s) * * @note an optional note about the function that may be of * interest to someone using it ***************************************************************/
For example, the Menu function might start with:
/*************************************************************** * Menu * * This function displays a menu of options to the user and gets * their choice * * @param none * * @return an integer value between 1 and 5 that is the user's * choice of which area to calculate (1 through 4) or * to stop running the program (5) ***************************************************************/
See the documentation standards on the course webpage for more examples or if further clarification is needed.
The main routine that has been provided may not be altered in the source code that is graded. However, as the program is being developed, you may comment out some of the function calls so that the functions can be coded one at a time. You may also want to think about making the loop execute fewer times as you're developing the functions.
Hand in a copy of the source code (the CPP file) on the autograder and Blackboard.
A run of the program might resemble the following:
Surface Area Calculator 1) Sphere 2) Cone 3) Rectangular Prism 4) Pyramid 5) Quit Enter your choice: 1 Enter the radius for the sphere (1 - 10): 7 The surface area of a sphere with radius 7 is 615.7516 Surface Area Calculator 1) Sphere 2) Cone 3) Rectangular Prism 4) Pyramid 5) Quit Enter your choice: 2 Enter the radius of the base of the cone (1 - 7): 10 10 is an invalid value. Try again: 5 Enter the length of the side of the cone (1 - 12): 21 21 is an invalid value. Try again: 1 The surface area of a cone with radius 5 and side length 1 is 94.2477 Surface Area Calculator 1) Sphere 2) Cone 3) Rectangular Prism 4) Pyramid 5) Quit Enter your choice: 3 Enter the length of the side of the prism (1 - 20): 13 Enter the width of the side of the prism (1 - 20): 4 Enter the height of the side of the prism (1 - 20): 2 The surface area of the prism with length 13 width 4 and height 2 is 172.0000 Surface Area Calculator 1) Sphere 2) Cone 3) Rectangular Prism 4) Pyramid 5) Quit Enter your choice: 4 Enter the length of the base of the pyramid (1 - 10): 5 Enter the slant height of the pyramid (1 - 15): 17 17 is an invalid value. Try again: 15 The surface area of the pyramid with base 5 and slant height 15 is 175.0000 Surface Area Calculator 1) Sphere 2) Cone 3) Rectangular Prism 4) Pyramid 5) Quit Enter your choice: -12 -12 is an invalid choice. Try again: 9 9 is an invalid choice. Try again: 2 Enter the radius of the base of the cone (1 - 7): 4 Enter the length of the side of the cone (1 - 12): 6 The surface area of a cone with radius 4 and side length 6 is 125.6636 Surface Area Calculator 1) Sphere 2) Cone 3) Rectangular Prism 4) Pyramid 5) Quit Enter your choice: 5