您的位置:首页 > 其它

第四周项目3-用对象数组操作长方柱类

2015-03-31 15:57 134 查看
问题及代码:

/*

*Copyright (c) 2015,烟台大学计算机学院

*All rights reserved.

*文件名称:test.cop

*作者:

*完成日期:2015年3月31日

*版本号:v1.0

*

*问题描述:

*输入描述:

*输出描述
#include <iostream>

using namespace std;
class Bulk
{
private:
double length;
double width;
double heigth;
public:
Bulk(double a=1.0,double b=1.0,double c=1.0):length(a),width(b),heigth(c){}
void get_value();

void display();
};
int main()
{
Bulk b[5]={Bulk(2.3,4.5,6.7),Bulk(1.5,3.4),Bulk(10.5)};
b[4].get_value();
//下面分别输出这5个长方柱的体积和表面积
int n;
for(n=0;n<=4;n++)
{
cout<<"第"<<n<<"个长方柱:"<<endl;
b
.display();
}
}
void Bulk::get_value()
{

cout<<"输入第五个长方柱的长(length),宽(width),高(heigth)"<<endl;
cin>>length>>width>>heigth;

}

void Bulk::display()
{
cout<<"表面积为: "<<2*(length*width+length*heigth+width*heigth)<<'\t';
cout<<"体积为: "<<length*width*heigth<<endl;
}


运行结果:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: