预览加载中,请您耐心等待几秒...
1/10
2/10
3/10
4/10
5/10
6/10
7/10
8/10
9/10
10/10

亲,该文档总共12页,到这已经超出免费预览范围,如果喜欢就直接下载吧~

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

#include<iostream> #include<fstream> #include<string> #include<stdlib.h> usingnamespacestd; intN=5;/*设置全局变量N=5,信息库最多存储5辆车辆信息*/ intn1=0;/*全局变量,记录大客车文件当前信息库信息数量*/ intn2=0;/*全局变量,记录小轿车文件当前信息库信息数量*/ intn3=0;/*全局变量,记录卡车文件当前信息库信息数量*/ ofstreamos1("file1.dat",ios::binary|ios::trunc);/*建立file1文件*/ ofstreamos2("file2.dat",ios::binary|ios::trunc);/*建立file2文件*/ ofstreamos3("file3.dat",ios::binary|ios::trunc);/*建立file3文件*/ classcar{/*汽车类*/ public: stringnumber; stringlicense_plat;/*车牌号码*/ stringcompany; voidgetcar(); voidshow(){ cout<<number<<"\t"<<license_plat<<"\t"<<company<<"\t";}/*输出所有数据*/ ~car(){} }; /*****************************/ classtruck:publiccar{/*卡车类*/ public: voidshow(){ car::show(); cout<<""<<endl;}/*输出所有数据*/ ~truck(){} }; /*****************************/ classsedan:publiccar{/*小轿车类*/ public: voidshow(){ car::show(); cout<<""<<endl;}/*输出所有数据*/ ~sedan(){} }; /*****************************/ classcoach:publiccar{/*客车类*/ public: voidshow(){ car::show(); cout<<""<<endl;}/*输出所有数据*/ ~coach(){} }; /*****************************/ voidcar::getcar(){/*getcar()函数实现*/ cout<<"车牌号:";cin>>license_plat; cout<<"车辆制造公司:";cin>>company; cout<<"车辆型号(1大客车2小轿车3卡车):";cin>>mode; } /*****************************/ coach*getcoach(){/*设置函数获取客车库中信息存储于数组中,方便之后提取*/ inti; coach*head=newcoach[n1]; ifstreamis1("file1.dat",ios::in|ios::binary); for(i=0;i<n1;i++){ is1>>head[i].number>>head[i].license_plat>>head[i].company>>head[i].apacity; } is1.close(); returnhead; } /*****************************/ sedan*getsedan(){/*设置函数获取小轿车库中信息存储于数组中,方便之后提取*/ inti; sedan*head=newsedan[n2]; ifstreamis2("file2.dat",ios::in|ios::binary); for(i=0;i<n2;i++){ is2>>head[i].number>>head[i].license_plat>>head[i].company>>head[i].CTNS; } is2.close(); returnhead; } /*****************************/ truck*gettruck(){/*设置函数获取卡车库中信息存储于数组中,方便之后提取*/ inti; truck*head=newtruck[n3]; ifstreamis3("file3.dat",ios::in|ios::binary); for(i=0;i<n3;i++) { is3>>head[i].number>>head[i].license_plat>>head[i].com