-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hierarchical.cpp
115 lines (109 loc) · 2.36 KB
/
Hierarchical.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
//Hierarchical
#include<iostream>
#include<math.h>
using namespace std;
class Area
{
protected:
float area;
public:
Area()
{
area = 0;
}
};
class Rectangle:public Area
{
private:
float length;
float width;
public:
void get()
{
cout<<"Enter the length of Rectangle => ";
cin>>length;
cout<<"Enter the width of Rectangle => ";
cin>>width;
}
Rectangle()
{
get();
}
Rectangle(float a, float b)
{
length = a;
width = b;
}
void show()
{
area = length*width;
cout<<"Area of Rectangle : "<<area<<endl;
}
};
class IsosalasTriangle:public Area
{
private:
float side_a;
float side_b;
public:
void get1()
{
cout<<"Enter the side 'a' of Isosalas Triangle => ";
cin>>side_a;
cout<<"Enter the side 'b' of Isosalas Triangle => ";
cin>>side_b;
}
IsosalasTriangle()
{
get1();
}
void show1()
{
area = side_b*sqrt((4*pow(side_a,2) - pow(side_b,2)))/4;
cout<<"Area of Isosalas Triangle : "<<area<<endl;
}
};
class Cylinder:public Area
{
private:
float radius;
float height;
public:
void get2()
{
cout<<"Enter the base radius of cylinder => ";
cin>>radius;
cout<<"Enter the height Of cylinder => ";
cin>>height;
}
Cylinder()
{
get2();
}
Cylinder(float a, float b)
{
radius = a;
height = b;
}
void show2()
{
area = 3.14*pow(radius,2)*height;
cout<<"Area of Cylinder : "<<area<<endl;
}
};
int main()
{
Rectangle R;
cout<<"------------------------------"<<endl;
R.show();
cout<<"************************************"<<endl;
IsosalasTriangle T;
cout<<"------------------------------"<<endl;
T.show1();
cout<<"************************************"<<endl;
Cylinder C;
cout<<"------------------------------"<<endl;
C.show2();
cout<<"************************************"<<endl;
return 0;
}