Answer to Question #156577 in C++ for Odee

Question #156577

IN THE FORM OF OBJECT ORIENTED PROGRAMMING, C++, CREATE A PROGRAM THAT COMPUTES THE AREA OF A GIVEN RECTANGLE, AREA OF A CIRCLE AND AREA OF A TRIANGLE.



1
Expert's answer
2021-01-21T03:19:28-0500
#include <iostream>
#include <cmath>
using namespace std;
class Area {
    public : 
        int length;
        int width;
        int radius;
        int base;
        int height;
};
class Rectangle : public Area {
    public :
        void getParametrsRectangle() {
            cout << "Enter length of a Rectangle: ";
            cin >> length;
            cout << "Enter width of a Rectangle: ";
            cin >> width;
        }
        void getAreaRectangle() {
            cout << "Area of Rectangle: " << length * width;
        }
};
class Circle : public Area {
    public : 
        void getParametrCircle() {
            cout << "\nEnter radius of a Circle: ";
            cin >> radius;
        }
        void getAreaCircle() {
            cout << "Area of Rectangle: " << 3.1416 * pow(radius, 2);
        }
};
class Triangle : public Area {
    public : 
        void getParametrsTriangle() {
            cout << "\nEnter base of a Triangle: ";
            cin >>  base;
            cout << "Enter height of a Triangle: ";
            cin >> height;
        }
        void getAreaTriangle() {
            cout << "Area of Triangle: " << 0.5 * base * height;
        }
};
int main () {
    Rectangle rectangle;
    Circle circle;
    Triangle triangle;
    rectangle.getParametrsRectangle();
    rectangle.getAreaRectangle();
    circle.getParametrCircle();
    circle.getAreaCircle();
    triangle.getParametrsTriangle();
    triangle.getAreaTriangle();
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog