📄 box.cpp
字号:
// Box.cpp Box class member function definitions
#include <iostream>
#include "Box.h"
using std::cout;
using std::endl;
// Default constructor
Box::Box() {
cout << "Default constructor called" << endl;
length = width = height = 1.0;
}
// Constructor
Box::Box(double lvalue, double wvalue, double hvalue) :
length(lvalue), width(wvalue), height(hvalue) {
cout << "Box constructor called" << endl;
// Ensure positive dimensions
if(length <= 0.0)
length = 1.0;
if(width <= 0.0)
width = 1.0;
if(height <= 0.0)
height = 1.0;
}
// Function to calculate the volume of a box
double Box::volume() const {
return length * width * 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,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -