当前位置:首页 > 问答大全 > 高分求3道C++机试题的详细代码!

高分求3道C++机试题的详细代码!

被浏览: 0次 2023年06月23日 18:11
热门回答(2个)
游客1

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.seta ();
box1.disp ();
cout<<"box2(1)"< box2.disp ();

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< cin>>high;
}

void putvol()
{
putrec();
cout<

游客2

这三个题目顺序是这样的吗?
如果我理灶和解成这三个题目是独立缓辩胡的,那这不难啊扰拦,如果三个题号对应三个要求,这个题目还是有一点麻烦的,不过也不难。明天没人回答,我来