📄 box.cpp
字号:
// Box.cpp Implementation of the Box class
#include "Box.h"
// Constructor
Box::Box(double aLength, double aWidth, double aHeight) {
length = aLength > 0.0 ? aLength : 1.0;
width = aWidth > 0.0 ? aWidth : 1.0;
height = aHeight > 0.0 ? aHeight : 1.0;
}
// Calculate Box volume
double Box::volume() const{ return length*width*height; }
// getXXX() functions
double Box::getLength() const { return length; }
double Box::getWidth() const { return width; }
double Box::getHeight() const { return height; }
// Function to compare two Box objects
// If the current Box is greater than the argument, 1 is returned
// If they are equal, 0 is returned
// If the current Box is less than the argument -1 is returned
int Box::compareVolume(const Box& otherBox) const {
double vol1 = volume(); // Get current Box volume
double vol2 = otherBox.volume(); // Get argument volume
return vol1>vol2 ? 1 : (vol1<vol2 ? -1 : 0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -