Question: As provided in the screenshots and the .cpp file, the goal of this program is to provide the functions for the already existing code .cpp
As provided in the screenshots and the .cpp file, the goal of this program is to provide the functions for the already existing code
.cpp file
/****************************************************************** CSCI 240 Program 6 Part 2 Spring 2023 Programmer: Section: Date Due: Purpose: This program uses functions to calculate the surface area of various shapes. It is an exercise in learning to write functions. ******************************************************************/ #include#include using namespace std; //Symbolic constant for the value of PI const double PI = 3.14159; //Function Prototypes int main() { int menuChoice, //The users choice from the menu radius, //The radius for the sphere and cone length, //The length of the side of the cone, prism, and pyramid height, //The height of the side of the prism and pyramid width; //The width of the side of the prism float surfArea; //The surface area of all of the shapes //Print the surface areas with 4 digits after the decimal points cout
PROGRAM INSTRUCTIONS
Overview
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.
The Functions The following functions are required for this assignment: intMenu() 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: int getValue( string prompt, int lowerBound, int upperBound ) 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 lower bound for the specified range, and an integer that holds the upper bound 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 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 (110) : float calcSphere( int radius ) 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 radius 2 float calcPrism( int length, int width, int height ) 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 ) float calcCone( int radius, int length ) 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 radius 2) float calcPyramid( int length, int slantHeight ) 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 )+ length 2 1. At the top of the C++ source code, include a documentation box like normal. 2. Complete program documentation is required for this assignment. This includes documentation boxes for EACH function that explains: its name its use or function: that is, what does it do? What service does it provide to the code that calls it? a list of its arguments briefly describing the meaning and use of each, and in particular whether the function modifies each one - the value returned (if any) or none. - notes on any unusual features, assumptions, techniques, etc. Function: Use: Arguments: Returns: Notes: 3. Hand in a copy of the source code (CPP file) using Blackboard. Output 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 (110):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 (17):10 10 is an invalid value. Try again: 5 Enter the length of the side of the cone (112):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 (120):13 Enter the width of the side of the prism (120):4 Enter the height of the side of the prism (120):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 (110):5 Enter the slant height of the pyramid (115):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 (17):4 Enter the length of the side of the cone (112):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 The Functions The following functions are required for this assignment: intMenu() 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: int getValue( string prompt, int lowerBound, int upperBound ) 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 lower bound for the specified range, and an integer that holds the upper bound 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 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 (110) : float calcSphere( int radius ) 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 radius 2 float calcPrism( int length, int width, int height ) 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 ) float calcCone( int radius, int length ) 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 radius 2) float calcPyramid( int length, int slantHeight ) 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 )+ length 2 1. At the top of the C++ source code, include a documentation box like normal. 2. Complete program documentation is required for this assignment. This includes documentation boxes for EACH function that explains: its name its use or function: that is, what does it do? What service does it provide to the code that calls it? a list of its arguments briefly describing the meaning and use of each, and in particular whether the function modifies each one - the value returned (if any) or none. - notes on any unusual features, assumptions, techniques, etc. Function: Use: Arguments: Returns: Notes: 3. Hand in a copy of the source code (CPP file) using Blackboard. Output 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 (110):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 (17):10 10 is an invalid value. Try again: 5 Enter the length of the side of the cone (112):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 (120):13 Enter the width of the side of the prism (120):4 Enter the height of the side of the prism (120):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 (110):5 Enter the slant height of the pyramid (115):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 (17):4 Enter the length of the side of the cone (112):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
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts






