第五周实验报告(三)
2012-03-22 19:40
239 查看
【任务3】编写基于对象的程序,求5个长方柱的体积和表面积。长方柱类的数据成员包括长(length)、宽(width)、高(heigth)等。另外:
(1) 需要定义长方柱类,5个长方柱采用一个对象数组表示;
(2) 前4个长方柱(即数组的前4个元素)要在定义数组时初始化,其中前3个直接给出参数初始化,第4个用默认构造函数初始化;第5个长方柱定义时不初始化,而是由键盘输入长、宽、高赋值;
(3) 输出这5个长方柱的体积和表面积;
迟来的报告3.早就生出来了。就是上不了户口。。。。
(1) 需要定义长方柱类,5个长方柱采用一个对象数组表示;
(2) 前4个长方柱(即数组的前4个元素)要在定义数组时初始化,其中前3个直接给出参数初始化,第4个用默认构造函数初始化;第5个长方柱定义时不初始化,而是由键盘输入长、宽、高赋值;
(3) 输出这5个长方柱的体积和表面积;
#include <iostream> using namespace std; class BOX { private: float length; float width; float high; public: BOX(float h=10,float w=12,float len=15):high(h),width(w),length(len){} void volume(); void s(); void set_data(); }; int main() { BOX a[5] = { BOX(11,11,11), BOX(12,12,12), BOX(13,13,13), }; cout<<"输入第4个长方体的长宽高。" ; a[3].set_data(); for(int i=0;i<5;i++) { cout<<"第"<<i+1<<"个长方体的面积,体积为"; a[i].volume(); a[i].s(); cout<<endl; } system("pause"); return 0; } void BOX::set_data() { cin>>length; cin>>width; cin>>high; } void BOX::volume() { cout<<(length*width*high)<<" "; } void BOX::s() { cout<< (2*(length*width+length*high+width*length)); }
迟来的报告3.早就生出来了。就是上不了户口。。。。
相关文章推荐
- C++程序设计实验报告(四十二)---第五周任务四
- 第五周实验报告(任务一)《使用参数初始化表对数据成员初始化》
- 第五周实验报告(任务二)《长方体的体积和表面积》
- 第五周实验报告(任务四)《学生类》
- 第五周实验报告一——(3)
- 《第五周实验报告3-1》---编写基于对象的程序,求5个长方柱的体积和表面积
- 第五周实验报告2
- 第五周实验报告任务(1-1)
- 第五周实验报告2
- Java第五周实验报告任务一【封装一类三角形对象Triangle】
- 《第五周实验报告4-1》---设计一个学生类,包括学号(num)和成绩(score)
- 第五周实验报告(一)带参数的构造函数
- 第五周实验报告1
- 第五周实验报告(1-2)
- 第五周实验报告 任务一
- 《第五周实验报告任务1》
- 第五周实验报告一——(1)
- 第五周实验报告(一)使用默认构造函数
- 第五周实验报告 1-1
- 第五周实验报告(1-3)