⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 box.cpp

📁 一本语言类编程书籍
💻 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 + -