|
|
发表于 2019-7-3 19:00:44
|
显示全部楼层
- #include <iostream>
- class Box
- {
- public:
- Box(float p, float q, float r): a(p), b(q), c(r), volume(0), area(0) {}
- void getvolume() {this->volume = this->a * this->b * this->c;}
- void getarea() {this->area = 2 * (this->a * this->b + this->b * this->c + this->c * this->a);}
- void disp() {std::cout << "volume: " << this->volume << ", area: " << area << std::endl;}
- private:
- float a, b, c;
- float volume, area;
- };
- int main()
- {
- Box box(4, 5, 6);
- box.getvolume();
- box.getarea();
- box.disp();
- return 0;
- }
复制代码 |
|