1.
#include
using namespace std;
class Box
{
private:
float a;//立方体漏唤边长
float volume;//体积
float area;//表面积
public:
Box()//构造函数1
{
a=0.0;
volume=0.0;
area=0.0;
}
Box(float x):a(x){}//构造函数2
void seta()//设置立方体边长
{
cout<<"enter a :";
cin>>a;
}
float getvolume();//计算体积
float getarea();//计算表面积
void disp();//输出结果
};
float Box::getvolume ()
{
volume=a*a*a;
return volume;
}
float Box::getarea ()
{
area=6*a*a;
return area;
}
void Box::disp ()
{
cout<<"\t a="< <<"\n\tarea="<
int main()
{
Box box1,box2(1);
cout<<"box1"<
box1.disp ();
cout<<"box2(1)"<
return 0;
}
2.
#include
using namespace std;
class Rectangle//长方形类
{
private:
float length;//长
float width;//宽
public:
void getrec();//输入嫌搜锋长和宽
void putrec();//输出长方行
float area()//面积
{
return length*width;
}
};
void Rectangle::getrec ()
{
cout<<"enter length:";
cin>>length;
cout<<"\nenter width:";
cin>>width;
}
void Rectangle::putrec ()
{
cout<
}
void putvol()
{
putrec();
cout<
};
int main()
{
Rectangle rec;
rec.getrec();
rec.putrec();
Volume vol;
vol.getvol ();
vol.putvol ();
return 0;
}
3.
#include
using namespace std;
class object//基类物体object
{
private:
float weight;//重量
public:
object(float w):weight(w){}
void printweight()
{
cout<<"weight= "<
};
class box:public object
{
private:
float heigh,width;
public:
box(float we,float he,float wi):object(we),heigh(he),width(wi){}
void printall();
};
void box::printall ()
{
printweight();
cout<
int main()
{
box b(2,1.5,3);
b.printall ();
return 0;
}
这三个题目顺序是这样的吗?
如果我理灶和解成这三个题目是独立缓辩胡的,那这不难啊扰拦,如果三个题号对应三个要求,这个题目还是有一点麻烦的,不过也不难。明天没人回答,我来