实验目的:用成员函数实现功能
实验内容:求三个长方体的体积
* 程序头部注释开始
* 程序的版权和版本声明部分
* Copyright (c) 2012, 烟台大学计算机学院学生
* All rights reserved.
* 文件名称:掌握类程序书写规则
* 作
* 完成日期:2012年 3月 5日
* 版 本 号:v03.054
* 对任务及求解方法的描述部分
* 输入描述:……
* 问题描述:……
* 程序输出:……
* 程序头部的注释结束
#include<iostream>
using namespace std;
class Box
{
public:
void get_value();
void volume();
void display();
private:
float length;
float width;
float height;
float vol;
};
void Box::get_value()
{
cout << "请输入长、宽、高:" << endl;
cin >> length;
cin >> width;
cin >> height;
}
void Box::volume()
{
vol = length * width * height;
}
void Box::display()
{
cout << vol << endl;
}
int main()
{
Box box1,box2,box3;
box1.get_value();
box1.volume();
cout << "箱子的体积为:";
box1.display();
box2.get_value();
box2.volume();
cout << "箱子的体积为:";
box2.display();
box3.get_value();
box3.volume();
cout << "箱子的体积为:";
box3.display();
return 0;
}