boxtypeimp.cpp

来自「C++编成数据结构与程序设计方法 D.S.Malk编著」· C++ 代码 · 共 53 行

CPP
53
字号
#include <iostream>
#include "rectangleType.h"
#include "boxType.h"

using namespace std;

void boxType::setDimension(double l, double w, double h)
{
    rectangleType::setDimension(l, w);

    if (h >= 0)
        height = h;
    else
        height = 0;
}

double boxType::getHeight() const
{
    return height;
}

double boxType::area() const
{
    return  2 * (getLength() * getWidth()
               + getLength() * height 
               + getWidth() * height);
}

double boxType::volume() const
{
    return rectangleType::area() * height;
}

void boxType::print() const
{
    rectangleType::print();
    cout << "; Height = " << height;
}

boxType::boxType()	
{
    height = 0.0;
}

boxType::boxType(double l, double w, double h)
         : rectangleType(l, w)
{ 
    if (h >= 0)
        height = h;
    else
        height = 0;
}

⌨️ 快捷键说明

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