资源描述:
《飞机售票系统程序.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、#include"ticket.h"#include"plan.h"#include"infor.h"//对plan.h进行定义//#ifndef_PLAN_H#define_PLAN_H#include#include#include#idefinePLANEDAT"plane.dat"//航班记录文件voidplane_check();AirPlaneplane_check_id(intid,intflag);//按航班id查找intplanesave(AirPl
2、anePlane);//保存航班记录#endif//_PLAN_H//对infor.h进行定义//#ifndef_INFOR_H#define_INFOR_H//机票信息typedefstruct{intm_planeID;//航班号charm_left;//剩余票数charm_date;//日期floatm_price;//价格intm_rebate;//设置打折}AirPlane;//用户信息typedefstruct{charm_ID[20];//身份证号charm_name[20];//姓名intm_planeID;
3、//航班号charm_ticketnum[15];//机票编号intm_isFlog;//}Passenger;#endif//_INFOR_Hintmain(){printf("-------------welcomeuse--------------");menu();return0;}voidmenu(){intc;while(1){printf("--MENU-------------------");printf("t[1]订票");printf("t[0]退出");printf("----
4、---------------------");printf("请输入:");scanf("%d",&c);switch(c){case1:book_ticket();break;case0:return;}}voidsave(Passengerpass)//保存售票记录{intr=0;AirPlaneplane={0};//用户文件写入FILE*fd=fopen(USERDAT,"a+");if(NULL==fd){printf("%sOPENERROR!",PLANEDAT);return;}fwrite(&pa
5、ss,sizeof(pass),1,fd);fclose(fd);//plane文件修改fd=fopen(PLANEDAT,"r+");if(NULL==fd){printf("%sOPENERROR!",PLANEDAT);return;}while(1){r=fread(&plane,sizeof(plane),1,fd);if(r<=0)break;if(plane.m_planeID==pass.m_planeID){plane.m_left--;fseek(fd,sizeof(plane)*(-1),SEEK_
6、CUR);fwrite(&plane,sizeof(plane),1,fd);break;}}fclose(fd);}voidbook_ticket(){intid=0;charc;AirPlaneplane={0};Passengerpass={0};printf("--订票-----------------------");while(1){printf("请输入航班号:(0退出订票)");scanf("%d",&id);if(0==id)break;plane=plane_check_id(id,0);if
7、(plane.m_planeID==0){printf("航班不存在");continue;}if(plane.m_left==0){printf("无票,是否定其它航班(y/n)");scanf("%c",&c);if(c!='y'&&c!='Y')break;elsecontinue;}printf("请输入你的身份证号");scanf("%s",pass.m_ID);printf("请输入你的姓名:");scanf("%s",pass.m_name);showticket(&plane,&pass);p
8、rintf("是否确定(y/n)");scanf("%c",&c);if(c=='y'
9、
10、c=='Y'){ticket(pass.m_ticketnum);printf("%s",pass.m_ticketnum);pass.m_planeID=plane.m_planeID;sa