-
Notifications
You must be signed in to change notification settings - Fork 3
/
Cicle.cc
82 lines (73 loc) · 1.12 KB
/
Cicle.cc
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
///
/// @file Cicle.cc
/// @author yll(1711019653@qq.com)
/// @date 2019-01-29 09:10:44
///
#include<math.h>
#include <iostream>
using std::cout;
using std::endl;
#define PI 3.1415926
class Cicle
{
public:
Cicle()
:_radius(0)
{
cout << "Cicle()" << endl;
}
Cicle(double r)
:_radius(r)
{
cout << "Cicle(double r)" << endl;
}
//面积
double getArea()
{
return pow(_radius, 2)*PI ;
}
//周长
double getPerimeter()
{
return 2*PI*_radius ;
}
void show()
{
cout << "Cicle's radius = " << _radius <<endl
<< "Cicle's Area = " << getArea() << endl
<< "Cicle's Perimeter = " << getPerimeter() << endl;
}
~Cicle() { cout << "~Cicle()" << endl; }
private:
double _radius;
};
class Cylinder
:public Cicle
{
public:
Cylinder(double r, double h)
:Cicle(r)
,_high(h)
{
cout << "Cylinder(double double)" << endl;
}
double getVolume()
{
return getArea()*_high;
}
void show()
{
cout << "Volume = " << getVolume() << endl;
}
private:
double _high;
};
int main(void)
{
Cicle c1(2);
c1.show();
cout << "---圆柱---" << endl;
Cylinder v1(2,2);
v1.Cicle::show();
v1.show(); //隐藏
}