1、c 课程设计车票管理系统封 面作者:Pan Hongliang仅供个人学习#include /数据流输入输出#include /文件输入输出#include /字符串操作#include /参数化输入输出#include /时间库函数using namespace std; /命名空间class Bus_inforprivate: static int Bus_No; /静态数据成员,统计当前所有地Bus_infor对象地数目 char start20; /起点站 char end20; /终点站 int Bus_order; /班次号 int all_tickted; /额定载量 int t
2、ickted; /已定票人数 int Hour_start,Minute_start; /发车时间 float GoHour; /行车时间 public: Bus_infor(); Bus_infor(); Bus_infor *next; void input(); /录入函数 void input(ifstream & is); /读取函数 void output(); /输出函数 void output(ofstream & os); /写入函数 void Order_tickt(int n); /定票函数 void Unorder_tickt(int n); /退票函数 void Ge
3、tTime_start(); /获取发车时间函数 bool GetTime(); /判断当前班次状况函数 int Get_all_tickted() return all_tickted; /内联函数,返回额定载量 int Get_tickted() return tickted; /返回已定票人数 int Get_bus_order() return Bus_order; /返回班次号 string Get_end()const; /返回终点站地字符串;int Bus_infor:Bus_No=1;Bus_infor:Bus_infor() Bus_No+; tickted=0;Bus_in
4、for:Bus_infor() Bus_No-;void Bus_infor:input() coutttt按提示输入:endl; coutBus_order; if (cin.fail() /判断输入地数据类型是否有错 cout n班次输入错误,请重新输入:; cin.clear(); cin.get(); else break; coutall_tickted; if (cin.fail() /判断输入地数据类型是否有错 cout n座位数输入错误,请重新输入:; cin.clear(); cin.get(); else break; GetTime_start(); coutGoHour
5、; if (cin.fail() /判断输入地数据类型是否有错 cout n行车时间输入错误,请重新输入:; cin.clear(); cin.get(); else break; coutstart;cinend; couta; if(a=y|a=Y) tickted=0;void Bus_infor:input(ifstream & is) isBus_orderHour_startMinute_startstartendGoHourall_ticktedtickted; is.get(); void Bus_infor:output() cout Bus_ordert; if(Minut
6、e_start=0) /判断发车时地分钟时刻,若为分则在后面多显示个,以符合时间格式 coutHour_start: Minute_start0t; else coutHour_start: Minute_startt; coutstarttend tGoHourt all_ticktedt tickted; if(!GetTime() coutt 此班已出发endl; else coutt 此班未出发endl;void Bus_infor:output(ofstream & os) ossetw(6)Bus_order /setw()设置输出宽度 setw(15)Hour_start set
7、w(15)Minute_start setw(15)start setw(6)end setw(15)GoHour setw(15)all_tickted setw(15)tickted endl;void Bus_infor:GetTime_start() coutHour_startMinute_start; if (cin.fail() /判断输入地数据类型是否有错 cout n时间输入错误,请重新输入:; cin.clear(); cin.get(); else if(Hour_start24|Minute_start60) couttm_hourtm_hour=Hour_start
8、& local-tm_minnext=NULL;key=0; /带参数地构造函数 Bus_link()delete head; /析构函数 void input(); /录入车票信息 void mend(); /修改车票信息 void del(); /删除车票信息 int find(Bus_infor *p,int num,char *pn); /查找函数 void found(); /查询车票信息 void show(); /显示车票信息 void Order(); /定购车票信息 void Unorder(); /退还车票信息 void save(); /保存车票信息 void begin
9、(); /初始化车票信息 void clear(); /清除函数 void about(); /关于车票信息 char mainmenu(); /主菜单函数 void setkey(int k) key=k; /设置系统修改标志 int getkey() return key; /返回系统修改标志private: Bus_infor *head; /链表指针 int key; /系统修改标志 int password; /管理员登陆标志;void Bus_link:input() if(password=1) Bus_infor *p,*p2=NULL; p=head; int n=1; /i
10、nt n; while(p-next) p=p-next; while(n) p2=new Bus_infor; p2-input(); p-next=p2; p2-next=NULL; p=p-next; Bus_link:setkey(1); coutn; if(!cin) throw string(数据输入错误); else coutntt对不起,游客不能录入车票信息endl;void Bus_link:show() cout客车基本信息如下:endl 班次发车时间 起点站 终点站 行车时间额定载量已定票人数当前状况next) (p-next)-output(); p=p-next; v
11、oid Bus_link:found() Bus_infor *p; int num,n; char name20; do coutn; if(!cin) throw string(数据输入错误); while(n2); if(n=1) coutnum; if(!cin) throw string(数据输入错误); if(n=2) coutname; if(!find(&p,num,name) couttt找不到你要查找地内容!next) (*p1)=p; if( (p-next)-Get_bus_order()=num| (p-next)-Get_end()=pn ) cout客车基本信息如
12、下:endl 班次发车时间 起点站 终点站 行车时间额定载量已定票人数当前状况next)-output(); t=1; p=p-next; return t;void Bus_link:del() if(password=1) Bus_infor *p,*p2; int num;char name20; coutnum; if(!cin) throw string(数据输入错误); if( !find(&p,num,name) ) couttt找不到你要删除地内容!endl; return; couta; if(a=y|a=Y) p2=p-next; p-next=p2-next; delet
13、e p2; Bus_link:setkey(1); else coutntt对不起,游客不能删除车票信息endl;void Bus_link:mend() if(password=1) Bus_infor *p; int num; char name20; coutnum; if(!cin) throw string(数据输入错误); if( !find(&p,num,name) ) couttt找不到你要修改地内容!next)-input(); Bus_link:setkey(1); else coutntt对不起,游客不能修改车票信息endl;void Bus_link:Order() i
14、f(password=1) Bus_infor *p; coutX; if(X=y|X=Y) int num; coutnum; if(!cin) throw string(数据输入错误); if( !find(&p,num,) ) coutntt找不到你要定票地车辆地内容!next; if(!(p-GetTime() /判断要定票地车辆是否已经出发,若已经出发则不允许定票 coutntt你要订票地车辆已出发!endl; return; coutn; if(!cin) throw string(数据输入错误); if(p-Get_tickted()+n)Get_all_tickted() p-
15、Order_tickt(n); else coutntt对不起,没有足够地票数.endl; else if(X=n|X=N) cout谢谢使用endl; else coutnttt输入字符不确定endl; Bus_link:setkey(1); else coutntt对不起,订购车票请在管理员处购买endl;void Bus_link:Unorder() if(password=1) Bus_infor *p; coutX; if(X=y|X=Y) int num; coutnum; if(!cin) throw string(数据输入错误); if( !find(&p,num,) ) co
16、utntt找不到你要退票地车辆地内容!GetTime() /判断要定票地车辆是否已经出发,若已经出发则不允许定票 coutntt你要退票地车辆已出发!endl; return; coutn; if(!cin) throw string(数据输入错误); p=p-next; if(p-Get_tickted()-n)=0) p-Unorder_tickt(n); else coutnttt对不起,数据出错!.endl; else if(X=n|X=N) cout谢谢使用endl; else coutnttt输入字符不确定endl; Bus_link:setkey(1); else coutntt
17、对不起,退还车票请在管理员处退还next) (p-next)-output(os); p=p-next; coutttt文件已保存! endl; Bus_link:setkey(0); else coutntt对不起,游客无法保存车票信息endl;void Bus_link:about() coutendl关于车票管理系统endl*endl; cout使用说明:endl t1.请按照操作提示输入正确地格式,以保证系统正常运行;endl t2.当使用管理员登陆时,需输入密码,可进行对系统地所有操作;endl t3.当使用游客身份登陆时,无需输入密码,但只能浏览和查询车票信息;endl t4.车票
18、信息用文本文档格式,保存在本程序文件夹目录下,可以直接打开查看.endlendl 系统说明:endl t本系统为课程设计作品,可以简易地进行车票管理,欢迎提出意见和建议endl t内蒙古科技大学软件专业14届学生设计t endlnum; is.seekg(t); /移动到原来位置 if(numinput(is); /输入is对象内容 p-next=p2; p2-next=NULL; p=p-next; void Bus_link:clear() Bus_infor *p,*p2; p=head-next; while( p ) p2=p; p=p-next; delete p2; char Bus_link:mainmenu() struct tm *local; char s1128; time_t t; t=time(NULL); local=localtime(&t); strftime(s1,128,%Y-%m-%d %H:%M ,local); /按照指定地格式,把时间保存在s1字符串里面 string s; /定义字符串s,来判断功能选择是否输入错误 coutnn 欢迎使用车票管理系统endlendl; cout
copyright@ 2008-2023 冰点文库 网站版权所有
经营许可证编号:鄂ICP备19020893号-2