飛機(jī)訂票系統(tǒng)實(shí)驗(yàn)報(bào)告_第1頁(yè)
飛機(jī)訂票系統(tǒng)實(shí)驗(yàn)報(bào)告_第2頁(yè)
飛機(jī)訂票系統(tǒng)實(shí)驗(yàn)報(bào)告_第3頁(yè)
飛機(jī)訂票系統(tǒng)實(shí)驗(yàn)報(bào)告_第4頁(yè)
飛機(jī)訂票系統(tǒng)實(shí)驗(yàn)報(bào)告_第5頁(yè)
已閱讀5頁(yè),還剩11頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡(jiǎn)介

成績(jī):課程設(shè)計(jì)課程名稱(chēng):數(shù)據(jù)結(jié)構(gòu)實(shí)驗(yàn)項(xiàng)目:飛機(jī)訂票系統(tǒng)姓名:專(zhuān)業(yè):班級(jí):學(xué)號(hào):計(jì)算機(jī)科學(xué)與技術(shù)學(xué)院月日一、 實(shí)驗(yàn)?zāi)康模毫私獠⒄莆諗?shù)據(jù)結(jié)構(gòu)與算法的設(shè)計(jì)方法,具備初步的獨(dú)立分析和設(shè)計(jì)能力;初步掌握軟件開(kāi)發(fā)過(guò)程的問(wèn)題分析、系統(tǒng)設(shè)計(jì)、程序編碼、測(cè)試等基本方法和技能;提高綜合運(yùn)用所學(xué)的理論知識(shí)和方法獨(dú)立分析和解決問(wèn)題的能力;二、 實(shí)驗(yàn)內(nèi)容(1) 本系統(tǒng)實(shí)現(xiàn)航班訂票的功能。要求具有錄入、訂票、退票等功能。(2) 航班信息存放在一個(gè)結(jié)構(gòu)體中,分別有航班號(hào)、起飛時(shí)間、降落時(shí)間、票價(jià)等信息。(3) 程序完成航班信息的錄入和乘客訂票功能。(4) 客戶(hù)能通過(guò)航班號(hào)或抵達(dá)城市查詢(xún)航班信息,并且能訂票。當(dāng)座位無(wú)剩余時(shí)提示客戶(hù)并提示相關(guān)航線(xiàn)。三.概要設(shè)計(jì)程序包含函數(shù):功能函數(shù)訂票book(air,linenum,cus,name)退票deletecus(cus,air,name)查詢(xún)printairline(air);修改航線(xiàn)inputpassword(password);增加航班號(hào)increaseair(air,linenum,planenum,endplace,total);刪除航班號(hào)delete_airline(air,line_num);deletecustomer(cus,linenum);查詢(xún)航線(xiàn)信息printairline(air)讀入文件loadairline(air);主控模塊包含子模塊為:圖3-1航班訂票子系統(tǒng)

四.詳細(xì)設(shè)計(jì)算法流程圖系統(tǒng)以菜單方式工作;航班訂票功能航班退票功能查詢(xún)航線(xiàn):(至少一種查詢(xún)方式)一一算法;菜單TOC\o"1-5"\h\z修改航線(xiàn) L—|一^增加航班號(hào) V__刪除航班號(hào) 增加航線(xiàn)信息修改密碼 查詢(xún)航班信息 *~~退票 查詢(xún)按終點(diǎn)站查詢(xún)。 訂票退票 查詢(xún)程序截圖c:Q*E:\_Sebug\Cpp4.exe*Tt輸入菜單號(hào)伯-5>:1請(qǐng)輸入你要訂的航班號(hào):a001請(qǐng)輸入你的姓名:£2對(duì)不起■沒(méi)有這個(gè)航班號(hào)辛K"E二l源程序\Debu.E\.ds.eze加除改詢(xún)出福修查退起線(xiàn)信班號(hào)班導(dǎo) 息修改:10f*?-?-線(xiàn)修改一-J4JbJncOlbjsh02shsrz@3r001planetplanedplane3rs航班號(hào)飛機(jī)號(hào)目的地nc 100sli 100gz 100sh 67總票數(shù)余票數(shù)51507867M-借改詢(xún)出盡修杳_退脈線(xiàn)信息倏改已班守‘0’*班■尋W?碼 ‘卽?線(xiàn)信息一-fr?寒修改一-F*請(qǐng)輸入你要増加的航班號(hào)F001請(qǐng)輸入飛機(jī)號(hào):f901請(qǐng)輸入目的地:*請(qǐng)輸入座位總數(shù):54增加航班^091成功甲”請(qǐng)輸入菜單號(hào)<0-5>:i請(qǐng)輸入你要訂的航班號(hào),P001請(qǐng)輸入你的姓容;tex蘋(píng)喜您?訂票成功?命馬產(chǎn)位號(hào)是:2五.源代碼#include<conio.h>#include<stdio.h>#include<string.h>#include<stdlib.h>#defineOK1#defineTRUE1#defineFALSE0#defineERROR0#defineOVERFLOW-2#definePRprintftypedefintstatus;typedefstructairline{charline_num[8];//航班號(hào)charplane_num[8];//飛機(jī)號(hào)charend_place[20];//目的的inttotal;//座位總數(shù)intleft;//剩余座位structairline*next;//下一個(gè)結(jié)點(diǎn)}airline;typedefstructcustomer{charname[9];//顧客名charline_num[8];//航班號(hào)intseat_num;//座位號(hào)structcustomer*next;//下一個(gè)結(jié)點(diǎn)}customer;airline*init_airline(){//初始化鏈表airline*l;l=(airline*)malloc(sizeof(airline));if(l==NULL){exit(0);}l->next=NULL;returnl;}customer*init_customer(){//初始化鏈表customer*l;l=(customer*)malloc(sizeof(customer));if(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("\n\t\t沒(méi)有這個(gè)航班,無(wú)法完成修改任務(wù)!〃);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->next;PR("\n\t\t刪除%s航班\n",p->line_num);returnOK;}pr=pr->next;p=pr->next;}PR("\n\t\t無(wú)此航班,無(wú)法刪除!\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("無(wú)此航班,無(wú)法刪除!\n〃);returnOK;}statusdelete_cus(customer*h,airline*l,char*name)//顧客退票{customer*p,*pr;charline_num[8];//qr=h;pr=h;p=pr->next;//PR(〃開(kāi)始刪除\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("\n\t\t顧客%s退票成功!〃,p->name);returnOK;}pr=pr->next;p=pr->next;}PR("\n\t\t無(wú)此顧客,無(wú)法退票!\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=1,b=0,c=0,i;for(i=strlen(ch)-1;i>=0;i--){if(ch[i]<58&&ch[i]>47){b=a*(ch[i]-48);a=a*10;c=c+b;}else{PR(〃\n\t\t%c不合法,無(wú)法將此字符串轉(zhuǎ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];//航班號(hào)charplane_num[8];//飛機(jī)號(hào)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);if(ch!='#'){if(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(〃錯(cuò)誤\n〃);returnERROR;}*/}else{flag=0;i=0;total=changStrInt(total_str);left=changStrInt(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];//航班號(hào)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);if(ch!='#'){if(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(〃錯(cuò)誤\n〃);returnERROR;}}else{flag=0;seat_num=changStrInt(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]={〃plane1〃,〃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]={〃ouyangj0〃,〃yhl〃,〃fs〃};char*line_num[3]={〃bjnc01〃,〃bjsh02〃,〃shgz03〃};intseat_num[3]={1,5,10};for(i=0;i<3;i++){insert_customer(&p,name[i],line_num[i],seat_num[i]);}returnOK;}statusincrease_air(airline*l,char*line_num,char*plane_num,char*end_place,inttotal)//增加航線(xiàn){airline*p=l->next;for(;p->next!=NULL;p=p->next){}insert_airline(&p,line_num,plane_num,end_place,total,total);PR("\n\t\t增加航班%s成功!",line_num);returnOK;}statusbook(airline*l,char*line_num,customer*c,char*name)//訂票函數(shù){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){if(p->left>0){PR(〃\n\t\t恭喜您!訂票成功!〃);PR("\n\t\t你的座位號(hào)是:%d〃,(p->total-p->left+1));insert_customer(&q,name,line_num,p->total-p->left+1);p->left--;returnOK;}elsePR("\n\t\t對(duì)不起,座位已滿(mǎn)!〃);return0;}}PR("\n\t\t對(duì)不起,沒(méi)有這個(gè)航班號(hào)!〃);returnERROR;}statusprint_airline(airline*l)//打印航線(xiàn)信息{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;}statusinputpassword(charcc[9])//隱藏密碼為*號(hào)的函數(shù) 樓主,Iqrl■注意這里!{charc;inti;for(i=0;c=getch();i++){if(c==13)break;/*13是回車(chē)的ascii碼,用'\n'不行,不知怎么回事*/else{cc[i]=c;printf("*");}}cc[i]='\0';//printf("\n");//printf("%s",cc);//getchar();returnstrlen(cc);}intmain()char{charchoice,choice2,name[9],line_num[8],password[9],plane_num[8],end_place[9];charpass[9]="12345678",re_pass_1[9],re_pass_2[9];intt=1,tt=1,total;airline*air=init_airline();customer*cus=init_customer();creat_airline(&air);creat_customer(&cus);//save_airline(air);//save_customer(cus);while(t==1){PR("\n\t\t********************************");PR(〃\n\t\t歡迎進(jìn)入航班訂票系統(tǒng)〃);PR(〃\n\t\t*1 訂票*〃)PR(〃\n\t\t*2 退票*〃)PR(〃\n\t\t*3 查詢(xún)*〃)PR(〃\n\t\t*4 修改航線(xiàn)*〃)PR(〃\n\t\t*5 讀入文件*〃)PR(〃\n\t\t*0 返回*〃)PR("\n\t\t********************************");PR(〃\n\t\t*請(qǐng)輸入菜單號(hào)(0-5):〃);choice=getch();PR(〃%c\n〃,choice);if(choice=='1'){PR("\n\t\t請(qǐng)輸入你要訂的航班號(hào):〃);scanf(〃%s〃,line_num);PR("\n\t\t請(qǐng)輸入你的姓名:〃);scanf(〃%s〃,name);book(air,line_num,cus,name);save_airline(air);save_customer(cus);}elseif(choice=='2'){PR(〃\n\t\t請(qǐng)輸入你的姓名:〃);scanf("%s",name);delete_cus(cus,air,name);save_airline(air);save_customer(cus);}elseif(choice=='3'){PR("\n航班號(hào)飛機(jī)號(hào)目的地總票數(shù)余票數(shù)\n");print_airline(air);PR("姓名航班號(hào)座位號(hào)\n");print_customer(cus);}elseif(choice=='4'){tt=1;PR("請(qǐng)輸入密碼:〃);//scanf(〃%s〃,password);inputpassword(password);if(strcmp(password,pass)==0){while(tt==1){PR(〃\n\t\t********************************〃);PR(〃\n\t\t* 航線(xiàn)信息修改: *〃);PR("\n\t\t*增加航班號(hào)——'0'*");PR("\n\t\t*刪除航班號(hào)——'1'*");PR("\n\t\t*修改密碼 '2'*");PR("\n\t\t*查詢(xún)航線(xiàn)信息

溫馨提示

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

評(píng)論

0/150

提交評(píng)論