当前位置: 首页 > 工具软件 > boxbox > 使用案例 >

BOX类

孙莫希
2023-12-01

设计一个立方体类BOX,它能计算并输出立方体的体积和表面积。
提示:定义一个BOX类,含有一个私有数据成员(立方体边长length),有两个公有数据函数(构造
函数Box和计算输出函数show)

#pragma once
#include <iostream>
#include <string>
class BOX
{
public:
    BOX(double width, double length, double height);
    void show();     //打印
    double Super();  //表面积
    double Bulk();  //体积

private:
    double  length_;
    double  width_;
    double  height_;
};
#include "student.h"

BOX::BOX(double width, double length, double height)
    :width_(width),length_(length),height_(height) {}

double  BOX::Super()
{
    return this->length_* this->width_* this->height_;
}
double BOX::Bulk()
{
    return this->length_* this->width_ * 2 +
        this->length_* this->height_ * 2 +
        this->width_* this->height_ * 2;
}
void  BOX::show()
{
    std::cout << "length:" << this->length_ << std::endl;
    std::cout << "width:" << this->width_ << std::endl;
    std::cout << "height:" << this->height_ << std::endl;
    std::cout << "super:" << this->Super() << std::endl;
    std::cout << "Area:" << this->Bulk() << std::endl;
}
#include "student.h"

void main()
{
    BOX a(2,3,4);
    a.show();
    system("pause");
}
 类似资料: