-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday6_1.cpp
More file actions
99 lines (82 loc) · 1.29 KB
/
day6_1.cpp
File metadata and controls
99 lines (82 loc) · 1.29 KB
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
#include<iostream>
using namespace std;
class Shape
{
public:
virtual void surfaceArea()=0;
virtual void volume()=0;
};
class Cylinder:public Shape
{
float r;
float h;
public:
Cylinder(float r,float h)
{
this->r=r;
this->h=h;
}
void surfaceArea()
{
cout<<endl<<"Surface Area Of Cylinder:"<<2*3.14*r*(r+h);
}
void volume()
{
cout<<endl<<"Volume of Cylinder:"<<3.14*r*r*h;
}
};
class Cube:public Shape
{
float a;
public:
Cube(float a)
{
this->a=a;
}
void surfaceArea()
{
cout<<endl<<"Surface Area Of Cube:"<<6*a*a;
}
void volume()
{
cout<<endl<<"Volume of Cube:"<<a*a*a;
}
};
class Cuboid:public Shape
{
float l;
float b;
float h;
public:
Cuboid(float l,float b,float h)
{
this->l=l;
this->b=b;
this->h=h;
}
void surfaceArea()
{
cout<<endl<<"Surface Area Of Cuboid:"<<2*(l*b+l*h+b*h);
}
void volume()
{
cout<<endl<<"Volume of Cuboid:"<<l*b*h;
}
};
int main()
{
Shape *ptr;
Cylinder c1(2,4.2);
Cube c2(2.6);
Cuboid c3(2,4,6.4);
ptr=&c1;
ptr->surfaceArea();
ptr->volume();
ptr=&c2;
ptr->surfaceArea();
ptr->volume();
ptr=&c3;
ptr->surfaceArea();
ptr->volume();
return 0;
}