c++课程设计——班车管理系统

来源:互联网 发布:淘宝助理连打走位 编辑:程序博客网 时间:2024/04/29 12:16

课程设计要求:

一交通公司,班车系统的数据包括如下两部分:

①班车信息:班交及车号、最大载客数、起点、开车时间、终地点、到达终点站时间,单价;

② 乘客信息:车次及车号、身份证号码、姓名、性别、出生年月、座位号。

乘客订票的主要方式是:乘客提供起点、时间、终点、订票数等订票要求,根据事先保存的班数据决定乘客能否订票?只有全部满足了乘客的订票要求并且所订班次有足够的未订座位之后才能完成订票处理,并且修改该班次的未订座位数(每个班的未订座位数的初始值就是该班次的最大载客数);否则,订票失败,并且给出不能订票的原因。

功能要求 :

⑴ 增加班次记录。

⑵ 班次取消。

⑶ 班次查询。

⑷ 班次订票。

⑸ 设计一个菜单,至少具有上述操作要求的基本功能。

程序:

</pre></p><pre name="code" class="cpp">// kcsjbcxxcx.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include<iostream>//#include<dos.h>//#include<time.h>using namespace std;int n=0,m=0;struct date{int year;int month;int day;};struct time{int shi;int fen;int miao;};struct guanli{char zh[15];char mima[20];}guan1={"zd1123xufei","201211632326"},guan2={"minggezhijia","zd2012cjjxx"};enum beiz{售票中,可发车,班次取消};enum qid{湛江};enum zhongd{广州,深圳,东莞,佛山,揭阳,中山,茂名,汕头};struct banche{int bianhao;//编号enum qid qidian;//出发地enum zhongd zhongdian;//终点站int zuoweishu;//最大载客量int shengyup;//剩余可载客数struct time fache;//发车时间enum beiz beizhu;//备注信息:是否可购票和发车banche *next;};struct dingpiaoxx{char xingming[30];char zheng[19];enum zhongd gpzd;struct time shijian;struct date riqi;int piaoshu;dingpiaoxx *NEXT;};banche *creat();banche *insert(banche *head,banche *banc);banche *charu(banche *hea);void xiug(banche *hed);banche *del(banche *head);void chache(banche *head);dingpiaoxx *CREAT();dingpiaoxx *dingpiao(dingpiaoxx *HEAD);void gaip(dingpiaoxx *HEAD);void xiup(dingpiaoxx *HED );void chapiao(dingpiaoxx *HEAD );dingpiaoxx  *tianjia(dingpiaoxx *HEAD);dingpiaoxx *shanc(dingpiaoxx *HEAD );void welc();//void chushi();void xuanze();void weihu();void kehu();int denglu();/*********************下面是主函数******************/int main(){char key='y';welc();//chushi();while(key!='n'&&key!='N'){xuanze();int a,b;cin>>a;if(a==1){b=denglu();if(b==1){int gg=1;while(gg=1){weihu();cout<<"是否继续?1:是 , 2:否 "<<endl;cin>>gg;}}}else if(a==2){{int gg=1;while(gg=1){kehu();cout<<"是否继续?1:是 , 2:否 "<<endl;cin>>gg;}}}elsecout<<"输入错误,请按提示信息输入!"<<endl;cout<<"感谢你使用本系统"<<endl<<"按“Y”返回身份选择界面"<<endl<<"按“N”退出本系统"<<endl;cin>>key;}return 0;}/********************************以下是实现各种功能的函数******************/banche *head=creat();banche *creat()//建立班次信息表{int a,b=1;char key;banche *head,*p1,*p2;head=NULL;p1=new(banche);p2=p1;cout<<"请输入班车编号"<<endl;cin>>p1->bianhao;p1->qidian=qid(0);cout<<"请输入班车到达的终点站对应的序号"<<endl<<"0 广州;1 深圳;2 东莞;3 佛山;4 揭阳;5 中山;6 茂名;7 汕头"<<endl;cin>>a;p1->zhongdian=zhongd(a);cout<<"请输入该班次最大乘客数"<<endl;cin>>p1->zuoweishu;p1->shengyup = p1->zuoweishu;cout<<"请输入班车出发时间(时、分)"<<endl;cin>>p1->fache.shi >>p1->fache.fen ;p1->beizhu =beiz(0);while(b==1){n++;if(n==1)head=p1;else{p2->next=p1;p2=p1;}p1=new(banche);cout<<"请输入班车编号"<<endl;cin>>p1->bianhao;p1->qidian=qid(0);cout<<"请输入班车到达的终点站对应的序号"<<endl<<"0 广州;1 深圳;2 东莞;3 佛山;4 揭阳;5 中山;6 茂名;7 汕头"<<endl;cin>>a;p1->zhongdian=zhongd(a);cout<<"请输入该班次最大乘客数"<<endl;cin>>p1->zuoweishu;p1->shengyup = p1->zuoweishu;p1->beizhu =beiz(0);cout<<"请输入班车出发时间(时、分)"<<endl;cin>>p1->fache.shi >>p1->fache.fen ;cout<<"是否继续,按任意键继续,按N结束"<<endl;cin>>key;if( key =='n'||key=='N')b=0;elseb=1;}return head;}banche *insert(banche *head,banche *banc){banche *p0,*p1;p1=head;p0=banc;if(head==NULL){head=p0;p0->next=NULL;}else{head=p0;p0->next=p1;}n++;return head;}banche *charu(banche *hea)//添加班次记录{int a,b=1;char key;while(b){banche *banc=new banche;cout<<"请输入班车到达的终点站对应的序号"<<endl<<"0 广州;1 深圳;2 东莞;3 佛山;4 揭阳;5 中山;6 茂名;7 汕头"<<endl;cin>>a;banc->zhongdian=zhongd(a);cout<<"请输入该班次最大乘客数"<<endl;cin>>banc->zuoweishu;banc->shengyup = banc->zuoweishu;banc->beizhu =beiz(0);cout<<"请输入班车出发时间(时、分)"<<endl;cin>>banc->fache.shi >>banc->fache.fen ;head=insert(hea,banc);cout<<"按任意键继续,按“N”结束添加"<<endl;cin>>key;if(key=='n'||key=='N')b=0;}return head;}void xiug(banche *hed){banche *p1,*p2,xiu;int a,b,c=1;cout<<"请输入要修改的班次编号"<<endl;cin>>xiu.bianhao ;p1=hed;while(p1!=NULL||p1->bianhao !=xiu.bianhao){p2=p1;p1=p1->next ;}if(p1==NULL)cout<<"没有这个班次"<<endl;else{while(c==1){cout<<"请输入要修改的部分对应编号"<<endl<<"1.编号\t"<<"2.出发地\t"<<"3.终点站\t"<<"4.最大载客量\t"<<endl<<"5.剩余可载客数\t"<<"6.发车时间\t"<<"7.备注信息\t"<<"\t"<<endl;cin>>a;switch (a){case 1:cout<<"请输入新编号"<<endl;cin>>p1->bianhao ;break;case 2:cout<<"不可更改信息"<<endl;break;case 3:cout<<"请输入新地名对应标号"<<endl<<"0 广州;1 深圳;2 东莞;3 佛山;4 揭阳;5 中山;6 茂名;7 汕头"<<endl;cin>>b ;p1->zhongdian=zhongd(b);break;case 4:cout<<"请输入新班次最大载客量"<<endl;cin>>p1->zuoweishu  ;break;case 5:cout<<"请输入新数字"<<endl;cin>>p1->shengyup  ;break;case 6:cout<<"请输入新时间"<<endl;cin>>p1->fache.shi >>p1->fache.fen ;break;case 7:cout<<"请输入新信息:0.售票中,1.可发车,2.班次取消"<<endl;cin>>b ;p1->beizhu =beiz(b);break;default :cout<<"输入错误!!"<<endl;} cout<<"是否更改其他信息?Y OR N"<<endl;char key;cin>>key;if(key=='n'||key=='N')c=0;}cout<<"修改成功!!"<<endl;}}banche *del(banche *head)//删除班车记录{banche *p1,*p2;int a;char key;if (head=NULL){cout<<"没有数据"<<endl;return head;}p1=head;p2=p1;cout<<"请输入班车编号"<<endl;cin>>a;while(a!=p1->bianhao &&p1->next !=NULL){p2=p1;p1=p1->next;}if(a==p1->bianhao ){cout<<"编号\t"<<"起点\t"<<"终点\t"<<"座位数\t"<<"发车时间\t"<<endl<<p1->bianhao <<'\t'<<p1->qidian <<'\t'<<p1->zhongdian <<'\t'<<p1->zuoweishu <<'\t'<<" 点"<<" 分"<<'\t'<<endl;cout<<"确定要删除本条记录吗?Y(是),N(否)"<<endl;cin>>key;if(key=='Y'||key=='y'){if(p1==head)head=p1->next;elsep2->next=p1->next ;cout<<"删除成功!"<<endl;n--;}}elsecout<<a<<" 不存在的班次"<<endl;return head;}void chache(banche *head)//班次信息查询{int a;banche *p,*p1;p=head;cout<<"请选择查询方式:"<<endl<<"1. 查看全部班次     2.查看指定编号班次"<<endl;cin>>a;if(a==1){cout<<"编号\t"<<"出发地\t"<<"终点站\t"<<"最大载客量\t"<<"剩余可载客数\t"<<"发车时间\t"<<"备注信息\t"<<endl;while(p!=NULL){cout<<p->bianhao <<p->qidian <<'\t'<<p->zhongdian <<'\t'<<p->zuoweishu<<'\t' <<p->shengyup <<'\t'<<p->fache.shi<<p->fache.fen <<'\t'<<endl;p1=p->next ;}}else if(a==2){banche cha;cout<<"请输入要查看班次的编号"<<endl;cin>>cha.bianhao ;while(p!=NULL&&p->bianhao!=cha.bianhao ){p1=p;p=p->next ;}if(p==NULL)cout<<"该班次不存在,查看失败!!"<<endl;elsecout<<"编号\t"<<"出发地\t"<<"终点站\t"<<"最大载客量\t"<<"剩余可载客数\t"<<"发车时间\t"<<"备注信息\t"<<endl<<p->bianhao <<p->qidian <<'\t'<<p->zhongdian <<'\t'<<p->zuoweishu<<'\t' <<p->shengyup <<'\t'<<p->fache.shi<<p->fache.fen <<'\t'<<endl;}elsecout<<"输入错误!!"<<endl;}dingpiaoxx *HEAD=CREAT();dingpiaoxx *CREAT()//建立初始订票信息{int a,b=1;char key;dingpiaoxx *HEAD,*p1,*p2;banche *s;HEAD =NULL;p1=new(dingpiaoxx );p2=p1;cout<<"请输入姓名、身份证号"<<endl;cin>>p1->xingming >>p1->zheng ;cout<<"请输入要到达的目的地:"<<"0 广州;1 深圳;2 东莞;3 佛山;4 揭阳;5 中山;6 茂名;7 汕头"<<endl;cin>>a;p1->gpzd=zhongd (a);cout<<"请输入所订票数(一人最多可定3张票)"<<endl;cin>>p1->piaoshu ;s=head;while(s->zhongdian !=p1->gpzd&&s->next !=NULL )s=s->next ;if(s==NULL)cout<<"班次不存在,请从新操作"<<endl;else{s->shengyup -=p1->gpzd ;while(b){m++;if(m==1)HEAD =p1;else{p2->NEXT =p1;p2=p1;}p1=new(dingpiaoxx );cout<<"请输入姓名、身份证号"<<endl;cin>>p1->xingming >>p1->zheng ;cout<<"请输入要到达的目的地:"<<"0 广州;1 深圳;2 东莞;3 佛山;4 揭阳;5 中山;6 茂名;7 汕头"<<endl;cin>>a;p1->gpzd=zhongd (a);cout<<"请输入所订票数(一人最多可定3张票)"<<endl;cin>>p1->piaoshu ;s=head;while(s->zhongdian !=p1->gpzd&&s->next !=NULL )s=s->next ;if(s==NULL){cout<<"班次不存在,请从新操作"<<endl;b=0;}else{s->shengyup -=p1->gpzd ;cout<<"是否继续,Y(是),N(否)"<<endl;cin>>key;if(key=='n'||key=='N')b=0;}}}delete p1;p2->NEXT =NULL;return HEAD ;}dingpiaoxx *dingpiao(dingpiaoxx *HEAD)//订票{int a,b=1;banche *s;char key;while(b=1){dingpiaoxx *p1=new dingpiaoxx ;cout<<"请输入您的姓名及身份证号"<<endl;cin>>p1->xingming >>p1->zheng ;cout<<"请输入您想要到达的目的地:"<<"0 广州;1 深圳;2 东莞;3 佛山;4 揭阳;5 中山;6 茂名;7 汕头"<<endl;cin>>a;p1->gpzd=zhongd (a);cout<<"请输入您想要订的票数(一人最多可定3张票)"<<endl;cin>>p1->piaoshu ;if(p1->piaoshu >3){cout<<"操作错误,订票失败!"<<endl;delete p1;}else {s=head;while(s->zhongdian !=p1->gpzd&&s!=NULL )s=s->next ;if(s==NULL){   delete p1;cout<<"班次不存在,订票失败!"<<endl<<"是否重新操作:Y(是),N(否)"<<endl;cin>>key;if(key=='n'||key=='N')b=0;}else{s->shengyup -=p1->gpzd ;p1->NEXT =HEAD ;HEAD =p1;cout<<"订票成功,祝您旅途愉快!"<<endl;b=0;m++;}}}return HEAD ;}void gaip(dingpiaoxx *HEAD)//用于管理员维护数据{int a;dingpiaoxx gai,*p;p=HEAD ;cout<<"请选择输入需要修改的姓名或身份证号:1.姓名;2身份证号"<<endl;cin>>a;if(a==1){cout<<"请输入要修改记录的姓名"<<endl;cin>>gai.xingming ;while(p->xingming !=gai.xingming &&p->NEXT !=NULL)p=p->NEXT ;if(p->NEXT ==NULL)cout<<"没有此人的订票信息,请核对后输入!!"<<endl;elsexiup(p);}else if(a==2){cout<<"请输入要修改记录的身份证号码"<<endl;cin>>gai.zheng  ;while(p->zheng!=gai.zheng &&p->NEXT !=NULL)p=p->NEXT ;if(p->NEXT ==NULL)cout<<"没有此人的订票信息,请核对后输入!!"<<endl;elsexiup(p);}elsecout<<"输入错误,请按提示输入!"<<endl;}void xiup(dingpiaoxx *HED ){int a,b=1;dingpiaoxx *p1;banche *s=head ;p1=HED;while (s->next!=NULL&&s->zhongdian !=p1->gpzd )s=s->next ;cout<<"姓名\t"<<"到达站\t"<<"所购票数\t"<<"车次编号\t"<<"购票日期\t"<<"购票时间\t"<<"备注信息"<<endl<<p1->xingming<<'\t'<<p1->gpzd<<'\t'<<p1->piaoshu<<s->bianhao<<'\t'<<" 年"<<' 月'<<" 日"<<'\t'<<" 点"<<" 分"<<" 秒"<<'\t'<<endl<<"查询成功!!"<<endl;while(b==1){cout<<"请输入需要修改的信息:"<<endl<<"1.姓名  2.到达站  3.所购票数  4.购票日期  5.购票时间  6.备注信息"<<endl;cin>>a;switch (a){case 1:cout<<"请输入姓名"<<endl;cin>>p1->xingming ;break;case 2:cout<<"请输入身份证号码"<<endl;cin>>p1->zheng ;break;case 3:cout<<"请输入订票数"<<endl;cin>>p1->piaoshu ;break;case 4:cout<<"请输入购票日期(年、月、日)"<<endl;cin>>p1->riqi .year >>p1->riqi .month >>p1->riqi .day  ;break;case 5:cout<<"请输入购票时间(时、分、秒)"<<endl;cin>>p1->shijian .shi  >>p1->shijian .fen >>p1->shijian .miao ;break;case 6:cout<<"请输入备注信息:(0.售票中,1.可发车,2.班次取消)"<<endl;int k;cin>>k ;s->beizhu =beiz (k); break;default :cout<<"输入错误,请按提示输入!"<<endl;}char key;cout<<"是否要修改其他信息?Y(是),N(否)"<<endl;cin>>key;if(key=='n'||key=='N')b=0;}cout<<"修改成功!!"<<endl;}void chapiao(dingpiaoxx *HEAD )//订票信息查询(管理员使用){dingpiaoxx *p1;banche *s=head ;p1=HEAD ;cout<<"姓名\t"<<"到达站\t"<<"所购票数\t"<<"车次编号\t"<<"购票日期\t"<<"购票时间\t"<<"备注信息"<<endl;while(p1->NEXT !=0){while (s->next!=NULL&&s->zhongdian !=p1->gpzd )s=s->next ;s->shengyup -=p1->piaoshu ;cout<<p1->xingming<<'\t'<<p1->gpzd<<'\t'<<p1->piaoshu<<s->bianhao<<'\t'<<" 年"<<' 月'<<" 日"<<'\t'<<" 点"<<" 分"<<" 秒"<<'\t'<<endl;}cout<<"查询成功!!"<<endl;}dingpiaoxx *tuip(dingpiaoxx *HEAD )//客户查询和退票{dingpiaoxx *p1,*p2;dingpiaoxx cx;banche *s;char key;int a,b=1;while(b==1){p1=HEAD ;p2=p1;cout<<"请输入您的姓名和身份证号码"<<endl;cin>>cx.xingming >>cx.zheng ;while(cx.xingming !=p1->xingming &&cx.zheng !=p1->zheng&&p1!=NULL ){p2=p1;p1=p2->NEXT ;}if(cx.xingming==p1->xingming&&cx.zheng ==p1->zheng){s=head;while (s->next!=NULL&&s->zhongdian !=p1->gpzd )s=s->next ;s->shengyup -=p1->piaoshu ;cout<<"姓名\t"<<"到达站\t"<<"所购票数\t"<<"车次编号\t"<<"购票日期\t"<<"购票时间\t"<<"备注信息"<<endl<<p1->xingming<<'\t'<<p1->gpzd<<'\t'<<p1->piaoshu<<s->bianhao<<'\t'<<" 年"<<' 月'<<" 日"<<'\t'<<" 点"<<" 分"<<" 秒"<<'\t'<<endl<<"查询成功!!"<<endl;cout<<"请选择您的操作:1.退票;    2.返回"<<endl;cin>>a;switch (a){case 1:if(p1==HEAD )HEAD =p1->NEXT ;elsep2->NEXT =p1->NEXT ;m--;cout<<"您已成功退票,感谢您的支持!"<<endl;break;case 2:return HEAD ;break;}b=0;}else if(cx.xingming ==p1->xingming&&cx.zheng !=p1->zheng){cout<<"姓名与身份证号不匹配,请重新输入!确定(Y)  取消(N)"<<endl;cin>>key;if(key=='n'||key=='N')b=0;}else{cout<<"没有您的购票记录或输入信息有误,请核实后输入"<<endl;cout<<"确定重新输入请按“Y”,取消请按“N”"<<endl;cin>>key;if(key=='n'||key=='N')b=0;}}return HEAD ;}dingpiaoxx  *tianjia(dingpiaoxx *HEAD)//管理员更改数据或人工售票{return HEAD;}dingpiaoxx *shanc(dingpiaoxx *HEAD )//人工退票、数据更新{dingpiaoxx *p,ss;p=HEAD ;cout<<"请输入要删除的记录的姓名或身份证号:1.姓名  2.身份证号码"<<endl;int a;cin>>a;if(a==1){cout<<"请输入删除者姓名"<<endl;cin>>ss.xingming ;while( p->NEXT!=NULL && p->xingming ==ss.xingming )p=p->NEXT ;}return HEAD ;}void welc()//欢迎界面{cout<<"***-。-。-。-。-。-。-。-***"<<endl<<"*                          *"<<endl<<"|                          |"<<endl<<"。    欢迎使用本系统       。"<<endl<<"|                          |"<<endl<<"*                          *"<<endl<<"***-。-。-。-。-。-。-。-***"<<endl;}void xuanze()//两个接口进入系统,管理员和用户采用不同入口//管理员进入管理界面需登陆{cout<<"######################################"<<endl<<"###         请选择入口             ###"<<endl<<"######################################"<<endl<<" "<<endl<<"&&&&&&   我是叼炸天的管理员    &&&&&&"<<endl<<"             代号:1                 "<<endl<<" "<<endl<<"&&&&&&    我只是个寂寞的乘客   &&&&&&"<<endl<<"            代号:2                  "<<endl<<"                                     "<<endl;}void chushi(){cout<<"首次使用系统,请进完善始数据"<<endl<<"^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"<<endl<<"第一项:请建立班次信息表并输入初始数据"<<endl;banche *creat();cout<<"班车信息已建立!!"<<endl<<"第二项:请建立订票信息表"<<endl;dingpiaoxx *CREAT();//cout<<"订票信息表已成功建立,请按任意键进入主界面"<<endl;}void weihu()//数据维护总函数,管理员使用,包括所有信息的查询、//修改、增添新纪录、删除原有记录{int a;cout<<"欢迎进入班车信息系统维护系统"<<endl;cout<<"请选择您要进行的操作:"<<endl<<"1.班次信息查询\t"<<"2.订票信息查询\t"<<endl<<"3.添加班次记录\t"<<"4.删除班次记录\t"<<endl<<"5.添加订票记录\t"<<"6.删除订票记录\t"<<endl<<"7.修改班次记录\t"<<"8.修改订票记录\t"<<endl;cin>>a;switch (a){case 1: chache(head);break;case 2: chapiao(HEAD );break;case 3:head=charu(head );break;case 4:head=del(head); break;case 5:HEAD =tianjia(HEAD ); break;case 6:HEAD=shanc (HEAD );break;case 7:xiug(head); break;case 8: gaip(HEAD );break;default :cout<<"输入错误,请输入正确的操作序号"<<endl;}}void kehu()  //用户中心,用户在此选择需要的操作{cout<<"欢迎您,请选择您要进行的操作:"<<endl<<"1.车次信息查看   2.我要购票     3.已购票查询及退订 "<<endl;int a;cin>>a;switch (a){case 1: chache(head);break;case 2:HEAD=dingpiao(HEAD );break;case 3:HEAD=tuip (HEAD);break;default :cout<<"输入错误,请按提示信息输入"<<endl;}}int denglu()//管理员登陆函数{guanli ff;int n=4;for(;n>0;){n--;cout<<"请输入您的账号和密码"<<endl;cin>>ff.zh >>ff.mima ;if((ff.zh ==guan1 .zh &&ff.mima ==guan1 .mima)||(ff.zh ==guan2 .zh &&ff.mima ==guan2 .mima) ){cout<<"恭喜:登陆成功!!"<<endl;return 1;break;}else cout<<"账号或密码错误,请重新输入"<<"还有"<<n<<"次机会"<<endl;}cout<<"登陆失败!!!"<<endl;return 2;}


建立链表:


欢迎界面


管理员主页面


乘客查询



对于时间和日期的问题,上网查了很多,各种方式,但都是直接输出的形式,未能找到一个能成功地将时间、日期的各个部分提取出来放入数组或变量中的方法(主要是停网之后上网极不方便,时间上受极大限制),所以,很多地方都跳过了对时间和日期的操作。

通过这次作业深刻体会到作为“程序猿”的痛苦,我知道我的程序有很多地方不够完善,有很多漏洞,与老师的要求还有一定出入,但我确实努力地做了,由于时间问题,不完善的地方只有以后慢慢修改了。

我庆幸当别人去网上复制粘贴的时候,我没有随波逐流,坚持完全原创,花了别人几倍乃至几十倍的时间来完成它,虽然不甚完美,但毕竟是自己做的,对得起自己的良心,也许将来再也不会写这么复杂的C++程序了,且行且珍惜吧。从另一个方面来说,写这样的程序锻炼了自我全方位思考问题,对于养成好的全局观念有一定作用。有点迟交了,望老师见谅。





1 0
原创粉丝点击