1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
const double PI = 3.14159265358979323846;
class Cone
{
private:
int height;
int radius;
public:
void setUp(int, int);
int getVolume();
void output();
};
void input(Cone *);
void setUp(Cone *, int, int);
int getVolume(Cone *);
void output(Cone *);
/* ******************main***********************
has 3 variables, new to obtain space, calls input, setUp and output.
*/
int main()
{
struct Cone *ptr = new Cone;
double height;
double radius;
input(ptr);
setUp(ptr, 6, 2);
output(ptr);
return 0;
}
/* ******************input***********************
takes height and radius as base of reference, reads in height and radius from user.
*/
void input(Cone * ptr)
{
int height, radius;
cout << "Enter height of the cone followed by the radius." << endl;
cin >> height;
cin >> radius;
ptr.setUp(height, radius);
cout << endl;
}
/* ******************setUp***********************
takes 2 parameters by value, height and radius .
*/
void Cone::setUp(int paramHeight, int paramRadius)
{
cout << "Now running function setUp" << endl << endl;
height = paramHeight;
radius = paramRadius;
}
/* ******************getVolume***********************
computers and returns volume.
*/
int Cone::getVolume()
{
int Volume;
Volume = ( PI * radius * radius * height ) / 3;
return Volume;
}
/* ******************output***********************
calls getvolume to get the volume. prints height and radius..
*/
void Cone::output()
{
cout << "Here is the volume of a cone with radius " << radius << " and height " << height
<< " \nrounded down to the nearest whole number" << endl;
cout << "Volume: " << getVolume() << endl;
}
/* Execution Results
*/
|