第一章 立方体

2019-06-24  本文已影响0人  这么帅的人啊

设计一个立方体类Box,它能计算并输出立方体的体积和表面积

#include<iostream>
using namespace std;
class CBox
{
public:
    CBox(double l = 0, double w = 0, double h = 0);
    double area();
    double volume();
private:
    double length;
    double width;
    double high;
};
CBox::CBox(double l, double w, double h)
{
    length = l;
    width = w;
    high = h;
}
double CBox::area()
{
    return 2 * (length + width + high);
}
double CBox::volume()
{
    return length * width * high;
}
int main()
{
    CBox box1(4, 5, 6);
    cout << box1.area() << endl;
    cout << box1.volume() << endl;
}
上一篇 下一篇

猜你喜欢

热点阅读