1、车辆管理系统主要负责各种车辆的常规信息管理工作车辆管理系统主要负责各种车辆的常规信息管理工作。 系统中的车辆主要有大客车、小轿车和卡车。每种车辆有车辆编号、车牌号、 车辆制造公司、车辆购买时间、车辆型号(大客车、小轿车和卡车)等信息。大客车还有载客量 (最大载客数)信息,小轿车还有箱数(两厢或三厢)信息,卡车还有载重量等信息。 功能要求: (1)添加车辆:主要完成车辆信息的添加,要求编号唯一. (2)查询车辆: (3)显示车辆信息库:输出当前车辆信息库中所有车辆信息,每条记录占据一行。 (4)统计信息 输出当前车辆信息库中总物品数,以及按车辆类别,统计出当前车辆信息库中各类别的物品数并显示。
2、(5)车辆信息存盘:将当前程序中的车辆信息存入文件中。 (6)读出车辆信息:从文件中将车辆信息读入程序。 主要程序: #include #include #include #include using namespace std; int N=50; /*设置全局变量N=50,信息库最多存储50辆车辆信息*/ int n1=0; /*全局变量,记录大客车文件当前信息库信息数量*/ int n2=0; /*全局变量,记录小轿车文件当前信息库信息数量*/ int n3=0; /*全局变量,记录卡车文件当前信息库信息数量*/ ofstream os1(file1.dat,ios:binary|ios
3、:trunc); ofstream os2(file2.dat,ios:binary|ios:trunc); ofstream os3(file3.dat,ios:binary|ios:trunc); /*/ class car /*汽车类*/ public: string license_plat; string company; double time_buying; string mode; void getcar(); void show() coutlicense_plat tcompany t time_buying t mode t ; car() ; /*/ class tru
4、ck:public car /*卡车类,公有继承汽车类*/ public: double load_weight; /*卡车附加属性载重量*/ void show() car:show(); cout load_weightendl; truck() ; /*/ class sedan:public car public: int CTNS; /*小轿车附加属性箱数*/ void show() car:show(); cout CTNSendl; sedan() ; /*/ class coach:public car public: int apacity ; /*大客车附加属性载客量*/
5、void show() car:show(); cout apacityendl; coach() ; /*/ void car:getcar() /*getcar()函数实现*/ coutlicense_plat; coutcompany; couttime_buying; coutmode; /*/ coach* getcoach() /*设置函数获取客车库中信息存储于数组中,方便之后提取*/ int i; coach *head=new coachn1; ifstream os1(file1.dat,ios:in|ios:binary); for(i=0;iheadi.license_p
6、anyheadi.time_buying headi.modeheadi.apacity; os1.close(); return head; /*/ sedan* getsedan() /*设置函数获取小轿车库中信息存储于数组中,方便之后提取*/ int i; sedan* head=new sedann2; ifstream os2(file2.dat,ios:in|ios:binary); for(i=0;iheadi.license_panyheadi.time_buying headi.modeheadi.CTNS; os2.close(); return head; /*/ tru
7、ck* gettruck() /*设置函数获取客车库中信息存储于数组中,方便之后提取*/ int i; truck* head=new truckn3; ifstream os3(file3.dat,ios:in|ios:binary); for(i=0;iheadi.license_panyheadi.time_buying headi.modeheadi.load_weight; os3.close(); return head; /*/ int add() /*添加函数*/ int i,j,k=0,x; coach c; sedan s; truck t; coutx; for(i=0;
8、ix;i+) int flag=0; cout请选择添加车辆的类别(退出输入0): endl; cout*endl; cout* 1 大客车 2 小轿车 3 卡车*endl; cout*j; if(flag=0) if(j=1) n1+; c.getcar(); coutc.apacity; ofstream os1(file1.dat,ios:binary|ios_base:app); os1c.license_plat pany c.time_buying c.mode c.apacity ; cout添加成功! endl; os1.close(); if(j=2) n2+; s.getc
9、ar(); couts.CTNS; ofstream os2(file2.dat,ios:binary|ios_base:app); os2s.license_plat pany s.time_buying s.mode s.CTNS ; cout添加成功! endl; os2.close(); if(j=3) n3+; t.getcar(); coutt.load_weight; ofstream os3(file3.dat,ios:binary|ios_base:app); os3t.license_plat pany t.time_buying t.mode t.load_weight
10、; cout添加成功!endl; os3.close(); return 0; /*/ void query() /*查询函数*/ int x,flag=0; string str; cout请输入查询方式(退出输入0):endl; cout*endl; cout* 1 车牌号查询2公司查询*endl; cout*x; /*按公司查询或按编号查询*/ if(x=1)|(x=2) int i; if(x=2) cout请输入公司: ; else coutstr; coach* c=getcoach(); for(i=0;in1;i+) if(ci.license_plat=str) cout车牌
11、号制造公司购买时间型号特有属性endl; ci.show();flag=1;break; if(pany=str) cout车牌号制造公司购买时间型号特有属性endl; ci.show(); if(flag=0) sedan* s=getsedan(); for(i=0;in2;i+) if(si.license_plat=str) cout车牌号制造公司购买时间型号特有属性endl; si.show(); flag=1; break; if(pany=str) cout车牌号制造公司购买时间型号特有属性endl; si.show(); if(flag=0) truck* t=gettruck
12、(); for(i=0;in3;i+) if(ti.license_plat=str) cout车牌号制造公司购买时间型号特有属性endl; ti.show(); flag=1; break; if(pany=str) cout车牌号制造公司购买时间型号特有属性endl; ti.show(); if(flag=0) cout未找到信息,输入错误!endl;/*未找到符合的数据输出错误*/ /*/ void show() /*显示函数*/ int i=0; cout*endl; cout车牌号制造公司购买时间型号特有属性endl; cout*endl; coach* c=getcoach();
13、for(i=0;in1;i+) ci.show(); sedan* s=getsedan(); for(i=0;in2;i+) si.show(); truck* t=gettruck(); for(i=0;in3;i+) ti.show(); /*/ void collect() /*统计函数*/ cout当前车辆信息库中共有n1+n2+n3条车辆信息.endl; cout其中:n1条大客车信息,endl n2 条小轿车信息endl n3条卡车信息.endl; /*/ int main() int a; cout*endl; coutt;cout* 欢迎进入车辆管理系统*endl; cout
14、t;cout*endl; coutt;cout* 车辆管理系统: *endl; coutt;cout* 1 添加*endl; coutt;cout* 2 查询*endl; coutt;cout* 3 显示*endl; coutt;cout* 4 统计*endl; coutt;cout* 5 退出*endl; coutt;cout* 请选择: *endl; cout*a;/*输入选项*/ do switch(a) case 1:add();break; case 2:query();break; case 3:show();break; case 4:collect();break; case 5:coutnnttt欢迎再次使用汽车库管理系统nn;exit(1); default:coutERROR:输入选项错误!endl; /*完成操作后给用户再次提供选项界面*/ cout*endl; cout* 车辆管理系统: *endl; cout* 1 添加*endl; cout* 2 查询*endl; cout* 3 显示*endl; cout* 4 统计*endl; cout* 5 退出*endl; cout* 请选择: *endl; cout*a; while(1); return 0;
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1