您的位置:首页 > 其它

第三周实验报告(任务二)

2012-03-09 20:38 260 查看
 /* (程序头部注释开始)

* 程序的版权和版本声明部分

* Copyright (c) 2011, 烟台大学计算机学院学生

 * All rights reserved

.* 文件名称:

* 作 者: 张培培

* 完成日期: 2011年 03月 09日

* 版 本 号:

* 对任务及求解方法的描述部分

* 输入描述:输入长方柱的长,宽,高

* 问题描述:利用成员函数输出长方柱的体积和表面积

* 程序输出: 输出长方体的体积和面积

* 程序头部的注释结束*

#include <iostream>

using namespace std;

class Box

{

public:

 void get_value();

 void display();

private:

 float length;

 float width;

 float heigth;

};

void Box::get_value()

{

 cout<<"请输入长方柱的长,宽,高: "<<endl;

 cin>>length;

 cin>>width;

 cin>>heigth;

}

void Box::display()

{

 cout<<"The value is: "<<length*width*heigth<<endl;

 cout<<"The areas is: "<<2*(length+width+heigth)<<endl;

}

int main()

{

 Box box1,box2,box3;

 box1.get_value();

 cout<<"The box1 is: ";

 box1.display();

    box2.get_value();

 cout<<"The box2 is: ";

 box2.display();

    box3.get_value();

 cout<<"The box3 is: ";

 box3.display();

 return 0;

}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  任务 float c