Answer to Question #156212 in C++ for GELO

Question #156212

In the form of Object-Oriented programming, create an equivalent program of the program from the first one. Create new source file and copy the given second program from. below


FIRST PROGRAM:

#include <iostream>

#include <cmath>

using namespace std;


void getArea(int length, int width, int radius) {

int recta;

float cira;

recta = length * width;

cira = 3.1416 * pow(radius, 2);

cout << "Area of Rectangle: " << recta << endl;

cout << "Area of Circle: " << cira << endl;

}

int main() {


int rectlength, rectwidth, cirradius;

cout << "Enter length of a Rectangle: ";

cin >> rectlength;

cout << "Enter width of a Rectangle: ";

cin >> rectwidth;

cout << "Enter radius of a Circle: ";

cin >> cirradius;


getArea(rectlength, rectwidth, cirradius);


return 0;

}



SECOND:#include <iostream>

#include <cmath>

using namespace std;


class Rectangle {

public:

int length, width;


double getArea(void) {

return length * width;

}

};


class Circle {

public:

int radius;


double getArea(void) {

return 3.1416 * pow(radius, 2);

}

};;


int main(){

Rectangle R;

Circle A;


cout << "Enter length of a Rectangle: ";

cin >> R.length;

cout << "Enter width of a Rectangle: ";

cin >> R.width;


cout << "Enter radius of a Circle: ";

cin >> A.radius;


cout << "Area of a Rectangle = " << R.getArea() << endl;

cout << "Area of a Circle = " << A.getArea() << endl;


}



1
Expert's answer
2021-01-19T04:15:27-0500
#include <iostream>
#include <cmath>
using namespace std;
class Area {
    public : 
        int length;
        int width;
        int radius;
    void getParametrs() {
        cout << "Enter length of a Rectangle: ";
        cin >> length;
        cout << "Enter width of a Rectangle: ";
        cin >> width;
        cout << "Enter radius of a Circle: ";
        cin >> radius;
    }
};
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 getParametrsCircle() {
            cout << "\nEnter radius of a Circle: ";
            cin >> radius;
        }
        void getAreaCircle() {
            cout << "Area of Rectangle: " << 3.1416 * pow(radius, 2);
        }
};
int main () {
    Rectangle rectangle;
    Circle circle;
    rectangle.getParametrsRectangle();
    rectangle.getAreaRectangle();
    circle.getParametrsCircle();
    circle.getAreaCircle();
    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