长方体类的 计算
/** 程序的版权和版本声明部分* Copyright (c)2012, 烟台大学计算机学院学生* All rightsreserved.* 文件名称: x.cpp* 作者:徐本锡* 完成日期: 2013年 4 月3 日* 版本号: v1.0* 输入描述:* 问题描述: 长方体* 程序输出:*///我的代码:#include <iostream>#include <stdlib.h>using namespace std;class Bulk{public : Bulk(double x=1.0,double y=1.0,double z=1.0):length(x),width(y),heigth(z){} double v(); double s(); void in();private : double length; double width; double heigth;};void Bulk::in(){cout<<"请输入长 宽 高 "<<endl;cin>>length>>width>>heigth;}double Bulk::v()//体积{ cout<<"体 积:"<<length*width*heigth;return 0; }double Bulk::s()//面积{ cout<<"表面积:"<<(2*length*width+2*length*heigth+2*width*heigth);return 0;}int main(){ Bulk b[5]={Bulk(2.3,4.5,6.7),Bulk(1.5,3.4),Bulk(10.5)}; b[4].in(); for(int i=0;i<5;i++) { cout<<"第"<<i+1<<"个长方体:"<<endl; b[i].v();cout<<endl; b[i].s();cout<<endl; } return 0;}
