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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
|
#include <iostream>
using namespace std;
/***************************************************
* Header file information containing 3 classes
* ************************************************/
class pointType
{
public:
void setCoordinates(double x, double y);
void print() const;
double getX() const;
double getY() const;
pointType();
pointType(double x, double y);
private:
double xCoordinate;
double yCoordinate;
};
class circleType : public pointType
{
public:
void setDimensions(double x, double y, double r);
void print() const;
double getR() const;
double area() const;
double circumference() const;
circleType();
circleType(double x, double y, double r);
private:
double radius;
};
class cylinderType : public circleType
{
public:
void setCylinderDimensions(double x, double y, double r, double h);
void print() const;
double getH() const;
double volume() const;
double surfaceArea() const;
cylinderType();
cylinderType(double x, double y, double r, double h);
private:
double height;
};
/*****************************************************
* Driver file to test classes
* **************************************************/
int main()
{
pointType points;
double x, y;
//points.setCoordinates(x, y);
//points.print();
//cout << points.getX() << endl;
//cout << points.getY() << endl;
circleType circlePoint;
double r;
circlePoint.setDimensions(x, y, r);
circlePoint.print();
//cout << circlePoint.getR() << endl;
cylinderType makeCylinder;
double h;
makeCylinder.setCylinderDimensions(x, y, r, h);
cout << "The area of the circle is: " << circlePoint.area() << endl;
cout << "The circumference of the circle is: " << circlePoint.circumference() << endl;
return 0;
}
/***********************************************************
* pointType class implementation follows below.
* ********************************************************/
void pointType::setCoordinates(double x, double y)
{
cout << "Please enter an X and Y coordiante: ";
cin >> xCoordinate >> yCoordinate;
cout << endl;
}
double pointType::getX() const
{
return xCoordinate;
}
double pointType::getY() const
{
return yCoordinate;
}
void pointType::print() const
{
cout << "The X coordinate is currently set to: " << xCoordinate << endl;
cout << "While the Y coordiate is set to: " << yCoordinate;
cout << endl;
}
pointType::pointType()
{
xCoordinate = 0;
yCoordinate = 0;
}
pointType::pointType(double x, double y)
{
setCoordinates(xCoordinate, yCoordinate);
}
/***********************************************************
* circleType class implementation follows below
* ********************************************************/
void circleType::setDimensions(double x, double y, double r)
{
pointType::setCoordinates(x, y);
cout << "Please enter the size of the circles radius: ";
cin >> radius;
cout << endl;
}
void circleType::print() const
{
pointType::print();
cout << "The radius is: " << radius;
cout << endl;
}
double circleType::getR() const
{
return radius;
}
double circleType::area() const
{
return (3.14159265359 * radius * radius);
}
double circleType::circumference() const
{
return (2 * 3.14159265359 * radius);
}
circleType::circleType()
{
radius = 0;
}
circleType::circleType(double x, double y, double r)
:pointType(x, y)
{
radius = r;
}
/***********************************************************
* cylinderType class implementation follows below
* ********************************************************/
void setCylinderDimensions(double x, double y, double r, double h)
{
circleType::setDimensions(x, y, r);
cout << "Please enter the height to create a cylinder: ";
cin >> height;
cout << endl;
}
void cylinderType::print() const
{
circleType::print();
cout << "The height of the cylinder is: " << height;
cout << endl;
}
double cylinderType::getH() const
{
return height;
}
double cylinderType::volume() const
{
return (3.14159265359 * getR() * getR() * height);
}
double cylinderType::surfaceArea() const
{
return ((2 * 3.14159265359 * getR() * height) + (2 * 3.14159265359 * getR() * getR()));
}
cylinderType::cylinderType()
{
height = 0;
}
cylinderType::cylinderType(double x, double y, double r, double h)
:circleType(x, y, r)
{
height = h;
}
| |