-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Area and Cost of shapes by inheritance.cpp
82 lines (76 loc) · 1.43 KB
/
Area and Cost of shapes by inheritance.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include<iostream>
using namespace std;
class Shape
{
protected:
int length, breadth, height;
public:
int Area;
Shape()
{
length = breadth = height = Area = 0;
}
virtual int getArea() = 0;
};
class Painting
{
public:
int getCost(int area)
{
int Cost;
Cost = 70 * area;
return Cost;
}
};
class Square : public Shape, public Painting
{
public:
Square(int l)
{
length = l;
}
int getArea()
{
Area = length * length;
return Area;
}
};
class Rectangle : public Shape, public Painting
{
public:
Rectangle(int l, int b)
{
length = l;
breadth = b;
}
int getArea()
{
Area = length * breadth;
return Area;
}
};
class Triangle : public Shape, public Painting
{
public:
Triangle(int h, int b)
{
height = h;
breadth = b;
}
int getArea()
{
Area = 0.5 * height * breadth;
return Area;
}
};
int main()
{
//change the values inside the object to change the area accourding to the condition
Square s(5);
Rectangle r(5, 7);
Triangle t(5, 12);
cout << "Total Area of Square : " << s.getArea() << endl;
cout << "Total Area of Rectangle : " << r.getArea() << endl;
cout << "Total Area of Triangle : " << t.getArea() << endl;
return 0;
}