C語言課程設計-民航訂票系統(tǒng).doc_第1頁
C語言課程設計-民航訂票系統(tǒng).doc_第2頁
C語言課程設計-民航訂票系統(tǒng).doc_第3頁
C語言課程設計-民航訂票系統(tǒng).doc_第4頁
C語言課程設計-民航訂票系統(tǒng).doc_第5頁
已閱讀5頁,還剩16頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

212013.12 中國地質大學C語言課程設計 第一章 實習報告1.1題目描述【要求】假定某民航機場共有n個航班。每個航班有一航班號、確定的航線(起始站、終點站)、確定的飛行時間(星期幾)和一定的成員訂額。試設計一民航訂票系統(tǒng),能提供下列服務。(1) 航班信息錄入功能(航班信息用文件保存)。(2) 航班信息瀏覽功能。(3) 查詢航線:(至少一種查詢方式)。按航班號查詢。按起點站查詢。按終點站查詢。按飛行時間查詢?!咎崾尽浚?) 需求分析航班信息用文件保存,因而要提供文件的輸入/輸出功能;要瀏覽航班信息,需要提供顯示功能;要查詢航線,需要提供查找功能;另外,還要提供鍵盤式選擇菜單以實現(xiàn)功能選擇。(2) 總體設計整個系統(tǒng)可以設計為航班信息輸入模塊、航班信息瀏覽模塊和航線查詢模塊。(3) 數(shù)據(jù)結構建立航班結構體,結構體成員包括航班號、起始站、終點站、飛行時間(星期幾)、預售票總數(shù)、已售票數(shù)。1.2算法設計根據(jù)需求分析,可以將這個系統(tǒng)的設計分為如下五大模塊:輸入航班信息,保存航班信息, 瀏覽航班信息,查找航班信息,退出。飛機訂票系統(tǒng)輸入航班信息保存航班信息瀏覽航班信息查找航班信息退出1.3程序設計及代碼分析1.結構體設計 建立航班結構體,結構體成員包括航班號,起點站,終點站,飛行時間(星期幾),預售票總數(shù)。 struct air int fir_num;char start20;char terminus20;char fir_time10;int count;sN; /*sN中每個數(shù)組元素依次對應一個航班信息*/注意 sN中的N為學生個數(shù), 程序中采用宏定義的方式, 可以隨時在源程序宏定義中改,本程序宏定義# define N 10000。2. 主函數(shù)流程圖顯示一系列功能選項輸入j 并判斷j 是否為0根據(jù)j 的值調用個功能模塊函數(shù)NY程序void main() int j ;printf(“-welcome to our scheduled flight manage system!-*n”);printf(“*n”);do printf(“1. Please input the scheduled flight informationnm” “2. Look through the scheduled flight informationnn ” “3. Search for the scheduled flight informationnn” “0. EXITnn”);printf(“*n”);printf(“NOTE: This system just support the fly information in the nearest week!nn”);printf(“Please choose one number during 0-3 then push enter: nn”);scanf(“%d”, &j );switch (j) case 1: input(); /*調用輸入模塊*/break; case 2: print(); /*調用打印模塊*/break;case 3: search(); /*調用查找模塊*/break; case 0: break; /*退出*/while(j!=0);printf(“Thank you for using our system!Goodbye!n”);3.各功能模塊設計3.1 輸入航班信息流程圖顯示提示信息并設置密碼讀取密碼驗證密碼是否正確N重新輸入密碼Yi =0i+依次讀取第si 班飛機的航班號, 起點站, 終點站,飛行時間, 機票數(shù)保存信息i NY退出N程序void input() char f=“20121000748”; /*設置密碼*/ int y; printf (“Please input the password then push Enter:nn”); scanf(“%s”,f); /*讀取密碼*/ if(strcmp(f,“20121000748”)= =0) printf(“Please input the flight information one by one(the number of the ticket should be ended by 0):nn”);printf(“*n”);for(i=0;iN;i+) printf(“Please input the flight number:n”); scanf(“%d”,&si.fir_num); /*讀取航班號*/ printf(“Please input the start place:n”); scanf(“%s”,si.start); /*讀取起點站*/ printf(“Please input the terminus:n”); scanf(“%s”,si.terminus); /*讀取終點站*/ printf(“Please input the time:n”); scanf(“%s”,si.fir_time); /*讀取時間*/ printf(“Please input the number of the ticket(the number of the ticket should be ended by 0:)n”,m); scanf(“%d”,&si.count); /*讀取機票數(shù)*/ m+; printf(“The %d group information have been inputted! Please push any key to continue, push 0 to the end”,m); scanf(“%d”,&y);if(y= =0) save(); /*將結構體存盤*/print(); /*輸入輸出航班信息*/break; else printf(“password error! Please check your password! Thank you! Goodbye!nn”);3.2 保存信息模塊流程圖打開文件判斷是否出錯定義文件指針返回YN向文件寫入數(shù)據(jù)關閉文件程序void save() FILE *fp, *fp1; /*定義文件指針*/ if(fp=fopen(“chen.dat”,”wb”)= =NULL) /*打開文件并判斷是否出錯*/ printf(“Fail to creat the file!nn”);getchar();return; if(fp1=fopen(“hao.dat”,”wb”)= =NULL) printf(“Fail to creat the file!nn”);getchar();return;for(i=0;im;i+) if(fwrite(&si,sizeof(struct air),1,fp)= =0) /*向文件寫入數(shù)據(jù)并判斷是否出錯*/ printf(“Fail to input data to the file!nn”); fprintf(fp1,”%d”,m); fclose(fp); /*關閉文件*/ fclose(fp1);3.3瀏覽信息模塊流程圖定義文件指針打開文件判斷是否出錯退出YN從文件中讀取信息關閉文件打印信息程序void read() FILE *fp, *fp1; /*定義文件指針*/if(fp=fopen(“chen.dat”,”rb”)= =NULL) /*打開文件判斷是否出錯*/ printf(“ Error please make sure the file is exist! Push any key back to the menu”); getchar();if(fp1=fopen(“hao.dat”,”rb”)= =NULL) /*打開文件判斷是否出錯*/ printf(“Fail to creat the file!nn”);getchar(); return; fscanf(fp1,”%d”,&m); fclose(fp1); for(i=0;im;i+) fread(&si,sizeof(s),1,fp); /*從文件中讀取信息*/ fclose(fp); /*關閉文件*/ void print() /*打印模塊*/ char w10; read(); /*調用讀文件函數(shù)*/ printf(“FlightNumber StartPlace Terminus Time TicketNumbern”); for(i=0;im;i+) printf(PRINT); /*打印信息*/ printf(“Please push any key back to the up menu:n”); scanf(“%s”,w);3.4 查詢信息模塊流程圖顯示查詢方式菜單選擇查找方式輸入要求信息顯示查詢結果是否繼續(xù)查找退出NY程序void search() char name120; char name220; char ii10; char time10; int n,no;do printf(Please choose one way you want to search:nn); /*打印查詢方式菜單*/ printf(1.According to the flight numbernn 2.According to the Terminusnn 3.According to the start placenn 4.According to the flying timenn 0.BACKnn); printf(Please choose one number during 0-3:nn Push any other key back to the top menu:nn); scanf(%d,&n); /*讀取查找方式*/ if(n= =0) break; switch(n) case 1: printf(Please input the flight number:n); scanf(%d,&no); /*航班號*/ break; case 2: printf(Please input the terminus :n); scanf(%s,name2); /*讀取終點站*/ break; case 3: printf(Please input the start place:n); scanf(%s,name1); /*讀取起點站*/ break; case 4: printf(Please input the flying time:n); scanf(%s,time); break; read(); /*調用讀取函數(shù)*/ for(i=0;im;i+) if(strcmp(si.start,name1)=0|strcmp(si.terminus,name2)=0)/*按終點站起始站判斷輸出條件*/ printf(nSucceed in searching for the flight information!n); printf(FlightNumber StartPlace Terminus Time TicketNumbern); printf(PRINT); /*打印信息*/ if(si.fir_num= =no) /*按航班號判斷輸出條件*/ printf(nSucceed in searching for the flight information!n); printf(FlightNumber StartPlace Terminus Time TicketNumbern); printf(PRINT); if(strcmp(si.fir_time,time)= =0) printf(nSucceed in searching for the flight information!n); printf(FlightNumber StartPlace Terminus Time TicketNumbern); printf(PRINT); /*打印信息*/ printf(Can not find the informtiong you wanted or you have done it:nn Do you want to continue?Please input YES or NO and push enter n);scanf(%s,ii);while(strcmp(ii,yes)=0); 1.4實驗數(shù)據(jù)及運行效果截圖1.輸入數(shù)據(jù)管理員輸入航班信息:航班號 起點站 終點站 飛行時間 總票數(shù)100 quzhou wuhan 9.1 100101 quzhou wuhan 9.2 150102 wuhan quzhou 9.1 130103 beijing wuhan 9.2 100 2.編譯,連接和運行3.結果3.1 主菜單函數(shù)3.2 輸入信息模塊3.3瀏覽信息模塊3.4查詢信息模塊3.4.1 按照航班號查詢3.4.2 按照終點站查詢3.4.3 按照起點站查詢3.4.4 按照時間查詢3.4.5 結束1.5設計中出現(xiàn)的錯誤及解決方法我在程序的設計中遇到了諸如中英輸入法錯誤、標點符號錯誤等錯誤,同時在函數(shù)調用處多次出錯,很感謝馬釗老師、殷商珉珉同學和李洋同學的指導,讓我學會用模塊化的方式處理相關問題。當然,那些錯誤在編譯過程

溫馨提示

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

評論

0/150

提交評論