问题及代码:
/*
*Copyright (c)2016,烟台大学计算机与控制工程学院
*All rights reserved.
*文件名称:main.cpp
*作 者:王艺霖
*完成日期:2016年3月28日
*版 本 号:v1.0
*问题描述: 求3个长方柱的体积,表面积。
*/
#include <iostream>
using namespace std;
class Bulk
{
public:
void set();
void get();
void qiu();
private:
int length;
int width;
int height;
int volume;
int areas;
};
void Bulk::set()
{
cin>>length>>width>>height;
}
void Bulk::qiu()
{
volume = length*width*height;
areas = length*width*2 + 2*width*height + length*2*height;
}
void Bulk::get()
{
cout << "体积:" << volume << endl;
cout << "表面积:" << areas << endl;
}
int main()
{
Bulk B1,B2,B3;
B1.set();
B2.set();
B3.set();
B1.qiu();
B2.qiu();
B3.qiu();
B1.get();
B2.get();
B3.get();
return 0;
}
运行结果: