Question: Hi! C++ program again. Help me, please! Each problem - different program. Thank you! Problem B1 The volume of a cone is given by the
Hi! C++ program again. Help me, please! Each problem - different program. Thank you!
Problem B1
The volume of a cone is given by the formula: V = r2 h / 3
For the value of use: const double PI = 3.14159265358979323846;
Declare a structure named: Cone containing:
| height | a double, the height of the cone |
| radius | a double, the radius of the base of the cone |
Create the following functions:
main
Contains three variables:
A pointer named ptr which points to a Cone structure
A double named height
A double named radius
Uses new to obtain space for the data structure
Calls the the input, setUp, and output functions
Deletes the space that was obtained using new
input:
Takes the height of the cone and radius of the base as reference parameters
Reads the height and radius from the user
Has a return type of void
setUp:
Takes three parameters by value: height, radius, and a pointer to the Cone
Puts the data into the data structure
Has a return type of void
getVolume:
Takes one parameter by value: a pointer to the Cone
Computes the volume
Returns the volume
output:
Takes one parameter by value: a pointer to the Cone
Calls the getVolume function to get the volume
Prints the height, radius, and volume in a neat format
Has a return type of void
Put the main function first. Use the function and variable names specified above. Arrange the functions in the order listed above.
Test your program with the following data:
| height | 6 |
| radius | 2 |
Problem B2
Repeat problem B1 with the following changes:
Make Cone a class rather than a struct. Make the height and radius in the class Cone private. Make setUp a public member function in the class Cone. Make getVolume a pubic member function in the class Cone. Make output a public member function in the class Cone. The main and input functions will remain global functions, not part of the Cone class. The main function will call the input, setUp, and output functions. The return types will all be unchanged.
The parameter lists will change for some of the functions:
main unchanged
input unchanged
setUp two parameters by value: height, radius
getVolume no parameters
output no parameters
Test with the same data.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
