/*
*copyright(c) 2016,烟台大学计算机学院
*All rights reserved
*文件名称:test.cpp
*作者:李硕
*版本:Code::Blocks
*
*问题描述:宣告主权
*输入描述:
*程序输出:
*/
#include <iostream>
using namespace std;
class Bulk
{
public:
Bulk(double a=1.0,double b=1.0,double c=1.0 ):length(a),width(b),heigth(c){};
void S();
void V();
void get_value();
private:
double length;
double width;
double heigth;
};
void Bulk::S()
{
double s;
s=heigth*length*2+heigth*width*2+length*width*2;
cout<<"表面积是:"<< s<<endl;
}
void Bulk::V()
{
double v;
v=heigth*width*length;
cout<<"体积是:"<< v<<endl;
}
void Bulk::get_value()
{
cout<<"请输入第五个圆柱的参数:";
cin>>heigth>>width>>length;
}
int main()
{
int i;
Bulk b[5]={Bulk(2.3,4.5,6.7),Bulk(1.5,3.4),Bulk(10.5)};
b[4].get_value();
//下面分别输出这5个长方柱的体积和表面积
for(i=0;i<5;i++)
{
b[i].S();
b[i].V();
}
}
<img src="https://img-blog.csdn.net/20160428193518791?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />