Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //yeo punya
- //MTQ2
- #include <iostream>
- #include <string>
- #define PI 3.141592654
- using namespace std;
- class Polygon{
- string type;
- double sphere, cylinder;
- public:
- static double m_TotalAreaSphere, m_TotalAreaCyld;
- Polygon(string t, double r, double h){
- type = t;
- if (t == "S"){
- sphere = 4 * 3.14159 * r * r;
- }
- else if (t == "C"){
- cylinder = (2 * PI * r * r) + (2 * PI * r * h);
- }
- else{
- sphere = 0;
- cylinder = 0;
- }
- }
- void Print(){
- cout << "Area of ";
- if (type == "S"){
- m_TotalAreaSphere += sphere;
- cout << "Sphere (cm2): " << sphere << endl << endl;
- }
- else{
- m_TotalAreaCyld += cylinder;
- cout << "Cylinder (cm2) " << cylinder << endl << endl;
- }
- }
- };
- double Polygon::m_TotalAreaSphere = 0.0;
- double Polygon::m_TotalAreaCyld = 0.0;
- int main()
- {
- string type;
- double radius, height;
- for(int i = 0; i < 4; i++){
- cout << "Specify polygon type (S for sphere or C for cylinder): ";
- cin >> type;
- cout << "Specify radius and height: ";
- cin >> radius >> height;
- Polygon polyobj(type, radius, height);
- polyobj.Print();
- }
- cout << "Total area for Sphere (cm2): " << Polygon::m_TotalAreaSphere << endl;
- cout << "Total area for Cylinder (cm2): " << Polygon::m_TotalAreaCyld << endl << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement