# 第五周任务三

234人阅读 评论(0)
#include <iostream>
#include <cmath>

using namespace std;
class Box
{
public:
void volume();
void area();
void set();
Box (int h = 18,int w = 20,int len = 36):height(h),width(w),length(len){}
private:
double length;
double width;
double height;
};
int main()
{
Box a[5] = {

Box(10,12,15),
Box(15,18,20),
Box(16,20,26),
};

a[4].set();

cout << "the volume of a[0] is: " << endl;
a[0].volume();
cout << "the area of a[0] is: " <<  endl;
a[0].area();

cout << "the volume of a[0] is: " << endl;
a[1].volume();
cout << "the area of a[0] is: " << endl;
a[1].area();

cout << "the volume of a[0] is: " << endl;
a[2].volume();
cout << "the area of a[0] is: " << endl;
a[2].area();

cout << "the volume of a[0] is: " << endl;
a[3].volume();
cout << "the area of a[0] is: " << endl;
a[3].area();

cout << "the volume of a[4] is: " << endl;
a[4].volume();
cout << "the area of a[4] is: " << endl;
a[4].area();

system("pause");

return 0;
}

void Box::area()
{
double ar;

ar=2*(length * height + length * width + height * width);

cout << ar << endl;

}

void Box::volume()
{
double vol;

vol = height * width * length;

cout << vol << endl;
}

void Box::set()
{
cin >> height >> length >> width;
}


0
0

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：28958次
• 积分：788
• 等级：
• 排名：千里之外
• 原创：53篇
• 转载：0篇
• 译文：0篇
• 评论：27条