數(shù)據結構課程設計(旅游管理系統(tǒng))_第1頁
數(shù)據結構課程設計(旅游管理系統(tǒng))_第2頁
數(shù)據結構課程設計(旅游管理系統(tǒng))_第3頁
數(shù)據結構課程設計(旅游管理系統(tǒng))_第4頁
數(shù)據結構課程設計(旅游管理系統(tǒng))_第5頁
已閱讀5頁,還剩27頁未讀, 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

1、 課 程 設 計 -數(shù)據結構課程設計報告 學 號 : 1016020203 姓 名 : 張 燦 指導教師 : 曹春萍 專 業(yè) : 計算機 完成日期 : 2012.06.25 目 錄 A篇:旅游信息管理系統(tǒng)1、 題目要求 1、題目內容-12、 程序設計目標 1、題目分析-1 2、功能簡介-2 3、數(shù)據結構-23、 概要簡述 1、功能結構圖-3 2、模塊分析-34、 詳細設計 1、結構體定義-3 2、程序流程圖 -55、 源程序代碼 1、源程序c+實現(xiàn)代碼-66、 調試分析及測試結果 1、運行結果截-147、 附錄 1、補充說明-198、 程序小結 1、報告總結19 B篇: B-樹手工題1、 題目

2、要求 1、題目內容-202、 運行過程 1、從空樹插入-20 2、插入完成-25 3、依次刪除要求點-26 4、最終結果-28 C篇:附加題1、 題目 1、題目內容292、 程序設計目標 1、功能簡介29 2、數(shù)據結構293、 設計思路 1、結構體定義29 2、功能結構圖30 3、程序流程圖304、 實現(xiàn)代碼 1、程序代碼325、 程序調試以及運行結果 1、調試結果及截圖436、 報告總結 1、報告總結44 27 A篇:旅游信息管理系統(tǒng)1、 題目要求1、 題目內容 旅游信息管理系統(tǒng) 1)數(shù)據結構 (1)、二叉排序樹加單鏈表 (2)、二叉排序樹 說明:1、用二叉排序樹表示旅游地點,用單鏈表表示游

3、客。 2、用二叉排序樹表示旅游地點和游客。 2)、功能 (1)、旅游地點的插入 (2)、游客報名 (3)、當某地的旅游人數(shù)少于三個人時,取消次旅游地,建議游客該選其他旅游點 (4)、當某旅游地旅游人數(shù)等于六個時,不允許在報名。 建議游客改選其它旅游地。 2、 程序設計目標 1、題目分析 讀題可知,需完成兩方面的編程以對旅游系統(tǒng)進行操作。一方面是旅游公司管理人員,主要是旅游景點的添加與刪除,對旅游人員的錄入與刪除,對旅游人數(shù)的統(tǒng)計,把游客所需信息打印等等;第二方面是游客對于旅游地的選、改、刪,以及個人信息的輸入、確認等等。 2、功能簡介 由以上分析可得:本設計程序功能主要有: 、 旅游公司管理人

4、員對旅游人員和旅游地點的操作,用二叉排序樹管理旅游地點。主要有地點的變更,插入、刪除、游客的信息存儲及及時提醒等功能。其中二叉樹每一個結點包括旅游地點的區(qū)號(area_node)、名稱(area)、該旅游地的游客人數(shù)(count)、以及一個指向游客信息結構的指針(list),還有二叉樹結點的左孩子和右孩子指針(lchild,rchild)。 、 游客可以登陸旅游公司界面進行報名、選擇旅游地點和輸入個人信息。游客結構采用單鏈表,其中包括單鏈表的初始化、插入、刪除、計數(shù)功能。其中每一個單鏈表結點包括游客的編號(id)、姓名(name)、性別(sex)、和鏈接鏈表的指針(next)。 3、數(shù)據結構用

5、到的數(shù)據結構有:單鏈表,排序二叉樹,數(shù)組。3、 概要簡述 1、功能結構圖 主 菜 單 程序員 游客刪除遍歷插入遍歷插入 二叉樹單鏈表 2、模塊分析工作去選擇模塊 本程序包括三個模塊:主程序模塊、二叉排序樹模塊、單鏈表模塊,工作區(qū)選擇模塊。如圖: 二叉排序樹模塊 主程序模塊 單鏈表模塊 4、 詳細設計 1、結構體定義 1)、鏈表結點結構體typedef struct touriststring name;int id;string sex;struct tourist *next;Trist,*linklist;左孩子 區(qū)號 地名 游客數(shù) 右孩子 指向鏈表的指針 2)、二叉排序樹結點結構體typ

6、edef struct Tree_Placeint area_code; /旅游地區(qū)號string area; /旅游地名稱int count; /記錄該旅游地報名游客人數(shù)struct Tree_Place *lchild,*rchild; Trist *list; /指向游客所在單鏈表的指針 Place,*TPlace; 左孩子 區(qū)號 地名 游客數(shù) 右孩子 指向鏈表的指針2、程序流程圖 主 菜 單(1、程序員,2、游客) 1 輸入密碼 錯誤 正確 (12345) 2 程序管理員 游 客退出顯示少于3人地查詢各地游客數(shù)目輸入地點退出輸入旅游地區(qū)號顯示所有旅游地查詢可報名地修改旅游地點刪除超額可

7、報提醒刪除打印退出 輸入退出可報地輸入信息重復 提醒 成功退/輸 Y N 報名成功 N打印個人信息 Y 5、 源程序代碼 1、源程序c+實現(xiàn)代碼#include<iostream>#include<stdlib.h>#include<string>#include<iomanip>using namespace std;#define MAX 50#define SIZE 12typedef struct tourist char nameSIZE; int id; char sex5; struct tourist *next;Trist,*l

8、inklist;typedef struct Tree_Place int code; /旅游地區(qū)號 char areaSIZE; /旅游地名稱 int count; /記錄該旅游地報名游客人數(shù) struct Tree_Place *lchild,*rchild; Trist *list; /指向游客所在單鏈表的指針 Place,*TPlace;void Search_T(TPlace &tree,int co);void Mainlist(TPlace &tree);void Tour_1(TPlace &tree);void Tour_2(TPlace &t

9、ree);void Destory(TPlace &tree);void Init_L(linklist &head) head=NULL;void Insert_L (TPlace &tree,TPlace &t,linklist &head) linklist tr; char c; int i=1,co,id; while(t->count<6&&i=1) cout<<"請輸入你的身份證號:"<<endl; cin>>id; tr=(linklist)malloc(

10、sizeof(Trist); tr->id =id; cout<<"輸入姓名,性別:"<<endl; cin>>tr->name>>tr->sex; tr->next=head; head=tr;t->count+; cout<<"繼續(xù)報名請按1,按0退出!"<<endl; cin>>i; if(t->count>=6) cout<<"此旅游地人數(shù)已滿,按'y'選擇其他旅游地,其他鍵退出!&q

11、uot;<<endl;cin>>c; if(c='y'|c='Y') cout<<"請重新輸入區(qū)號"<<endl;cin>>co;Search_T(tree,co); else Tour_2(tree);void Delet_L (linklist &head) linklist p,pro; pro=head; while(pro) p=pro ;pro=p->next ;free(p); void Insert_T(TPlace &tree,TPlace p

12、) /在二叉排序樹中插入一個新結點 if (tree=NULL) tree=p; else if(p->code<tree->code) Insert_T(tree->lchild,p); else if(p->code>tree->code) Insert_T(tree->rchild,p);void Search_T(TPlace &tree,int co) char c; TPlace p; int code; p=tree; while(p&&p->code!=co ) if(p->code>co

13、) p=p->lchild ; else p=p->rchild ; if(!p) cout<<"此旅游地點還未存在!"<<endl;system("pause");Tour_2(tree); else if(p->count>=6) cout<<"此旅游地人數(shù)已滿,按'y'選擇其他旅游地,其他鍵退出!"<<endl;cin>>c; if(c='y'|c='Y') cout<<"請重

14、新輸入區(qū)號"<<endl;cin>>code;Search_T(tree,code);else Tour_2(tree); else cout<<"可以報名"<<endl;Insert_L(tree,p, p->list);Tour_2(tree);TPlace Delete_T(TPlace &t,int co) TPlace p,parent,s,q;/parent指向要刪除的節(jié)點的雙親,p指向要刪除的節(jié)點 p=t; parent=NULL; while(p) if(p->code=co) b

15、reak; parent=p; if(p->code>co) p=p->lchild; else p=p->rchild; if(p=NULL) /不存在該樹節(jié)點 return t; if(p->lchild=NULL) /無左子樹,右子樹可有可無 if(parent=NULL) t=p->rchild; else if(parent->lchild=p) parent->lchild=p->rchild; else parent->rchild=p->rchild; Delet_L (p->list); free(p);

16、 else /有左子樹,右子樹可有可無 q=p; s=q->lchild; / while(s->rchild) q=s; s=s->rchild; if(q=p) /其左孩子沒有右子樹 q->lchild=s->lchild; else q->rchild=s->lchild; p->code=s->code; Delet_L (s->list); free(s); return t; void Fun1(TPlace &tree) char c; int n; TPlace p; cout<<"請輸入

17、插入地點個數(shù):"<<endl; cin>>n; cout<<"依次輸入各個旅游地點的區(qū)號和地名:"<<endl; for(int i=0;i<n;i+) p=(TPlace)malloc(sizeof(Place); cout<<"請輸入第"<<i+1<<"個地點:"<<endl; cin>>p->code>>p->area ; p->lchild =p->rchild =NU

18、LL; p->list=NULL; p->count =0; Insert_T(tree,p); cout<<"輸入完成,輸入y或者Y繼續(xù)操作,其他鍵退出!" cin>>c; if(c='y'|c='Y') Fun1(tree); else system("cls");Tour_1(tree);void Fun2(TPlace &tree,int x) int top=0; TPlace p,sMAX; p=tree; while(p|top>0) while(p) sto

19、p+=p; p=p->lchild; if(top>0) p=s-top;cout<<setw(8)<<"區(qū)號:"<<p->code<<setw(10)<<"地名:"<<p->area<<setw(10)<<"人數(shù):"<<p->count<<endl; p=p->rchild; if(tree=NULL)cout<<"還未錄入旅游地!請稍后查詢!"&

20、lt;<endl; cout<<"按任意鍵返回上一級菜單!"<<endl; system("pause");if(x=1)Tour_1(tree);if(x=2) Tour_2(tree);void Fun3(TPlace &tree,int x) int n1=0,n2=0; char c; int top=0; int elemMAX; TPlace p,sMAX; p=tree; while(p|top>0) while(p) stop+=p; p=p->lchild; if(top>0) p

21、=s-top; if(p->count<3&&x=1) cout<<setw(8)<<"區(qū)號:"<<p->code<<setw(10)<<"地名:"<<p->area<<setw(10)<<"人數(shù):"<<p->count<<endl;elemn1=p->code ;n1+; if(p->count<6&&x=2) cout<<

22、setw(8)<<"區(qū)號:"<<p->code<<setw(10)<<"地名:"<<p->area<<setw(10)<<"人數(shù):"<<p->count<<endl;n2+; p=p->rchild; if(x=1)cout<<"一共有"<<n1<<"各旅游景點人數(shù)少于三個"<<endl;cout<<&qu

23、ot;刪除旅游地請輸入D或者d,其他鍵返回菜單!"<<endl;cin>>c; if(c='d'|c='D') for(int i=0;i<n1;i+) Delete_T(tree,elemi);cout<<"刪除完成!"<<endl; system("pause");Tour_1(tree); if(x=2)cout<<"一共有"<<n2<<"個旅游景點仍可報名"<<en

24、dl;cout<<"按任意鍵返回上一級菜單!"<<endl;system("pause");Tour_2(tree); void Fun4(TPlace &tree) int co,id;TPlace p; linklist l,pre; p=tree; cout<<"輸入要退出旅游地的區(qū)號和自己的身份證號:"<<endl; cin>>co>>id; while(p&&p->code!=co ) if(p->code>co

25、) p=p->lchild ; else p=p->rchild ; if(!p) cout<<"此旅游地點還未存在!"<<endl;system("pause");Tour_2(tree); else l=p->list;pre=l; while(l->id!=id) pre=l; l=l->next; pre->next=l->next;free(l);p->count-;cout<<"輸入要報名的地點區(qū)號:"<<endl;cin>

26、;>co;Search_T(tree,co); void Mainlist(TPlace &tree) system("cls"); cout<<" *"<<endl<<endl; cout<<" 歡迎登陸旅游購票系統(tǒng)"<<endl; cout<<" 請選擇登錄身份:"<<endl; cout<<" 1、旅游公司管理人員"<<endl; cout<<"

27、2、游客"<<endl; cout<<" 3、退出 程序"<<endl; cout<<" *"<<endl<<endl; int n,key,i=1; cin>>n; switch(n) case 3: Destory(tree);exit(0); case 1: docout<<"請輸入登陸密碼:"cin>>key;i+; while(key!=12345&&i<=3); if(key=1234

28、5) Tour_1(tree);else Mainlist(tree);break; case 2: Tour_2(tree);break; default :cout<<"輸入錯誤,請重新選擇!"<<endl;system("pause"); Mainlist(tree); void Tour_1(TPlace &tree) system("cls"); int n; cout<<" *"<<endl<<endl; cout<<&qu

29、ot; 1、輸入旅游地點 "<<endl; cout<<" 2、查詢各旅游地游客人數(shù)"<<endl; cout<<" 3、顯示不足三人的旅游地"<<endl; cout<<" 4、退出"<<endl; cout<<" *"<<endl<<endl; cin>>n; switch(n) case 1: Fun1(tree);break; case 2: Fun2(tree,1)

30、;break; case 3: Fun3(tree,1);break; case 4: Mainlist(tree);break; default :cout<<"輸入錯誤,請重新輸入!"<<endl;system("pause");Tour_1(tree); void Tour_2(TPlace &tree) int code; system("cls"); int n; cout<<" *"<<endl<<endl; cout<<&

31、quot; 1、輸入旅游地區(qū)號 "<<endl; cout<<" 2、顯示所有旅游地"<<endl; cout<<" 3、查詢可報名地"<<endl; cout<<" 4、修改旅游地點"<<endl; cout<<" 5、退出"<<endl; cout<<" *"<<endl<<endl; cin>>n; switch(n) cas

32、e 1: cout<<"請輸入區(qū)號:"<<endl;cin>>code;Search_T(tree,code);break; case 2: Fun2(tree,2);break; case 3: Fun3(tree,2);break; case 4: Fun4(tree);break; case 5:Mainlist(tree);break; default :cout<<"輸入錯誤,請重新輸入!"<<endl;system("pause");Tour_2(tree); /

33、銷毀二叉樹void Destory(TPlace &tree)if(!tree) cout<<"此樹已空!"<<endl;system("pause"); exit(0);if(tree&&tree->lchild)Destory(tree->lchild);if(tree&&tree->rchild)Destory(tree->rchild);cout<<setw(5)<<tree->code<<setw(5)<<tree->area<<endl; Delet_L (tree->list);free(tree);void main() TPlace T=NULL; Mainlist(T);六、調試分析及測試結果 1、運行結果截圖七、附錄 1、補充說明 #include<

溫馨提示

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

評論

0/150

提交評論