box.cpp
来自「一本语言类编程书籍」· C++ 代码 · 共 32 行
CPP
32 行
// Box.cpp
#include <iostream>
#include "Box.h"
using std::cout;
using std::endl;
// Constructor
Box::Box(double lv, double wv, double hv) :
length(lv), width(wv), height(hv){}
// Destructor
Box::~Box() {}
// Function to show the volume of an object
void Box::showVolume() const {
cout << endl << "Box usable volume is " << volume();
}
// Function to calculate the volume of a Box object
double Box::volume() const {
return length * width * height;
}
// Friend operator function for Box
std::ostream& operator<<(std::ostream& out, const Box& rBox) {
return out << ' ' << rBox.length << ' ' << rBox.width << ' ' << rBox.height;
}
std::istream& operator>>(std::istream& in, Box& rBox) {
return in >> rBox.length >> rBox.width >> rBox.height;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?