问题及代码:
/*
* Copyright (c) 2015, 烟台大学计算机学院
* All rights reserved.
* 文件名称:Project4.cpp
* 作 者:陈旭
* 完成日期:2015年3月16日
* 版 本 号:v1.0
*
* 问题描述:计算长方体的表面积和体积
* 输入描述:略
* 程序输出:略
*/
#include <iostream>
using namespace std;
class Bulk
{
public:
void getvalue();
void display(); //下面声明需要的成员函数(从已经提供的main函数中可以找出需要哪些成员函数)
private:
double length;
double width;
double heigth;
};
void Bulk::getvalue()//下面定义需要的成员函数
{
cout<<"清分别输入长方柱的长,宽,高:";
cout<<endl;
cin>>length>>width>>heigth;
}
void Bulk::display()
{
cout<<"这个长方柱的体积为:"<<length*width*heigth<<endl;
cout<<"这个长方柱的表面积为:"<<2*(length*width+length*heigth+width*heigth)<<endl;
}
int main()
{
Bulk b1,b2,b3;
cout<<"对于长方柱b1:"<<endl;
b1.getvalue();
b1.display();
cout<<"对于长方柱b2:"<<endl;
b2.getvalue();
b2.display();
cout<<"对于长方柱b3:"<<endl;
b3.getvalue();
b3.display();
return 0;
}
运行结果: