carton.cpp

来自「一本语言类编程书籍」· C++ 代码 · 共 27 行

CPP
27
字号
// Carton.cpp
#include "Carton.h"
#include <cstring>
#include <iostream>
using std::cout;
using std::endl;

// Constructor
Carton::Carton(double lv, double wv, double hv,     
               const char* pStr, double dense, double thick):
                      Box(lv, wv, hv), density(dense), thickness(thick) {
  pMaterial = new char[strlen(pStr)+1];     // Allocate space for the string
  strcpy( pMaterial, pStr);                 // Copy it
  cout << "Carton constructor" << endl;
}

// Destructor
Carton::~Carton() {
  cout << "Carton destructor" << endl;
  delete[] pMaterial;
}

// "Get carton weight" function
double Carton::getWeight() const { 
  return 2*(length*width + width*height + height*length)*thickness*density;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?