C++ Ask for B2 ONLY Problem B1 The volume of a cone is given by the formula: V =
ID: 3694812 • Letter: C
Question
C++
Ask for B2 ONLY
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:
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:
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
height a double, the height of the cone radius a double, the radius of the base of the coneExplanation / Answer
Please write the program as mentioned below and Apply your changes in the IDE and do the experiments for your targeted results .
#include <ionstream>
#include <string>
using namespace std;
int main ()
{
//User inputs cone's radius.
cout << "Input cone's radius.";
cin >> r;
//User inputs cone's height.
cout << "Input cone's height.";
cin >> ;
//Declares pi, r, h, v.
const float pi = 3.14159;
float = r
float = h
float = v
//Caculates the cone's volume.
v = (1/3) * pi * (r*r) * h
//Output to screen.
cout << "The volume of the cone is " << v;
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.