C語言程序設(shè)計-火車訂票系統(tǒng)程序設(shè)計報告_第1頁
C語言程序設(shè)計-火車訂票系統(tǒng)程序設(shè)計報告_第2頁
C語言程序設(shè)計-火車訂票系統(tǒng)程序設(shè)計報告_第3頁
C語言程序設(shè)計-火車訂票系統(tǒng)程序設(shè)計報告_第4頁
C語言程序設(shè)計-火車訂票系統(tǒng)程序設(shè)計報告_第5頁
已閱讀5頁,還剩30頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

遼寧師范大學(xué)設(shè)計題目火車訂票系設(shè)計專:

電信工班:09級3班姓:

張學(xué):word可自由復(fù)制編輯

錄一總體設(shè)計(包含幾大功能模塊)二詳細(xì)設(shè)計(各功能模塊的具體實現(xiàn)算法——流程圖......................................................................................2三調(diào)試分(包含各模塊的測試用例及測試結(jié)果)..............................................................................................33.1程序.......................................................................63.2試與測試.............................................................四總結(jié)...............................................................................

word可自由復(fù)制編輯

總體設(shè)計(包含幾大功能模塊)1.Insertatraininformation(入火車息)2.inquireatrainjinformation(詢火車息)3.Bookatrain訂票4.Updatethetrain更新火信)5.Advicetoyouaboutthe(建議6.Saveinformationtofile(儲存信歸檔)7.Quitthesystem(出系統(tǒng))word可自由復(fù)制編輯

二、詳細(xì)設(shè)計(各功能模塊的具體實現(xiàn)算法——流程圖)2.1各函數(shù)的能和實現(xiàn)1.Insertatraininformation(入火車信息:輸入包火車班次,最終地,始發(fā)站火車到站時,車票價,所定票號。用函數(shù)voidinput實現(xiàn)此操作2.inquiretrain查詢火車息):沒有任何記錄3.Bookatrainticket(訂)輸入你想要的城市4.Updatethetrain更新火車信息):可用find()來實現(xiàn)5.Advicetoyouabouttrain(于火車對的建議)6.Saveinformationto儲存信歸檔7.Quitsystem(出系統(tǒng)可用一個函數(shù))來實現(xiàn),首先將信息保存到文件中放動態(tài)創(chuàng)建的內(nèi)存空間退出此程序。word可自由復(fù)制編輯

流程圖詳見A4紙上繪word可自由復(fù)制編輯

三調(diào)試分析(包含各模塊的測試用例,及測試結(jié)果)3.1源程序#include<conio.h>#include<stdio.h>#include<stdlib.h>#include<string.h>intshoudsave=0;intcount1=0,count2=0,mark=0,mark1=0;/*定義存儲火車信的結(jié)構(gòu)體*/structtrain{charnum[10];/*列車*/charcity[10];/*的城市/chartakeoffTime[10];/*車時間*/charreceiveTime[10];/*達(dá)時間*/intprice;/*票價/intbookNum;/*數(shù)*/};word可自由復(fù)制編輯

/*訂票人的信*/structman{charnum[10];/*ID*/charname[10];/*名*/intbookNum;/*求的票數(shù)/};/*定義火車信息鏈的結(jié)點結(jié)構(gòu)/typedefstructnode{structtraindata;structnode*next;}Node,*Link;/*定義訂票人鏈表結(jié)點結(jié)構(gòu)*/typedefstructpeople{structmandata;structpeople*next;}bookMan,*bookManLink;word可自由復(fù)制編輯

/*初始界面/voidprintInterface(){puts("********************************************************");puts("*Welcometousethesystemofbookingtickets*");puts("********************************************************");puts("*Youcanchoosetheoperation:*");puts("*1:Insertatraininformation*");puts("*2:Inquireatraininformation*");puts("*3:Bookatrainticket*");puts("*4:Updatethetraininformation*");puts("*5:Advicetoyouaboutthetrain*");puts("*6:saveinformationtofile*");puts("*7:quitthesystem*");puts("********************************************************");}/*添加一個火車信*/voidInsertTraininfo(Linklinkhead){word可自由復(fù)制編輯

structnode*p,*r,*s;charnum[10];r=linkhead;s=linkhead->next;while(r->next!=NULL)r=r->next;while(1){printf("pleaseinputthenumberofthetrain(0-return)");scanf("%s",num);if(strcmp(num,"0")==0)break;/*斷是否已經(jīng)存在/while(s){if(strcmp(s->data.num,num)==0){printf("thetrain'%s'hasbeenborn!\n",num);return;word可自由復(fù)制編輯

}s=s->next;}p=(structnode*)malloc(sizeof(structnode));strcpy(p->data.num,num);printf("Inputthecitywherethetrainwillreach:");scanf("%s",p->data.city);printf("Inputthetimewhichthetraintakeoff:");scanf("%s",p->data.takeoffTime);printf("Inputthetimewhichthetrainreceive:");scanf("%s",&p->data.receiveTime);printf("Inputthepriceofticket:");scanf("%d",&p->data.price);printf("Inputthenumberofbookedtickets:");scanf("%d",&p->data.bookNum);p->next=NULL;r->next=p;r=p;shoudsave=1;word可自由復(fù)制編輯

}}/*打印火車票信息/voidprintTrainInfo(structnode*p){puts("\nThefollowingistherecordyouwant:");printf(">>numberoftrain:%s\n",p->data.num);printf(">>citythetrainwillreach:%s\n",p->data.city);printf(">>thetimethetraintakeoff:%s\nthetimethetrainreach:%s\n",p->data.takeoffTime,p->data.receiveTime);printf(">>thepriceoftheticket:%d\n",p->data.price);printf(">>thenumberofbookedtickets:%d\n",p->data.bookNum);}structnode*Locate1(Linkl,charfindmess[],charnumorcity[]){Node*r;if(strcmp(numorcity,"num")==0){word可自由復(fù)制編輯

r=l->next;while(r){if(strcmp(r->data.num,findmess)==0)returnr;r=r->next;}}elseif(strcmp(numorcity,"city")==0){r=l->next;while(r){if(strcmp(r->data.city,findmess)==0)returnr;r=r->next;}}return0;word可自由復(fù)制編輯

}/*查詢火車信*/voidQueryTrain(Linkl){Node*p;intsel;charstr1[5],str2[10];if(!l->next){printf("Thereisnotanyrecord!");return;}printf("Choosetheway:\n>>1:accordingtothenumberoftrain;\n>>2:accordingtothecity:\n");scanf("%d",&sel);if(sel==1){word可自由復(fù)制編輯

printf("Inputthethenumberoftrain:");scanf("%s",str1);p=Locate1(l,str1,"num");if(p){printTrainInfo(p);}else{mark1=1;printf("\nthefilecan'tbefound!");}}elseif(sel==2){printf("Inputthecity:");scanf("%s",str2);p=Locate1(l,str2,"city");if(p)word可自由復(fù)制編輯

{printTrainInfo(p);}else{mark1=1;printf("\nthefilecan'tbefound!");}}}/*訂票子模塊/voidBookTicket(Linkl,bookManLinkk){Node*r[10],*p;charch,dem;bookMan*v,*h;inti=0,t=0;charstr[10],str1[10],str2[10];word可自由復(fù)制編輯

v=k;while(v->next!=NULL)v=v->next;printf("Inputthecityyouwanttogo:");scanf("%s",&str);p=l->next;while(p!=NULL){if(strcmp(p->data.city,str)==0){r[i]=p;i++;}p=p->next;}printf("\n\nthenumberofrecordhave%d\n",i);for(t=0;t<i;t++)printTrainInfo(r[t]);if(i==0)word可自由復(fù)制編輯

printf("\n\t\t\tSorry!Can'tfindthetrainforyou!\n");else{printf("\ndoyouwanttobookit?<1/0>\n");scanf("%d",&ch);if(ch==1){h=(bookMan*)malloc(sizeof(bookMan));printf("Inputyourname:");scanf("%s",&str1);strcpy(h->,str1);printf("Inputyourid:");scanf("%s",&str2);strcpy(h->data.num,str2);printf("InputyourbookNum:");scanf("%d",&dem);h->data.bookNum=dem;h->next=NULL;v->next=h;word可自由復(fù)制編輯

v=h;printf("\nLucky!youhavebookedaticket!");getch();shoudsave=1;}}}bookMan*Locate2(bookManLinkk,charfindmess[]){bookMan*r;r=k->next;while(r){if(strcmp(r->data.num,findmess)==0){mark=1;returnr;}r=r->next;word可自由復(fù)制編輯

}return0;}/*修改火車信*/voidUpdateInfo(Linkl){Node*p;charfindmess[20],ch;if(!l->next){printf("\nthereisn'trecordforyoutomodify!\n");return;}else{QueryTrain(l);if(mark1==0){printf("\nDoyouwanttomodifyit?\n");word可自由復(fù)制編輯

getchar();scanf("%c",&ch);if(ch=='y');{printf("\nInputthenumberofthetrain:");scanf("%s",findmess);p=Locate1(l,findmess,"num");if(p){printf("Inputnewnumberoftrain:");scanf("%s",&p->data.num);printf("Inputnewcitythetrainwillreach:");scanf("%s",&p->data.city);printf("Inputnewtimethetraintakeoff");scanf("%s",&p->data.takeoffTime);printf("Inputnewtimethetrainreach:");scanf("%s",&p->data.receiveTime);printf("Inputnewpriceoftheticket::");scanf("%d",&p->data.price);word可自由復(fù)制編輯

printf("Inputnewnumberofpeoplewhohavebookedticket:");scanf("%d",&p->data.bookNum);printf("\nmodifyingrecordissucessful!\n");shoudsave=1;}elseprintf("\t\t\tcan'tfindtherecord!");}}elsemark1=0;}}/*系統(tǒng)給用戶的提信息*/voidAdvicedTrains(Linkl){Node*r;charstr[10];intmar=0;word可自由復(fù)制編輯

r=l->next;printf("Iuputthecityyouwanttogo:");scanf("%s",str);while(r){if(strcmp(r->data.city,str)==0&&r->data.bookNum<200){mar=1;printf("\nyoucanselectthefollowingtrain!\n");printf("\n\npleaseselectthefourthoperationtobooktheticket!\n");printTrainInfo(r);}r=r->next;}if(mar==0)printf("\n\t\t\tyoucan'tbookanyticketnow!\n");}/*保存火車信*/word可自由復(fù)制編輯

voidSaveTrainInfo(Linkl){FILE*fp;Node*p;intcount=0,flag=1;fp=fopen("c:\\train.txt","wb");if(fp==NULL){printf("thefilecan'tbeopened!");return;}p=l->next;while(p){if(fwrite(p,sizeof(Node),1,fp)==1){p=p->next;count++;}word可自由復(fù)制編輯

else{flag=0;break;}}if(flag){printf("thenumberoftherecordwhichhavebeensavedis%d\n",count);shoudsave=0;}fclose(fp);}/*保存訂票人的信*/voidSaveBookmanInfo(bookManLinkk){FILE*fp;bookMan*p;intcount=0,flag=1;word可自由復(fù)制編輯

fp=fopen("c:\\man.txt","wb");if(fp==NULL){printf("thefilecan'tbeopened!");return;}p=k->next;while(p){if(fwrite(p,sizeof(bookMan),1,fp)==1){p=p->next;count++;}else{flag=0;break;}word可自由復(fù)制編輯

}if(flag){printf("thenumberoftherecordwhichhavebeensavedis%d\n",count);shoudsave=0;}fclose(fp);}intmain(){FILE*fp1,*fp2;Node*p,*r;charch1,ch2;Linkl;bookManLinkk;bookMan*t,*h;intsel;l=(Node*)malloc(sizeof(Node));word可自由復(fù)制編輯

l->next=NULL;r=l;k=(bookMan*)malloc(sizeof(bookMan));k->next=NULL;h=k;fp1=fopen("c:\\train.txt","ab+");if((fp1==NULL)){printf("can'topenthefile!");return0;}while(!feof(fp1)){p=(Node*)malloc(sizeof(Node));if(fread(p,sizeof(Node),1,fp1)==1){p->next=NULL;r->next=p;r=p;word可自由復(fù)制編輯

count1++;}}fclose(fp1);fp2=fopen("c:\\man.txt","ab+");if((fp2==NULL)){printf("can'topenthefile!");return0;}while(!feof(fp2)){t=(bookMan*)malloc(sizeof(bookMan));if(fread(t,sizeof(bookMan),1,fp2)==1){t->next=NULL;h->next=t;h=t;word可自由復(fù)制編輯

count2++;}}fclose(fp2);while(1){clrscr();printInterface();printf("pleasechoosetheoperation:");scanf("%d",&sel);clrscr();if(sel==8){if(shoudsave==1){getchar();printf("\nthefilehavebeenchanged!doyouwanttosaveit(y/n)?\n");scanf("%c",&ch1);if(ch1=='y'||ch1=='Y')word可自由復(fù)制編輯

{SaveBookmanInfo(k);SaveTrainInfo(l);}}printf("\nThankyou!!Youarewelcometoo\n");break;}switch(sel){case1:InsertTraininfo(l);break;case2:QueryTrain(l);break;case3:BookTicket(l,k);break;case4:UpdateInfo(l);break;word可自由復(fù)制編輯

case5:AdvicedTrains(l);break;case6:SaveTrainInfo(l);SaveBookmanInfo(k);break;case7:return0;}printf("\npleasepressanykeytocontinue.......");getch();}return0;}3.2調(diào)試與測試主要程運(yùn)行結(jié)果:行開始word可自由復(fù)制編輯

選擇入信息選擇詢信息選擇票選擇用word可自由復(fù)制編輯

選擇你的建選擇出系統(tǒng)3.心得體會通過這次課

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論