车辆管理系统主要负责各种车辆的常规信息管理工作.docx
《车辆管理系统主要负责各种车辆的常规信息管理工作.docx》由会员分享,可在线阅读,更多相关《车辆管理系统主要负责各种车辆的常规信息管理工作.docx(13页珍藏版)》请在冰豆网上搜索。
![车辆管理系统主要负责各种车辆的常规信息管理工作.docx](https://file1.bdocx.com/fileroot1/2023-2/3/7a9ded93-1c42-40bf-90b9-6bfe1ddfc9ec/7a9ded93-1c42-40bf-90b9-6bfe1ddfc9ec1.gif)
车辆管理系统主要负责各种车辆的常规信息管理工作
车辆管理系统主要负责各种车辆的常规信息管理工作。
系统中的车辆主要有大客车、小轿车和卡车。
每种车辆有车辆编号、车牌号、
车辆制造公司、车辆购买时间、车辆型号(大客车、小轿车和卡车)等信息。
大客车还有载客量
(最大载客数)信息,小轿车还有箱数(两厢或三厢)信息,卡车还有载重量等信息。
功能要求:
(1)添加车辆:
主要完成车辆信息的添加,要求编号唯一.
(2)查询车辆:
(3)显示车辆信息库:
输出当前车辆信息库中所有车辆信息,每条记录占据一行。
(4)统计信息
输出当前车辆信息库中总物品数,以及按车辆类别,统计出当前车辆信息库中各类别的物品数并显示。
(5)车辆信息存盘:
将当前程序中的车辆信息存入文件中。
(6)读出车辆信息:
从文件中将车辆信息读入程序。
主要程序:
#include
#include
#include
#include
usingnamespacestd;
intN=50;/*设置全局变量N=50,信息库最多存储50辆车辆信息*/intn1=0;/*全局变量,记录大客车文件当前信息库信息数量*/
intn2=0;/*全局变量,记录小轿车文件当前信息库信息数量*/
intn3=0;/*全局变量,记录卡车文件当前信息库信息数量*/ofstreamos1("file1.dat",ios:
:
binary|ios:
:
trunc);
ofstreamos2("file2.dat",ios:
:
binary|ios:
:
trunc);
ofstreamos3("file3.dat",ios:
:
binary|ios:
:
trunc);
/**********************************************************************/classcar
{/*汽车类*/
public:
stringlicense_plat;
stringcompany;
doubletime_buying;
stringmode;
voidgetcar();
voidshow(){
cout<<~car(){}
};
/******************************************************************/
classtruck:
publiccar/*卡车类,公有继承汽车类*/
{
public:
doubleload_weight;/*卡车附加属性载重量*/
voidshow()
{
car:
:
show();
cout<<""<}
~truck(){}
};
/******************************************************************/
classsedan:
publiccar
{
public:
intCTNS;/*小轿车附加属性箱数*/
voidshow()
{
car:
:
show();
cout<<""<}
~sedan(){}
};
/*****************************************************************/
classcoach:
publiccar
{
public:
intapacity;/*大客车附加属性载客量*/
voidshow()
{
car:
:
show();
cout<<""<}
~coach(){}
};
/****************************************************************/
voidcar:
:
getcar()/*getcar()函数实现*/
{
cout<<"车牌号:
";cin>>license_plat;
cout<<"车辆制造公司:
";cin>>company;
cout<<"车辆购买时间(月):
";cin>>time_buying;
cout<<"车辆型号(1大客车2小轿车3卡车):
";cin>>mode;
}
/******************************************************************/
coach*getcoach()/*设置函数获取客车库中信息存储于数组中,方便之后提取*/{
inti;
coach*head=newcoach[n1];
ifstreamos1("file1.dat",ios:
:
in|ios:
:
binary);
for(i=0;i{
os1>>head[i].license_plat>>head[i].company>>head[i].time_buying
>>head[i].mode>>head[i].apacity;
}
os1.close();
returnhead;
}
/**********************************************************************/
sedan*getsedan()/*设置函数获取小轿车库中信息存储于数组中,方便之后提取*/
{
inti;
sedan*head=newsedan[n2];
ifstreamos2("file2.dat",ios:
:
in|ios:
:
binary);
for(i=0;i{
os2>>head[i].license_plat>>head[i].company>>head[i].time_buying
>>head[i].mode>>head[i].CTNS;
}
os2.close();
returnhead;
}
/************************************************************************/
truck*gettruck()/*设置函数获取客车库中信息存储于数组中,方便之后提取*/{
inti;
truck*head=newtruck[n3];
ifstreamos3("file3.dat",ios:
:
in|ios:
:
binary);
for(i=0;i{
os3>>head[i].license_plat>>head[i].company>>head[i].time_buying
>>head[i].mode>>head[i].load_weight;
}
os3.close();
returnhead;
}
/**************************************************************************/
intadd()/*添加函数*/
{
inti,j,k=0,x;
coachc;
sedans;
truckt;
cout<<"请输入添加数量:
";
cin>>x;
for(i=0;i{
intflag=0;
cout<<"请选择添加车辆的类别(退出输入0):
"<cout<<"*************************************************"<cout<<"*1大客车2小轿车3卡车*"<cout<<"*************************************************"<cin>>j;
if(flag==0)
{
if(j==1)
{
n1++;
c.getcar();
cout<<"请输入载客量:
";cin>>c.apacity;
ofstreamos1("file1.dat",ios:
:
binary|ios_base:
:
app);
os1<<cout<<"添加成功!
"<os1.close();
}
if(j==2)
{
n2++;
s.getcar();
cout<<"请输入箱数:
";cin>>s.CTNS;
ofstreamos2("file2.dat",ios:
:
binary|ios_base:
:
app);
os2<<cout<<"添加成功!
"<os2.close();
}
if(j==3)
{
n3++;
t.getcar();
cout<<"请输入载重量):
";cin>>t.load_weight;
ofstreamos3("file3.dat",ios:
:
binary|ios_base:
:
app);
os3<<cout<<"添加成功!
"<os3.close();
}
}
}
return0;
}
/******************************************************************/
voidquery()/*查询函数*/
{intx,flag=0;
stringstr;
cout<<"请输入查询方式(退出输入0):
"<cout<<"****************************************"<cout<<"*1车牌号查询2公司查询*"<cout<<"****************************************"<cin>>x;
/*按公司查询或按编号查询*/
if((x==1)||(x==2))
{
inti;
if(x==2)cout<<"请输入公司:
";
elsecout<<"请输入车牌号:
";
cin>>str;
coach*c=getcoach();
for(i=0;i{
if(c[i].license_plat==str)
{cout<<"车牌号制造公司购买时间型号特有属性"<c[i].show();flag=1;break;
}
if(c[i].company==str)cout<<"车牌号制造公司购买时间型号特有属性"<c[i].show();
}
if(flag==0)
{
sedan*s=getsedan();
for(i=0;i{
if(s[i].license_plat==str)
{
cout<<"车牌号制造公司购买时间型号特有属性"<s[i].show();
flag=1;
break;
}
if(s[i].company==str)cout<<"车牌号制造公司购买时间型号特有属性"<s[i].show();
}
}
if(flag==0)
{
truck*t=gettruck();
for(i=0;i{
if(t[i].license_plat==str)
{
cout<<"车牌号制造公司购买时间型号特有属性"<t[i].show();
flag=1;
break;
}
if(t[i].company==str)cout<<"车牌号制造公司购买时间型号特有属性"<t[i].show();
}
}
if(flag==0)
cout<<"未找到信息,输入错误!
"<}
/*******************************************************************/
voidshow()/*显示函数*/
{
inti=0;
cout<<"***************************************************"<cout<<"车牌号制造公司购买时间型号特有属性"<cout<<"***************************************************"<coach*c=getcoach();
for(i=0;ic[i].show();
sedan*s=getsedan();
for(i=0;is[i].show();
truck*t=gettruck();
for(i=0;it[i].show();
}
/********************************************************************/
voidcollect()/*统计函数*/
{
cout<<"当前车辆信息库中共有"<cout<<"其中:
"<<<"条小轿车信息"<}
/********************************************************************/
intmain()
{
inta;
cout<<"***********************************************************"<cout<<"\t";cout<<"**欢迎进入车辆管理系统**"<cout<<"\t";cout<<"***********************************************"<cout<<"\t";cout<<"*车辆管理系统:
*"<cout<<"\t";cout<<"*1添加*"<cout<<"\t";cout<<"*2查询*"<cout<<"\t";cout<<"*3显示*"<cout<<"\t";cout<<"*4统计*"<cout<<"\t";cout<<"*5退出*"<cout<<"\t";cout<<"*请选择:
*"<cout<<"***********************************************************"<cin>>a;/*输入选项*/
do{
switch(a){
case1:
add();break;
case2:
query();break;
case3:
show();break;
case4:
collect();break;
case5:
cout<<"\n\n\t\t\t欢迎再次使用汽车库管理系统\n\n";exit
(1);
default:
cout<<"ERROR:
输入选项错误!
"<}
/*完成操作后给用户再次提供选项界面*/
cout<<"***********************************************"<cout<<"*车辆管理系统:
*"<cout<<"*1添加*"<cout<<"*2查询*"<cout<<"*3显示*"<cout<<"*4统计*"<cout<<"*5退出*"<cout<<"*请选择:
*"<cout<<"***********************************************"<cin>>a;
}while
(1);
return0;
}