63 215
Assignments Done
99,3%
Successfully Done
In July 2018

Answer to Question #33484 in C++ for vivek kaushik

Question #33484
write object orientedprogram to find areas of following geometricals shapes
1)square
2)rectangle
3)circle
4)triangle
Expert's answer
#include <iostream>
#include <math.h>
#define PI 3.1415


using namespace std;


class square{
public:
void computeArea(){
area = a*a;
}


void getSide(){
cout << "Input value side : ";
cin >> a;
}




void sendArea(){
cout << "The area is: " << area << endl;
}
private:
double a;
double area;
};


class rectangle{
public:
void getSide(){
cout << "Input value sides : ";
cin >> a >> b;
}


void sendArea(){
cout << "The area is: " << area << endl;
}


void computeArea(){
area = a * b;
}
private:
double a, b;
double area;
};


class circle{
public:
void computeArea(){
area = PI * pow(radius, 2);
}


void getSide(){
cout << "Input radius : ";
cin >> radius;
}


void sendArea(){
cout << "The area is: " << area << endl;
}
private:
double radius;
double area;
};


class triangle{
public:
void computeArea(){
double p = (a + b + c) / 2;
area = pow(p * (p - a) * (p - b) * (p - c), 0.5);
}


void getSide(){
cout << "Input sides values : ";
cin >> a >> b >> c;
}


void sendArea(){
cout << "The area is: " << area << endl;
}
private:
double a, b, c;
double area;
};


int main(){
int shapesNum;


cout << "If you ont compute square area input 1" << endl;
cout << "If you ont compute rectangle area input 2" << endl;
cout << "If you ont compute circle area input 3" << endl;
cout << "If you ont compute triangle area input 4" << endl;
cin >> shapesNum;


switch (shapesNum){
case 1:
square mySquare;
mySquare.getSide();
mySquare.computeArea();
mySquare.sendArea();
break;


case 2:
rectangle myRectangle;
myRectangle.getSide();
myRectangle.computeArea();
myRectangle.sendArea();
break;


case 3:
circle myCircle;
myCircle.getSide();
myCircle.computeArea();
myCircle.sendArea();
break;


case 4:
triangle myTriangle;
myTriangle.getSide();
myTriangle.computeArea();
myTriangle.sendArea();
break;


default:
cout << "Invalid number" << endl;
break;


}


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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions