求3个长方柱的体积和表面积

来源:互联网 发布:聚成网络网站建设 编辑:程序博客网 时间:2024/04/29 19:32

源程序:

/* (程序头部注释开始)* 程序的版权和版本声明部分* Copyright (c) 2011, 烟台大学计算机学院学生 * All rights reserved.* 文件名称:求3个长方柱的体积和表面积                              * 作    者:2011级 114-3 张宗佳                              * 完成日期:2012 年 03 月07 日* 版 本 号:vc.0          * 对任务及求解方法的描述部分* 输入描述:输入三个长方体的长宽高* 问题描述:仿照你阅读过的程序,编写基于对象的* 程序,求3个长方柱的体积。数据成员包括长(length)、宽(width)、高(heigth)、体积,要求用成员函数实现下面的功能:  * 程序输出:输出三个长方体的长宽高 * 程序头部的注释结束*/#include <iostream>using namespace std;class cuboid{public:void input_volume_areas();void output_volume_areas(); private: int length;int width;int heigth;int volume;int areas;};int main( ){cuboid c1, c2, c3;  c1.input_volume_areas();c1.output_volume_areas();c2.input_volume_areas();c2.output_volume_areas();c3.input_volume_areas();c3.output_volume_areas();return 0;}void cuboid::input_volume_areas(){cout << "输入长方体的长宽高:" ;cin >> length >> width >> heigth;return ;}void cuboid::output_volume_areas(){volume = length * width * heigth;areas = 2 * (length * width + length * heigth + width * heigth);cout << "长方体的体积是:" << volume << endl;cout << "长方体的表面积是:" << areas << endl;return ;}

实验结果:


经验积累:

还好,不算难,主要是成员函数的定义,不能少了"cuboid :: "


原创粉丝点击