Created
February 1, 2014 00:38
-
-
Save svenoaks/8746230 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define _USE_MATH_DEFINES | |
#define L_TO_CU_FT 28.32 | |
#include <iostream> | |
#include <math.h> | |
#include <sstream> | |
using namespace std; | |
void getDimensions(double&, double&); | |
double inputDouble(string prompt); | |
double getShippingCost(); | |
struct point3d | |
{ | |
double x, y, z; | |
point3d(double x = 0.0, double y = 0.0, double z = 0.0) | |
{ | |
this->x = x; | |
this->y = y; | |
this->z = z; | |
} | |
}; | |
class circleType | |
{ | |
protected: | |
double radius; | |
public: | |
void setRadius(double r) | |
{ | |
if (r >= 0) | |
radius = r; | |
else | |
radius = 0; | |
} | |
double getRadius() | |
{ | |
return radius; | |
} | |
double area() | |
{ | |
return M_PI * radius * radius; | |
} | |
double circumference() | |
{ | |
return 2 * M_PI * radius; | |
} | |
void print() | |
{ | |
cout << "Radius: " << getRadius() << " " << "Area: " | |
<< area() << "Circumference: " << circumference(); | |
} | |
circleType(double r) | |
{ | |
setRadius(r); | |
} | |
}; | |
class cylinderType : public circleType | |
{ | |
double height; | |
point3d centerOfBase; | |
public: | |
cylinderType(double radius, double height) : circleType(radius) | |
{ | |
this->height = height; | |
} | |
cylinderType(double radius, double height, point3d centerOfBase) | |
: cylinderType(radius, height) | |
{ | |
this->centerOfBase = centerOfBase; | |
} | |
void setHeight(double height) | |
{ | |
this->height = height; | |
} | |
void setCenterOfBase(point3d centerOfBase) | |
{ | |
this->centerOfBase = centerOfBase; | |
} | |
double volume() | |
{ | |
return height * M_PI * radius * radius; | |
} | |
double surfaceArea() | |
{ | |
return 2 * M_PI * radius * radius | |
+ 2 * M_PI * radius * height; | |
} | |
void printVolume() | |
{ | |
cout << volume(); | |
} | |
void printSurfaceArea() | |
{ | |
cout << surfaceArea(); | |
} | |
}; | |
int main() | |
{ | |
double radius_f, height_f; | |
double shippingCost_l, paintCost_sf; | |
radius_f = inputDouble("Enter the radius of the cylinder in feet: "); | |
height_f = inputDouble("Enter the height of the cylinder in feet: "); | |
shippingCost_l = inputDouble("Enter the shipping cost per liter: "); | |
paintCost_sf = inputDouble("Enter the paint cost per square foot: "); | |
cylinderType cylinder = { radius_f, height_f }; | |
double shippingCost_cf = shippingCost_l / L_TO_CU_FT; | |
cout << endl; | |
cout.precision(2); | |
cout << "The shipping cost of the cylinder is: " | |
<< "$" << fixed << shippingCost_cf * cylinder.volume() << endl; | |
cout << "The cost of painting the cylinder is: " | |
<< fixed << "$" << paintCost_sf * cylinder.surfaceArea() << endl; | |
cout << endl; | |
system("pause"); | |
} | |
double inputDouble(string prompt) | |
{ | |
double result; | |
stringstream convert; | |
do | |
{ | |
string in; | |
convert.clear(); | |
cout << prompt; | |
cin >> in; | |
convert.str(in); | |
} while (!(convert >> result)); | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment