-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic3.cpp
More file actions
65 lines (55 loc) · 1.24 KB
/
Copy pathbasic3.cpp
File metadata and controls
65 lines (55 loc) · 1.24 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
#include<iostream>
using namespace std;
class Shape
{
public:
double area;
void area_rec(int x,int y);
void area_c(int r);
Shape() { cout << "这是Shape类的构造函数" << endl; }
~Shape() { cout << "这是Shape类的析构函数" << endl; }
};
class rectangle:public Shape
{
public:
int length;
int width;
rectangle() { cout << "这是rectangle类的构造函数" << endl; }
~rectangle() { cout << "这是rectangle类的析构函数" << endl; }
};
class circle:public Shape
{
public:
int r;
circle() { cout << "这是circle类的构造函数" << endl; }
~circle() { cout << "这是circle类的析构函数" << endl; }
};
class square: public rectangle
{
public:
int side;
square() { cout << "这是square类的构造函数" << endl; }
~square() { cout << "这是square类的析构函数" << endl; }
};
void Shape::area_rec(int x,int y)
{
this->area=x*y;
}
void Shape::area_c(int r)
{
this->area=3.14*r*r;
}
int main()
{
square s;
circle c;
cout << "请输入正方形的边长" <<endl;
cin >> s.side;
s.area_rec(s.side,s.side);
cout<< "正方形面积为:"<< s.area <<endl;
cout << "请输入圆形的半径" << endl;
cin >> c.r;
c.area_c(c.r);
cout << "圆形的面积为:" << c.area << endl;
return 0;
}