第一章 立方体

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

#include
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;
}

你可能感兴趣的:(第一章 立方体)