home *** CD-ROM | disk | FTP | other *** search
- /****************************************************************************
- This program was made by Andrew Wong and is strictly freeware.
- Feel free to distribute this to your friends.
- Please forward any questions or comments to mwong@acay.com.au
- Disclaimer: I take no responsibility for the use of this product.
- *****************************************************************************/
-
-
- #ifndef IOSTREAM_H
- #define IOSTREAM_H
- #include<iostream.h>
- #endif
-
- const double pi = 3.14159265359; //global constant
-
- class CircularShape
- {
-
- public:
-
- CircularShape() {}
- CircularShape(double radius): itsradius(radius) {}
- virtual ~CircularShape() {}
-
- double getradius() const {return itsradius;}
-
- void setheight(double height) {itsheight = height;}
- void setradius(double radius) {itsradius = radius;}
-
- virtual double gethemisphere() const {return 0;}
- virtual double getsurfaceArea() const
- {
- return (pi * (itsradius * itsradius));
- }
-
- protected:
-
- double itsradius;
- double itsheight;
- };
-
-
- class Circle : public CircularShape
- {
- public:
-
- double getcircumference() const
- {
- return (2 * pi * itsradius); //formula for circumference
- }
- };
-
-
- class Sphere : public CircularShape
- {
- public:
-
- double getsurfaceArea() const
- {
- return (4 * pi * (itsradius * itsradius)); //formula for SA
- }
-
- double gethemisphere() const
- {
- return (3 * pi * (itsradius * itsradius)); //formula for SA
- }
- };
-
-
- class Cylinder : public Circle
- {
- public:
-
- double getsurfaceArea() const
- { //formula for SA
- return ((pi * (itsradius * itsradius)) + (getcircumference() * itsheight));
- }
-
- };
-
-
- class Cone : public Circle
- {
- public:
-
- double getsurfaceArea() const
- { //formula for SA of cone
- return (pi * itsradius * itsheight);
- }
-
- };
-
-
- int main()
- {
- short int choice = 1;
- short int number = 1;
- double radius;
- double height;
- CircularShape *pshape = 0;
-
- cout << "This program was made by Andrew Wong and is strictly freeware\n";
- cout << "Feel free to distribute this to your friends\n";
- cout << "Please forward any questions or comments to mwong@acay.com.au\n";
- cout << "Disclaimer: I take no responsibility for the use of this product\n\n";
- cout << "This program finds out the surface area of all circular shapes\n";
- cout << "Never enter anything besides numbers!!\n";
- cout << "If you do, the program will crash!!!\n";
-
- while(choice != 0)
- {
- cout << "\nWhat circular shape do you want to find the surface area of \n";
- cout << "(0)quit, (1)circle, (2)cone, (3)cylinder, (4)sphere ";
- cin >> choice;
-
- switch(choice)
- {
- case 1: pshape = new Circle; break;
- case 2: pshape = new Cone; break;
- case 3: pshape = new Cylinder; break;
- case 4: pshape = new Sphere; break;
- default: cout << "\ngoodbye\n";
- pshape = 0; break;
- }
-
- if((choice < 1) || (choice > 4)) //is choice a valid number?
- {
- break;
- }
-
- cout << "\nPlese enter the radius\n";
- cin >> radius;
- pshape->setradius(radius);
-
- if((choice == 2) || (choice == 3)) //does the shape require a height?
- {
- cout << "\nPlease enter the hieght\n";
- cin >> height;
- pshape->setheight(height);
- }
-
- if(choice == 4)
- {
- cout << "\nDo you want the SA of the (1)whole sphere or a (2)hemisphere? \n";
- cin >> number;
-
- while((number < 1) || (number >2))
- {
- cout << "Sorry, that is not a valid choice\n";
- cout << "Please eneter a new choice ";
- cin >> number;
- }
-
- if(number == 1)
- { cout << "\nThe surface are of the sphere is:\t";
- cout << pshape->getsurfaceArea();
- }
- else
- { cout << "\nThe surface are of the hemisphere is:\t";
- cout << pshape->gethemisphere();
- }
- }
- else
- { cout <<"\nThe surface are of your shape is:\t";
- cout << pshape->getsurfaceArea();
- }
- delete pshape;
- pshape = 0;
- }
- return 0;
- }
-