/*
* 程序的版权和版本声明部分:
* Copyright (c) 2013, 烟台大学计算机学院
* All rights reserved.
* 文件名称:test.cpp
* 作 者:周经纬
* 完成日期:2014年 4月 2日
* 版 本 号:v12.1
* 长方柱类
* 输入描述:无
* 问题描述:。
* 程序输出:
* 问题分析:略
* 算法设计:略
*/
#include <iostream>
using namespace std;
class Bulk
{
public:
Bulk(double x=1.0,double y=1.0,double z=1.0):lengh(x),width(y),height(z) {};
void get_value();
void display();
private:
double lengh;
double width;
double height;
};
void Bulk::get_value()
{
cout<<"请输入长,宽,高:";
cin>>lengh;
cin>>width;
cin>>height;
}
void Bulk::display()
{
cout<<" 体积是: "<<lengh*width*height<<endl;
cout<<" 表面积是: "<<2*(lengh*width+lengh*height+width*height)<<endl;
cout<<endl;
}
int main()
{
Bulk b[5]= {Bulk(2.3,4.5,6.7),Bulk(1.5,3.4),Bulk(10.5)};//第一个确定了长宽高,第二个确定了长款,高用的默认的1,第三个只有长是赋值的。
b[4].get_value();
//下面分别输出这个长方柱的体积和表面积
for(int i=0; i<5; ++i)
{
cout<<"关于b["<<i<<"]"<<endl;
b[i].display();
}
return 0;
}
这个整明白了,这个public跟这周的第二个差不多。我看看这周第二个会了吧、、、