-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcubeplus.cpp
More file actions
53 lines (41 loc) · 884 Bytes
/
Copy pathcubeplus.cpp
File metadata and controls
53 lines (41 loc) · 884 Bytes
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
#include <iostream>
using namespace std;
class cube { //创建类cube
public:
int hei;
int len;
int bre;
void add(int h ,int l ,int b) { //为变量赋值
hei = h;
len = l;
bre = b;
}
int vol() {
return hei* len* bre; //计算方体体积
}
};
class num :public cube { //创建cube的派生类num
public:
int n;
void numb(int a) {
n = a;
}
int vols() {
return vol() * n; //计算所有方体体积之和
}
};
int main() {
num boxnum{}; //创建对象boxnum
int a, b, c, n;
cout << "Enter the cube's height: "; cin >> a;
cout << "Enter the cube's length: "; cin >> b;
cout << "Enter the cube’s bre"; cin >> c;
boxnum.add(a, b, c);
int volum = boxnum.vol(); //输出单个方体体积
cout << "体积:" << volum << endl;
cout << "输入方体个数:"; cin >> n;
boxnum.numb(n);
int volums = boxnum.vols();
cout << "总体积:" << volums << endl; //输出一定数量的方体总体积
return 0;
}