/*
* Copyright (c) 2011, 烟台大学计算机学院
* All rights reserved.
* 作 者:王静
* 完成日期:2013 年 4 月 2 日
* 版 本 号:v1.0
* 输入描述:
* 问题描述:
* 程序输出:
* 问题分析:
* 算法设计:略
*/
#include<iostream>
#include<cmath>
using namespace std;
class Bulk
{private:
double length;
double width;
double heigth;
public:
Bulk(double l=1,double w=1,double h=1);
void show();
double meter(void);//计算长方柱的体积
double volume(void);//计算并返回长方柱的表面积
void get_value();
};
Bulk::Bulk(double l,double w,double h)
{
length=l;width=w;heigth=h;
}
void Bulk::get_value()
{
cout<<"请输入长方柱的长,宽,高"<<endl;
cin>>length>>width>>heigth;
}
void Bulk::show()
{
cout<<"长方柱的长为"<<length<<"宽为"<<width<<"高为"<<heigth<<endl;
}
double Bulk::meter()
{
double met;
met=(length*width+length*heigth+width*heigth)*2;
return met;
}
double Bulk::volume()
{
double vol;
vol=length*width*heigth;
return vol;
}
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].show();
cout<<"表面积为"<<b[0].meter()<<endl;
b[1].show();
cout<<"体积为"<<b[1].volume()<<endl;
b[2].show();
cout<<"表面积为"<<b[2].meter()<<endl;
b[3].show();
cout<<"体积为"<<b[3].volume()<<endl;
b[4].show();
cout<<"表面积为"<<b[4].meter()<<endl;
cout<<"体积为"<<b[4].volume()<<endl;
return 0;
}
运行结果:
(贴图)
心得体会: