悬赏就!!!!关于C++的问题,回答正确在加分

来源:百度知道 编辑:UC知道 时间:2024/06/04 19:35:09
二、汽车管理模拟程序 (
【要求】按以下描述和要求建立两个类moto和All :
class moto{ //汽车类
friend class ALL;
private:
int ; //汽车代号
char ; //汽车类型('A'-货车,'B'-客车)
int ; //空闲/使用(0/1)
float ; //载重量/载客人数
public:
moto(){ id=0; type=NULL; flag=0; weight=0;}
void set(int a, char b) //输入一辆汽车数据
{ id=a; type=b;}
void disp() //输出一辆汽车数据
{ cout<<id<<','<<type<<','<<weight<<endl;}
};
class ALL{ //汽车管理类
private:
moto car[12]; //最多管理12辆汽车
int num; //实际存储的汽车数量
public:
ALL(){num=0;} //构造函数
void AddCar(); //添加一辆新汽车,要求输入代号和类型
void list(); //分别打印客车清单和货车清单
void load(char t,float w); //派出车辆,输入车型和上货重量(或上客人数),
//选择一辆空车修改其数据,输出派出车号
};
请完成以上All类中未定义函数体的成员函数,并调试运行。All类的成员函数AddCar()和list()可以调用moto类的相应成员函数实现其功能。
测试用主函

#include"iostream.h"
class moto{
friend class ALL;
private:
int id;
char type;
int flag;
float weight;
public:
moto(){ id=0; type=NULL; flag=0; weight=0;}
void set(int a, char b)
{ id=a; type=b;}
void disp()
{ cout<<id<<','<<type<<','<<weight<<endl;}
};
class ALL{
private:
moto car[12];
int num;
public:
ALL(){num=0;}
void AddCar();
void list();
void load(char t,float w);
};
void ALL::AddCar()
{
int a;
char b;
cout<<"添加一辆车"<<endl;
cout<<"输入id,type"<<endl;
cin>>a>>b;
car[num].set(a,b);
num++;
}
void ALL::list()
{
int i=0;
cout<<"车辆清单"<<endl;
for(i=0;i&l