/*
*Copyright(c) 2016, 烟台大学计算机与控制工程学院
*All rights reserved.
*文件名称:main.cpp
*作 者:李德坤
*完成日期:2016年4月17日
*版本号:v1.0
*
*问题描述:求长方体的表面积和体积
*输入描述:无
*输出描述:长方体的表面积和体积
*/
#include<iostream>
#include<iomanip>
using namespace std;
class Bulk
{
public:
void get_value();
void out_biaoti();
Bulk(float x=1.0,float y=1.0,float z=1.0):length(x),width(y),heigh(z)
{
cout<<"带有默认值构造函数已执行。"<<endl;
}
~Bulk();
private:
float length;
float width;
float heigh;
};
Bulk::~Bulk()
{
cout<<"程序完成。"<<endl;
}
void Bulk::get_value()
{
cout<<"请输入长,宽,高:"<<endl;
cin>>length>>width>>heigh;
}
void Bulk::out_biaoti()
{
float biao,ti;
biao=(length+width)*2*heigh;
ti=length*width*heigh;
cout<<"表面积为:"<<setprecision(3)<<biao<<endl;
cout<<"体积为:"<<ti<<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();
b[0].out_biaoti();
b[1].out_biaoti();
b[2].out_biaoti();
b[3].out_biaoti();
b[4].out_biaoti();
}