第五周实验报告(三)

01.#include <iostream>  
02.#include <cmath>  
03.  
04.using namespace std;  
05.class Box  
06.{  
07.public:  
08.    void volume();  
09.    void area();  
10.    void set();  
11.    Box (int h = 18,int w = 20,int len = 36):height(h),width(w),length(len){}  
12.private:  
13.    double length;  
14.    double width;  
15.    double height;  
16.};  
17.int main()  
18.{  
19.    Box a[5] = {  
20.  
21.    Box(10,12,15),  
22.    Box(15,18,20),  
23.    Box(16,20,26),  
24.    };  
25.  
26.    a[4].set();  
27.  
28.    cout << "the volume of a[0] is: " << endl;  
29.    a[0].volume();  
30.    cout << "the area of a[0] is: " <<  endl;  
31.    a[0].area();  
32.  
33.    cout << "the volume of a[0] is: " << endl;  
34.    a[1].volume();  
35.    cout << "the area of a[0] is: " << endl;  
36.    a[1].area();  
37.  
38.    cout << "the volume of a[0] is: " << endl;  
39.    a[2].volume();   
40.    cout << "the area of a[0] is: " << endl;  
41.    a[2].area();  
42.  
43.    cout << "the volume of a[0] is: " << endl;  
44.    a[3].volume();  
45.    cout << "the area of a[0] is: " << endl;  
46.    a[3].area();  
47.  
48.    cout << "the volume of a[4] is: " << endl;  
49.    a[4].volume();  
50.    cout << "the area of a[4] is: " << endl;  
51.    a[4].area();  
52.  
53.    system("pause");  
54.  
55.    return 0;  
56.}  
57.  
58.void Box::area()  
59.{  
60.    double ar;  
61.  
62.    ar=2*(length * height + length * width + height * width);  
63.  
64.    cout << ar << endl;  
65.  
66.}  
67.  
68.void Box::volume()  
69.{  
70.    double vol;  
71.  
72.    vol = height * width * length;  
73.  
74.    cout << vol << endl;  
75.}  
76.  
77.void Box::set()  
78.{  
79.    cin >> height >> length >> width;  
80.}  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值