設(shè)計(jì)一個(gè)立方體類Box,它能計(jì)算并輸出立方體的體積和表面積
#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;
}