Answer to Question #179049 in C++ for Hari bashkar

Question #179049

Create a class by name Area and initialize the data members. Then, find areas of square [Area(a)], area of rectangle [Area(l, b)], area of triangle [Area(a, b, c)] using constructor overloading. Also define a destructor to destroy the object.


1
Expert's answer
2021-04-07T04:04:50-0400
#include <iostream>
#include <math.h>

using namespace std;


class Area{
    public:
        double area;
        Area(double a){
            area = a*a;
        }
        Area(double l, double b){
            area = b * l;
        }
        Area(double a, double b, double c){
            float s  = 0.5 * (a + b + c);
            area = sqrt(s * (s - a)*(s - b)*(s - c));
        }
        ~Area(){
            
        };
};
int main()
{
    Area triangle(2,3,4);
    Area square(2);
    Area rect(2,8);
    
    cout<<triangle.area <<endl;
    cout<< square.area << endl;
    cout<<rect.area<< endl;


    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
APPROVED BY CLIENTS