#include <iostream>
using namespace std;
class Cube
{
private:
double length,width,heigh,volume,areas;
public:
void set_data(double,double,double);
void get_volume();
void get_areas();
void display();
};
int main()
{
Cube c;
double l,w,h;
for(int i=0;i<3;i++)
{
cin>>l>>w>>h;
c.set_data(l,w,h);
c.get_volume();
c.get_areas();
c.display();
}
return 0;
}
void Cube::set_data(double l,double w,double h)
{
length=l;
width=w;
heigh=h;
}
void Cube::get_volume()
{
volume=length*width*heigh;
}
void Cube::get_areas()
{
areas=2*(length*width+width*heigh+heigh*length);
}
void Cube::display()
{
cout<<"此长方形体积为:"<<volume<<endl;
cout<<"此长方形表面积为:"<<areas;
}
我就是懒了点做了个正方体的,不过应该都没问题,如有问题,请赐教。