1、typedef struct people struct man data ; struct people*next ;bookMan,*bookManLink ;/* 初始界面*/void printInterface() puts(*);* Welcome to use the system of booking tickets * You can choose the operation: * 1:Insert a train information * 2:Inquire a train information * 3:Book a train ticket * 4:Update th
2、e train information * 5:Advice to you about the train * 6:save information to file * 7:quit the system */*添加一个火车信息*/void InsertTraininfo(Link linkhead) struct node *p,*r,*s ; r = linkhead ; s = linkhead-next ; while(r-next!=NULL) r=r- while(1) printf(please input the number of the train(0-return) sc
3、anf(%s,num); if(strcmp(num,0)=0) break ; /*判断是否已经存在*/ while(s) if(strcmp(s-data.num,num)=0)the train %shas been born!n return ; s = s- p = (struct node*)malloc(sizeof(struct node); strcpy(p-data.num,num);Input the city where the train will reach:,p-data.city);Input the time which the train take off:
4、data.takeoffTime);Input the time which the train receive:,&p-data.receiveTime);Input the price of ticket:%ddata.price);Input the number of booked tickets:data.bookNum); p-next=NULL ; r-next=p ; r=p ; shoudsave = 1 ;/*打印火车票信息*/void printTrainInfo(struct node*p)nThe following is the record you want:nu
5、mber of train: %sndata.num);city the train will reach:the time the train take off: %snthe time the train reach:data.takeoffTime,p-the price of the ticket: %dnthe number of booked tickets:struct node * Locate1(Link l,char findmess,char numorcity) Node*r ; if(strcmp(numorcity,num r=l- while(r) if(strc
6、mp(r-data.num,findmess)=0) return r ; else if(strcmp(numorcity,citydata.city,findmess)=0) return 0 ;/*查询火车信息*/void QueryTrain(Link l) Node *p ; int sel ; char str15,str210; if(!l-next)There is not any record !Choose the way:n1:according to the number of train;2:according to the city:sel); if(sel=1)I
7、nput the the number of train:,str1); p=Locate1(l,str1, if(p) printTrainInfo(p); else mark1=1 ;nthe file cant be found! else if(sel=2)Input the city:,str2); p=Locate1(l,str2,/*订票子模块*/void BookTicket(Link l,bookManLink k) Node*r10,*p ; char ch,dem ; bookMan*v,*h ; int i=0,t=0 ; char str10,str110,str21
8、0; v=k ; while(v- v=v-Input the city you want to go: str); p=l- while(p! if(strcmp(p-data.city,str)=0) ri=p ; i+; p=p-nnthe number of record have %dn,i); for(t=0;ti;t+) printTrainInfo(rt); if(i=0)ntttSorry!Cant find the train for you!ndo you want to book it?ch); if(ch = 1) h=(bookMan*)malloc(sizeof(
9、bookMan);Input your name:str1); strcpy(h-data.name,str1);Input your id:str2);data.num,str2);Input your bookNum:dem); h-data.bookNum=dem ; v-next=h ; v=h ;nLucky!you have booked a ticket! getch(); shoudsave=1 ;bookMan*Locate2(bookManLink k,char findmess) bookMan*r ; r=k- mark=1 ;/*修改火车信息*/void Update
10、Info(Link l) Node*p ; char findmess20,ch ;nthere isnt record for you to modify! QueryTrain(l); if(mark1=0)nDo you want to modify it? getchar();%c if(ch=ynInput the number of the train:,findmess); p=Locate1(l,findmess,Input new number of train:Input new city the train will reach:Input new time the tr
11、ain take offInput new time the train reach:Input new price of the ticket:Input new number of people who have booked ticket:nmodifying record is sucessful!tttcant find the record! mark1=0 ;/*系统给用户的提示信息*/void AdvicedTrains(Link l) char str10; int mar=0 ;Iuput the city you want to go:,str);data.city,st
12、r)=0&r-data.bookNum if(fwrite(p,sizeof(bookMan),1,fp)=1)int main() FILE*fp1,*fp2 ; Node*p,*r ; char ch1,ch2 ; Link l ; bookManLink k ; bookMan*t,*h ; l=(Node*)malloc(sizeof(Node); l- r=l ; k=(bookMan*)malloc(sizeof(bookMan); k- h=k ; fp1=fopen(ab+ if(fp1=NULL)cant open the file! while(!feof(fp1) p=(
13、Node*)malloc(sizeof(Node); if(fread(p,sizeof(Node),1,fp1)=1) count1+; fclose(fp1); fp2=fopen( if(fp2=NULL)feof(fp2) t=(bookMan*)malloc(sizeof(bookMan); if(fread(t,sizeof(bookMan),1,fp2)=1) t-next=t ; h=t ; count2+; fclose(fp2); system(cls printInterface();please choose the operation: if(sel=8) if(sh
14、oudsave=1)nthe file have been changed!do you want to save it(y/n)?ch1); if(ch1=|ch1=Y) SaveBookmanInfo(k); SaveTrainInfo(l);nThank you!You are welcome toon switch(sel) case 1 : InsertTraininfo(l);break ; case 2 : case 3 : BookTicket(l,k); case 4 : UpdateInfo(l); case 5 : AdvicedTrains(l); case 6 :SaveBookmanInfo(k); case 7 : return 0;nplease press any key to continue.
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1