![數(shù)據(jù)結(jié)構(gòu)訂票系統(tǒng)_第1頁](http://file4.renrendoc.com/view/d04f3819ca4448fb8aa6de39dd4b43f4/d04f3819ca4448fb8aa6de39dd4b43f41.gif)
![數(shù)據(jù)結(jié)構(gòu)訂票系統(tǒng)_第2頁](http://file4.renrendoc.com/view/d04f3819ca4448fb8aa6de39dd4b43f4/d04f3819ca4448fb8aa6de39dd4b43f42.gif)
![數(shù)據(jù)結(jié)構(gòu)訂票系統(tǒng)_第3頁](http://file4.renrendoc.com/view/d04f3819ca4448fb8aa6de39dd4b43f4/d04f3819ca4448fb8aa6de39dd4b43f43.gif)
![數(shù)據(jù)結(jié)構(gòu)訂票系統(tǒng)_第4頁](http://file4.renrendoc.com/view/d04f3819ca4448fb8aa6de39dd4b43f4/d04f3819ca4448fb8aa6de39dd4b43f44.gif)
![數(shù)據(jù)結(jié)構(gòu)訂票系統(tǒng)_第5頁](http://file4.renrendoc.com/view/d04f3819ca4448fb8aa6de39dd4b43f4/d04f3819ca4448fb8aa6de39dd4b43f45.gif)
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
荊楚理工學(xué)院《數(shù)據(jù)結(jié)構(gòu)》課程設(shè)計學(xué)院:計算機(jī)工程學(xué)院班級:計算機(jī)科學(xué)與技術(shù)(1)班學(xué)生姓名:????? 學(xué)號: 20094040101..設(shè)計地點(diǎn)(單位) 設(shè)計題目: 訂票系統(tǒng) 完成日期:2011年01月4日 指導(dǎo)教師評語: 成績(五級記分制): 教師簽名: TOC\o"1-5"\h\z\o"CurrentDocument"一、 需求分析 3\o"CurrentDocument"二、 算法流程圖 3\o"CurrentDocument"三、 詳細(xì)設(shè)計 4\o"CurrentDocument"四、 源程序 5\o"CurrentDocument"五、 程序測試 19\o"CurrentDocument"六、 心得體會 20、需求分析:通過此系統(tǒng)可以實(shí)現(xiàn)如下功能:1)錄入航線信息每條航線信息包括航班號、飛機(jī)號、目的地、訂票數(shù)、余票數(shù)共5項。假設(shè)現(xiàn)在有3條航線,目的地分別是北京,上海,廣州,飛機(jī)上可乘坐100人(即初始訂票數(shù)為0,余票數(shù)為100),將這3條航線信息存入文件“airline.dat”中。2) 訂票業(yè)務(wù)客戶信息包括姓名,航班號,座位號(初始為0),假設(shè)已有3個客戶信息存入文件“customer.dat”中。有新客戶訂票時,先輸入客戶的姓名和他提出的航班號,查詢該航線的訂票情況,若有余票,則為客戶辦理訂票手續(xù),分配給客戶一個座位號,然后將新客戶的信息添加到文件“customer.dat”中,并修改文件“airline.dat”中該航線的訂票數(shù)和余票數(shù)。若無余票,則輸出客滿信息。進(jìn)一步可實(shí)現(xiàn)如果該航班已經(jīng)無票,可以提供相關(guān)可選擇航班信息。3) 退票業(yè)務(wù)根據(jù)客戶提出的航班號,辦理退票,從文件“customer.dat”中刪除該客戶的信息,并修改文件“airline.dat”中相應(yīng)航線的訂票數(shù)和余票數(shù)。4) 修改航班信息:當(dāng)航班信息改變可以修改航班數(shù)據(jù)文件。5) 輸出全部航線信息和全部客戶信息。6) 退出系統(tǒng)。二、算法流程圖三、詳細(xì)設(shè)計:所需抽象數(shù)據(jù)類型定義和一些函數(shù)的聲明見設(shè)計概要。這里只解釋一下執(zhí)行函數(shù)和一些比較復(fù)雜一點(diǎn)的算法。航空訂票系統(tǒng):、執(zhí)行函數(shù):見voidair_main();、定票函數(shù):statusbook(airlineconst*l,char*line_num,customer*c,char*name)//訂票{//訂票airline*p=l;customer*q=c—〉next;p=l-〉next;for(;q-〉next!=NULL;q=q-〉next){}//PR("%s\n",q-〉name);for(;p!=NULL;p=p—>next){if(strcmp(line_num,p-〉line_num)==0){辻(p-〉left〉0){PR(〃恭喜您!訂票成功!\n〃);PR("你的座位號是:%d\n",(p-〉total-p-〉left+1));insert_customer(&q,name,line_num,p-〉total-p-〉left+1);p-〉left—;returnOK;}elsePR("對不起,座位已滿!\n");return0;}}PR(〃對不起,沒有這個航班號!\n〃);returnERROR;}定票的同時也同時了修改航線信息,并在修改后把修改后的信息儲存到文件中去。、退票函數(shù):statusdelete_cus(customer*h,airline*l,char*name){//顧客退票customer*p,*pr;charline_num[8];//qr=h;pr=h;p=pr—〉next;//PR(〃開始刪除\n〃);while(p!二NULL){if(strcmp(name,p-〉name)==0){strcpy(line_num,p-〉line_num);l二modefy_airline(l,line_num);pr—〉next二p—〉next;free(p);PR("顧客%s退票成功!\n",p-〉name);returnOK;}pr二pr—〉next;p=pr—〉next;}PR("無此顧客,無法退票!\n");returnERROR;}在此函數(shù)執(zhí)行后執(zhí)行顧客信息修改和航線信息修改。從而實(shí)現(xiàn)了退票功四、源程序:#include<stdio.h〉#include<string.h〉#include<stdlib.h〉#defineOK1#defineTRUE1#defineFALSE0#defineERROR0#defineOVERFLOW—2#definePRprintftypedefintstatus;typedefstructairline{charline_num[8];//航班號charplane_num[8];//飛機(jī)號charend_place[20];//目的的inttotal;//座位總數(shù)intleft;//剩余座位structairline*next;//下一個結(jié)點(diǎn)}airline;typedefstructcustomer{charname[9];//顧客名charline_num[8];//航班號intseat_num;//座位號structcustomer*next;//下一個結(jié)點(diǎn)}customer;airline*init_airline(){//初始化鏈表airline*l;l=(airline*)malloc(sizeof(airline));辻(l==NULL){exit(0);}l-〉next=NULL;returnl;}customer*init_customer(){//初始化鏈表customer*l;l=(customer*)malloc(sizeof(customer));辻(l==NULL){exit(0);}l-〉next=NULL;returnl;}statusinsert_airline(airline**p,char*line_num,char*plane_num,char*end_place,inttotal,intleft){//airline鏈表插入操作airline*q;q=(airline*)malloc(sizeof(airline));strcpy(q-〉line_num,line_num);strcpy(q-〉plane_num,plane_num);strcpy(q-〉end_place,end_place);q-〉total二total;q-〉left=left;q-〉next=NULL;(*p)->next二q;(*p)=(*p)-〉next;//PR("insert%d,%dissuccssed!\n",e,bl);returnOK;}statusinsert_customer(customer**p,char*name,char*line_num,intseat){//customer鏈表插入操作customer*q;q=(customer*)malloc(sizeof(customer));/*{PR(〃內(nèi)存分配失敗\n〃);returnOVERFLOW;}*/strcpy(q-〉name,name);strcpy(q-〉line_num,line_num);q—〉seat_num=seat;q-〉next=NULL;(*p)-〉next二q;(*p)=(*p)-〉next;// PR("insert%d,%dissuccssed!\n",e,bl);returnOK;}airline*modefy_airline(airline*l,char*line_num)//修改airline鏈表中的數(shù)據(jù){airline*p;p=l-〉next;for(;p!二NULL;p二p-〉next){if(strcmp(line_num,p-〉line_num)==0){p-〉left++;// PR("modefy%s\n",p-〉line_num);returnl;}}PR(〃沒有這個航班,無法完成修改任務(wù)!\n");return0;}statusdelete_airline(airline*h,char*line_num)//刪除航班{airline*p,*pr;pr=h;p=pr—〉next;while(p!二NULL){if(strcmp(line_num,p-〉line_num)==0){pr—〉next二p—〉nextPR("刪除%s航班\n",p-〉line_num);returnOK;}pr二pr—〉next;p=pr—〉next;}PR("無此航班,無法刪除!\n");returnERROR;}statusdelete_customer(customer*h,char*line_num)//刪除顧客{customer*p,*pr;pr=h;p=pr->next;while(p!二NULL){if(strcmp(line_num,p->line_num)==0){pr->next二p->next;}pr二pr—〉next;p=pr->next;}//PR("無此航班,無法刪除!\n");returnOK;}statusdelete_cus(customer*h,airline*l,char*name)//顧客退票{customer*p,*pr;charline_num[8];//qr=h;pr=h;p=pr—>next;//PR("開始刪除\n");while(p!=NULL){if(strcmp(name,p-〉name)==0){strcpy(line_num,p-〉line_num);l二modefy_airline(l,line_num);pr—>next二p—〉next;PR("顧客%s退票成功!\n",p-〉name);returnOK;}pr二pr—〉next;p=pr—〉next;}PR("無此顧客,無法退票!\n");returnERROR;}statussave_airline(airline*l)//保存airline.dat{FILE*fp_airline;charch二'#';airline*p=l->next;charfilename□二"c:\\airline.dat";if((fp_airline二fopen(filename,"wb"))==NULL){printf("cannotopenfiletowrite:%s\n",filename);returnERROR;}for(;p!=NULL;p=p->next){//printf("%s,%s,%s,%d,%d\n",p->line_num,p->plane_num,p->end_place,p->total,p->left);fprintf(fp_airline,"%s,%s,%s,%d,%d%c\n",p->line_num,p->plane_num,p->end_place,p->total,p->left,ch);}fclose(fp_airline);returnOK;}statussave_customer(customer*l)//保存顧客信息customer.dat{FILE*fp_customer;charch='#';customer*p=l->next;charfilename□二"c:\\customer.dat";if((fp_customer=fopen(filename,"wb"))==NULL){printf("cannotopenfiletowrite:%s\n",filename);returnERROR;for(;p!二NULL;p二p-〉next){// PR("%s,%s,%d\n",p-〉name,p-〉line_num,p-〉seat_num);fprintf(fp_customer,"%s,%s,%d%c",p-〉name,p-〉line_num,p-〉seat_num,ch);}fclose(fp_customer);returnOK;}intchangStrlnt(char*ch)//把字符串轉(zhuǎn)化為整型{inta=l,b=0,c=0,i;for(i=strlen(ch)T;i〉=O;i—){if(ch[i]〈58&&ch[i]〉47){b=a*(ch[i]-48);a=a*10;c=c+b;}else{PR("%c不合法,無法將此字符串轉(zhuǎn)化為整形!\n〃,ch[i]);return0;}//printf("thecis%d\n",c);}returnc;}statusinsert_air(airline*l,char*line_num,char*plane_num,char*end_place,inttotal,intleft){//airline鏈表插入操作airline*q;q=(airline*)malloc(sizeof(airline));strcpy(q-〉line_num,line_num);strcpy(q-〉plane_num,plane_num);strcpy(q-〉end_place,end_place);q-〉total二total;q-〉left=left;q->next=l—〉next;l-〉next=q;//PR("insert%d,%dissuccssed!\n",e,bl);returnOK;statusinsert_cus(customer*l,char*name,char*line_num,intseat){//customer鏈表插入操作customer*q;q=(customer*)malloc(sizeof(customer));strcpy(q-〉name,name);strcpy(q-〉line_num,line_num);q—〉seat_num=seat;q—〉next=l—〉next;l-〉next=q;returnOK;}statusload_airline(airline*l){FILE*fp_airline;intflag=0,i=0;charch;charline_num[8];//航班號charplane_num[8];//飛機(jī)號charend_place[20];//目的的chartotal_str[5];charleft_str[5];inttotal;//座位總數(shù)intleft;//剩余座位//airline*p=l;charfilename□二"c:\\airline.dat";if((fp_airline=fopen(filename,"rb"))==NULL){printf("cannotopenfiletoload:%s\n",filename);returnERROR;}while(!feof(fp_airline)){ch=fgetc(fp_airline);辻(ch!二'#'){辻(flag==0&&ch!=','){line_num[i]=ch;i++;}elseif(flag==1&&ch!=','){plane_num[i]二ch;i++;}elseif(flag==2&&ch!二',’){end_place[i]=ch;i++;}elseif(flag==3&&ch!=','){total_str[i]=ch;i++;}elseif(flag==4&&ch!=','){left_str[i]=ch;i++;}elseif(ch==',‘){flag++;i=0;}/*else{PR(〃錯誤\n〃);returnERROR;}*/}else{flag=0;i=0;total二changStrlnt(total_str);left=changStrlnt(left_str);PR("%8s%8s%8s%9d%9d\n",line_num,plane_num,end_place,total,left);insert_air(l,line_num,plane_num,end_place,total,left);}}fclose(fp_airline);returnOK;}statusload_customer(customer*l){FILE*fp_customer;intflag=0,i=0;charch;charname[9];charline_num[8];//航班號charseat_num_str[5];intseat_num;//座位//customer*p=*l;charfilename[50]="c:\\customer.dat";if((fp_customer二fopen(filename,"rb"))==NULL){printf("cannotopenfiletoload:%s\n",filename);returnERROR;}while(!feof(fp_customer)){ch=fgetc(fp_customer);printf("%c\n",ch);辻(ch!二'#'){辻(flag==0&&ch!=','){name[i]=ch;i++;}elseif(flag==1&&ch!=','){line_num[i]=ch;i++;}elseif(flag==2&&ch!=','){seat_num_str[i]=ch;i++;}elseif(ch==',‘){flag++;i=0;}else{PR(〃錯誤\n〃);returnERROR;}}else{flag=0;seat_num二changStrlnt(seat_num_str);PR(〃%10s %10s %d\n"',name,line_num,seat_num);insert_cus(l,name,line_num,seat_num);// p=p-〉next;}}fclose(fp_customer);returnOK;}statuscreat_airline(airline**l)//創(chuàng)建airline單鏈表{airline*p=*l;inti=0;char*line_num[3]={"bjnc01","bjsh02","shgz03"};char*plane_num[3]={"planel","plane2","plane3"};char*end_place[3]={"nc","sh","gz"};inttotal[3]={100,100,100};intleft[3]={51,50,78};for(i=0;i〈3;i++){insert_airline(&p,line_num[i],plane_num[i],end_place[i],total[i],left[i]);}returnOK;}statuscreat_customer(customer**l)////創(chuàng)建customer單鏈表{customer*p=*l;inti=0;char*name[3]={"wunan","liang","hekan"};char*line_num[3]={"bjnc01","bjsh02","shgz03"};intseat_num[3]={l,5,10};for(i=0;i〈3;i++){insert_customer(&p,name[i],line_num[i],seat_num[i]);}returnOK;}*end_place,intstatusincrease_air(airline*l,char*line_num,char*plane_num,chartotal)//增加航線*end_place,int{airline*p=l—〉next;for(;p-〉next!=NULL;p=p-〉next){}insert_airline(&p,line_num,plane_num,end_place,total,total);PR("增加航班%s成功!\n",line_num);returnOK;}statusbook(airline*l,char*line_num,customer*c,char*name)//訂票{airline*p=l;customer*q=c—>next;p=l—>next;for(;q—>next!=NULL;q=q-〉next){}//PR("%s\n",q-〉name);for(;p!=NULL;p=p—>next){if(strcmp(line_num,p-〉line_num)==0){辻(p-〉left〉0){PR(〃恭喜您!訂票成功!\n〃);PR("你的座位號是:%d\n",(p-〉total-p-〉left+1));insert_customer(&q,name,line_num,p-〉total-p-〉left+1);p-〉left—;returnOK;}elsePR("對不起,座位已滿!\n");return0;}}PR(〃對不起,沒有這個航班號!\n〃);returnERROR;}statusprint_airline(airline*l)//打印航線信息{airline*p=l—〉next;for(;p!二NULL;p二p-〉next){PR("%8s%8s%8s%9d%9d\n",p-〉line_num,p-〉plane_num,p-〉end_place,p-〉total,p-〉left);}returnOK;}statusprint_customer(customer*l)//打印顧客信息{customer*p=l—〉next;for(;p!=NULL;p=p->next){PR("%10s %10s %d\n",p-〉name,p-〉line_num,p-〉seat_num);}returnOK;}voidmain(){charchoice,choice2,name[9],line_num[8],password[9],plane_num[8],end_place[9];charpass[9]="wunan",re_pass_l[9],re_pass_2[9];intt=l,tt=l,total;airline*air=init_airline();customer*cus=init_customer();PR("數(shù)據(jù)結(jié)構(gòu)課程設(shè)計\n");PR(" 航空訂票系統(tǒng)\n");PR(" 石玉萍編寫時間:2011.01.04\n〃);PR(" 指導(dǎo)老師:李素若\n");creat_airline(&air);creat_customer(&cus);//save_airline(air);//save_customer(cus);while(t==l){PR("* *\n");PR("*—航空訂票系統(tǒng)選擇菜單 *\n");PR("*訂票一一—--0*\n")PR("*退票一一——1*\n")PR("*查詢一一——2*\n")PR("*修改航線---3*\n")PR("*讀入文件---4*\n")PR("*退出一一——5*\n")PR("* *\n");PR(〃請選擇:〃);choice=getch();PR("%c\n",choice);if(choice=='0'){PR(〃請輸入你要訂的航班號:〃);scanf("%s",line_num);PR(〃請輸入你的姓名:〃);scanf("%s",name);book(air,line_num,cus,name);save_airline(air);save_customer(cus);}elseif(choice=='1'){PR(〃\n請輸入你的姓名:〃);scanf("%s",name);delete_cus(cus,air,name);save_airline(air);save_customer(cus);}elseif(choice=='2'){PR("\n航班號飛機(jī)號目的地總票數(shù)余票數(shù)\n");print_airline(air);PR("姓名 航班號座位號\n");print_customer(cus);}elseif(choice=='3'){tt=1;PR(〃請輸入密碼:〃);scanf("%s",password);if(strcmp(password,pass)==0){while(tt==1){PR("\n**\n)PR("*——航線信息修改:一―*\n);PR("*增加航班號-—--'0'*\n");PR("*刪除航班號-—-'1'*\n");PR("*修改密碼 -'2'*\n");PR("*查詢航線信息---'3'*\n");PR("*退出航線修改---'4'*\n");PR("**\n);PR(〃請選擇:〃);choice2=getch();PR("%c\n",choice2);if(choice2=='0'){PR(〃請輸入你要增加的航班號:〃);scanf("%s",line_num);PR(〃請輸入飛機(jī)號:〃);scanf("%s",plane_num);PR(〃請輸入目的地:〃);scanf("%s",end_place);PR(〃請輸入座位總數(shù):〃);scanf("%d",&total);increase_air(air,line_num,plane_num,end_place,total);save_airline(air);save_customer(cus);}elseif(choice2=='l‘){PR(〃請輸入你要刪除的航班號:〃);scanf("%s",line_num);delete_airline(air,line_num);delete_customer(cus,line_num);save_airline(air);save_cust
溫馨提示
- 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)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- Trilysine-TFA-生命科學(xué)試劑-MCE-4187
- KIF18A-IN-15-生命科學(xué)試劑-MCE-5317
- 4-4-Dimethoxyoctafluorobiphenyl-生命科學(xué)試劑-MCE-5198
- 1-3-Dinervonoyl-glycerol-生命科學(xué)試劑-MCE-1243
- 2025年度特色民宿體驗住宿協(xié)議
- 二零二五年度消防設(shè)備定制設(shè)計與銷售合同
- 二零二五年度農(nóng)產(chǎn)品線上線下一體化購銷合同標(biāo)準(zhǔn)
- 施工現(xiàn)場施工防傳染病傳播制度
- 個人兼職用工合同模板
- 鄉(xiāng)村別墅租賃合同樣本
- 老師呀請你別生氣教學(xué)反思
- 2023年北京市平谷區(qū)中考英語二模試卷
- 變壓器更換施工方案
- 【高分復(fù)習(xí)筆記】陳澄《新編地理教學(xué)論》筆記和課后習(xí)題詳解
- 安徽新宸新材料有限公司年產(chǎn)6000噸鋰離子電池材料雙氟磺酰亞胺鋰項目環(huán)境影響報告書
- 日本酒類消費(fèi)行業(yè)市場分析報告
- GB/T 29594-2013可再分散性乳膠粉
- 西子奧的斯電梯ACD2調(diào)試說明書
- 成長感恩責(zé)任高中主題班會-課件
- 建設(shè)項目全過程工程咨詢服務(wù)指引(咨詢企業(yè)版)(征求意見稿)
- 分手的協(xié)議書模板(5篇)
評論
0/150
提交評論