1、车票管理系统1#include #include #include #include #include using namespace std; class Bus_infor int No; static int Bus_No; char start20; char end20; int Bus_order; int all_tickted; int tickted; int Hour_start,Minute_start,Hour_end,Minute_end; int Hour;int Minute; public: Bus_infor *next; Bus_infor(); Bus_i
2、nfor(); int Get_no(); int Get_all_tickted(); int Get_tickted(); int Get_bus_order(); char *Get_start(); char *Get_end(); void addr(); void Order_tickt(int n); void Unorder_tickt(int n); void GetTime_start(); void GetTime_end(); void ShowTime(); void GetTime(); void Show_infor(); void input() coutttt
3、按提示输入:endl; coutBus_order; coutall_tickted; GetTime_start(); GetTime_end(); addr(); char a; cout是否清空售票(y/n)?a; if(a=y) tickted=0; void input(ifstream & is) isBus_orderstartendall_ticktedticktedHour_startMinute_startHour_endMinute_end; is.get(); void output() cout客车基本信息如下:endl; cout车次:Bus_order 始发站:s
4、tart 终点站:end 额定人数:all_tickted 已售票tickted 始发时间Hour_start: Minute_start到站时间 Hour_end: Minute_endendlendl; void output(ofstream & os) ossetw(6)Bus_order setw(15)start setw(6)end setw(15)all_tickted setw(15)tickted setw(15)Hour_start setw(15)Minute_start setw(15)Hour_end setw(15)Minute_end endl; ; int B
5、us_infor:Bus_No=1; void Bus_infor:GetTime_start() int NewH=0,NewM=0; cout请输入始发时间:NewHNewM; Hour_start=NewH; Minute_start=NewM; void Bus_infor:GetTime_end() int NewH=0,NewM=0; cout请输入到站时间:NewHNewM; Hour_end=NewH; Minute_end=NewM; void Bus_infor:GetTime() if(Minute_end=Minute_start)Minute=(Minute_end-
6、Minute_start); Hour=(Hour_end-Hour_start); else Minute=(Minute_end-Minute_start+60); Hour=(Hour_end-Hour_start-1); void Bus_infor:ShowTime() coutHour_start:Minute_start ; coutHour_end:Minute_end ; coutHour:Minuteendl; Bus_infor:Bus_infor() No=Bus_No+; tickted=0; Bus_infor:Bus_infor() Bus_No-; /set t
7、he addr void Bus_infor:addr() cout请输入起始站与终点站:a;cinb; strcpy(start,a);strcpy(end,b); /Get the start addr char *Bus_infor:Get_start() return start; /Get the end addr char *Bus_infor:Get_end() return end; /Get the no int Bus_infor:Get_no() return No; int Bus_infor:Get_all_tickted() return all_tickted;
8、int Bus_infor:Get_tickted() return tickted; int Bus_infor:Get_bus_order() return Bus_order; /order the tickt void Bus_infor:Order_tickt(int n) tickted=tickted+n; void Bus_infor:Unorder_tickt(int n) tickted=tickted-n; ; class Bus_link public: Bus_link()head=new Bus_infor;head-next=NULL;key=0; /Bus_li
9、nk()delete head; void input(); void mend(); void del(); int find(Bus_infor *p,int num,char *pn); int find1(Bus_infor *p,int num,char *pn); void found(); void show(); void Order(); void Unorder(); void save(); void begin(); void clear(); char mainmenu(); int getkey() return key; void setkey(int k) ke
10、y=k; private: Bus_infor *head; int key; ; /录入函数 void Bus_link:input() Bus_infor *p,*p2=NULL; p=head; int 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; /定票函数void Bus_link:Order() Bus_infor *p; cout确定购票(y/n)?X; if(X=y) i
11、nt num; coutnum; if( !find1(&p,num,) ) couttt找不到你要定票的车辆的内容!endl; return; coutn; p=p-next; if(p-Get_tickted()+n)Get_all_tickted() p-Order_tickt(n); else cout对不起,没有足够的票数。endl; else if(X=n) cout谢谢使用endl; else cout输入字符不确定endl; Bus_link:setkey(1); /退票函数void Bus_link:Unorder() Bus_infor *p; cout确定退票(y/n)?
12、X; if(X=y) int num; coutnum; if( !find1(&p,num,) ) couttt找不到你要定票的车辆的内容!endl; return; coutn; p=p-next; if(p-Get_tickted()-n)=0) p-Unorder_tickt(n); else cout对不起,数据出错!。endl; else if(X=n) cout谢谢使用endl; else cout输入字符不确定endl; Bus_link:setkey(1); /查找函数void Bus_link:found() Bus_infor *p; int num=-1,n=9; ch
13、ar name20=; do coutn; while(n2); if(n=1) coutnum; if(n=2) coutname; if(!find(&p,num,name) couttt找不到你要查找的内容!next) (*p1)=p; if( (p-next)-Get_bus_order()=num|!strcmp( (p-next)-Get_end(),pn ) ) (p-next)-output(); t=1; p=p-next; return t; /子查找函数 int Bus_link:find1(Bus_infor *p1,int num,char *pn) Bus_info
14、r *p; p=head; int t=0; while(p-next) (*p1)=p; if( (p-next)-Get_bus_order()=num|!strcmp( (p-next)-Get_end(),pn ) ) return 1; p=p-next; return 0; /删除函数void Bus_link:del() Bus_infor *p,*p2; int num; coutnum; if( !find(&p,num,) ) couttt找不到你要删除的内容!next; p-next=p2-next; delete p2; Bus_link:setkey(1); /显示函
15、数 void Bus_link:show() Bus_infor *p; p=head; while(p-next) (p-next)-output(); p=p-next; /修改函数void Bus_link:mend() Bus_infor *p; int num=-1; char name20=; coutnum; if( !find1(&p,num,name) ) couttt找不到你要修改的内容!next)-output(); (p-next)-input(); Bus_link:setkey(1); /保存函数void Bus_link:save() Bus_infor *p;
16、p=head; ofstream os(bus.txt,ios:out); if (Bus_link:getkey()=1) while(p-next) (p-next)-output(os); p=p-next; coutttt文件已保存! num; is.seekg(t); if(numinput(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
17、 Bus_link:mainmenu() char n6; coutnn 欢迎使用车票管理系统endlendl; cout-endlendl -endl -endl 1. 录入车票信息 2. 浏览车票信息 endl 3. 查询车票信息 4. 删除车票信息 endl 5. 修改车票信息 6. 定购车票信息 endl 7. 退还车票信息 8. 保存车票信息 endl 0: 退出系统 endl -endl -endl n; return n0; /主函数int main() Bus_link pp; int k=1; char n; pp.begin(); while(k=1) n=pp.mainm
18、enu();/调用主菜单函数 switch(n) case 1:pp.input(); break; /录入车票信息 case 2:pp.show(); break; /浏览车票信息 case 3:pp.found(); break; /查询车票信息case 4:pp.del(); break; /删除车票信息case 5:pp.mend(); break; /修改车票信息 case 6:pp.Order(); break; /保存车票信息 case 7:pp.Unorder(); break; /退还车票信息case 8:pp.save(); break; /保存车票信息case 0: /退出系统 if(pp.getkey()=1) coutk; if(k=1) pp.save(); pp.clear(); k=0; break; return 0;
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1