/*copyright(c)2016.烟台大学计算机学院
* All rights reserved,
* 文件名称:text.Cpp
* 作者:舒文超
* 完成日期:2016年4月17日
* 版本号:vc++6.0
*
* 问题描述: 输入长方柱的长宽高,求长方柱的体积与表面积
*/
#include<iostream>
using namespace std;
class Bulk
{
public:
Bulk(double x=1.0,double y=1.0,double z=1.0):length(x),width(y),height(z){};
void get_value();
void output_value();
private:
double length;
double width;
double height;
};
void Bulk::get_value()
{
cout<<"please input the length"<<endl;
cin>>length;
cout<<"please input the width"<<endl;
cin>>width;
cout<<"please input the height"<<endl;
cin>>height;
}
void Bulk::output_value()
{
cout<<"长方柱体积为:"<<endl;
cout<<length*width*height<<endl;
cout<<"长方柱表面积为:"<<endl;
cout<<2*((length*width)+(length*height)+(width*height))<<endl<<endl;
}
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 i;
for(i=0;i<5;i++)
{
cout<<"长方柱"<<i<<"基本数据:"<<endl;
b[i].output_value();
}
return 0;
}
第八周项目二 用对象数组操作长方柱类
最新推荐文章于 2016-05-30 19:34:29 发布