#include<iostream>
#include<math.h>
using namespace std;
class Shape{
public:
void Area(){
cout<<"The area of the shape must be calculated"<<endl;
}
};
class Rectangle: public Shape{
private:
int length, width;
public:
Rectangle(int l, int w){
length = l;
width = w;
}
Area(){
cout<<"The area of the rectangle is \t"<<length * width;
}
};
class Triangle: public Shape{
private:
int side;
public:
Triangle(int n){
side = n;
}
//Equilateral all angles are 60. Therefore, we use 0.5*side* side * sin 60
Area(){
cout<<"The area of the triangle is\t"<<0.5 * side * side * (sqrt(3) /2) <<endl;
}
};
int main(){
Triangle t(8);
t.Area();
Rectangle rec(6,7);
rec.Area();
}
Comments
Leave a comment