2012C++程序设计实验报告【3.3】

来源:互联网 发布:如何挖掘数据的价值 编辑:程序博客网 时间:2024/04/30 14:21

/* (程序头部注释开始)
* 程序的版权和版本声明部分
* Copyright (c) 2011, 烟台大学计算机学院学生
* All rights reserved.
* 文件名称: 立方体的表面积和体积(第三周任务四)
* 作 者: 王琳
* 完成日期: 2012年 3 月17日
* 版 本 号:3-3-1

* 对任务及求解方法的描述部分
* 输入描述:立方体的体积和表面积
* 问题描述: ......
* 程序输出: ......
* 程序头部的注释结束
*/

源程序

01.#include <iostream>  02.using namespace std;  03.class Bulk  04.{  05.public:  06.    void get_value();  07.    void display();  08.private:  09.    float lengh;  10.    float width;  11.    float height;  12.};  13.  14.void Bulk::get_value()  15.{   16.    cout<<"please input lengh, width,height:";  17.    cin>>lengh;  18.    cin>>width;  19.    cin>>height;  20.}  21.  22.void Bulk::display()  23.{   24.    cout<<"The volume is: "<<lengh*width*height<<endl;  25.    cout<<"The surface area is: "<<2*(lengh*width+lengh*height+width*height)<<endl;  26.}  27.  28.int main()  29.{  30.    Bulk b1,b2,b3;  31.  32.    b1.get_value();  33.    cout<<"For bulk1: "<<endl;  34.    b1.display();  35.  36.    b2.get_value();  37.    cout<<"For bulk2: "<<endl;  38.    b2.display();  39.  40.    b3.get_value();  41.    cout<<"For bulk3: "<<endl;  42.    b3.display();  43.    return 0;  44.}   


原创粉丝点击