box.cpp
来自「这是一个Box的源码。Function to calculate the vol」· C++ 代码 · 共 26 行
CPP
26 行
// Box.cpp Box class member function definitions
#include <iostream>
#include "Box.h"
using std::cout;
using std::endl;
// 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() {
return length * width * height;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?