您的位置:首页 > 其它

第五周项目3-对象数组操作长方体类

2014-03-25 11:45 393 查看
/*
*程序的版权和版本声明部分:
*Copyright(c)2014,烟台大学计算机学院学生
*All rights reserved.
*文件名称:
*作者:田成琳
*完成日期:2014  年 3月 25 日
*版本号:v1.0
*对任务及求解方法的描述部分:
*输入描述:第四个长方体的长、宽、高
*问题描述:
*程序输出:5个长方体的面积与体积
*问题分析:
*算法设计:
*/
#include<iostream>
using namespace std;
class Bulk
{
public:
double area();
double volume();
void get_value();
void output();
Bulk(double l=1.0,double w=1.0,double h=1.0);
private:
double length,width,height;
};
Bulk::Bulk(double l,double w,double h)
{
length=l;
width=w;
height=h;
}
void Bulk::get_value()
{
cin>>length>>width>>height;
}
double Bulk::area()
{
return 2*length+2*width+2*height;
}
double Bulk::volume()
{
return length*width*height;
}
void Bulk::output()
{
cout<<area()<<" "<<volume()<<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();
for(int i=0;i<5;i++)
{
cout<<"第"<<i+1<<"个长方体的面积和体积分别为:"<<endl;
b[i].output();
}
return 0;
}

运行结果:



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