/* *Copyright (c) 2016,烟台大学计算机学院 *All rights reserved. *文件名称:test.cpp *作者: 武聪 *完成日期:2016年5月17日 *版本号:v1.0 *问题描述:用对象数组操作长方柱类 15. *输入描述: 16. *程序输出:输出这5个长方柱的体积和表面积 /* #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() { cin>>lengh; cin>>width; cin>>height; } void Bulk::display() { cout<<"体积为:"<<lengh*width*height; cout<<"表面积为:"<<2*(lengh*width)+2*(lengh*height)+2*(width*height); cout<<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(); for(int i=0;i<5;i++) b[i].display(); return 0; }
运行结果:
知识点总结:- 默认函数的使用
- 学习心得:
- 好好努力
06-30
06-30
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交