#include<iostream>
using namespace std;
class Bulk
{
public:
Bulk(int a=0,int b=0,int c=0):lengh(a),width(b),height(c) {}
double get_volume();
double get_area();
void set_value();//此处声明需要的成员函数
private:
double lengh;
double width;
double height;
};
void Bulk::set_value()
{
int l,w,h;
cin>>l>>w>>h;
lengh=l;
width=w;
height=h;
}
double Bulk::get_volume()
{
return lengh*width*height;
}
double Bulk::get_area()
{
return 2*(lengh*width+lengh*height+width*height);
}
//下面定义成员函数
//用main()函数测试,完成输入输出
int main()
{
Bulk b1;
b1.set_value();
cout<<b1.get_volume()<<endl;
cout<<b1.get_area()<<endl;
return 0;
}
运算结果:
知识点总结:
类的使用,在类内声明成员函数。