列車時刻查詢系統(tǒng)設(shè)計(jì)--C++課程設(shè)計(jì)報(bào)告_第1頁
列車時刻查詢系統(tǒng)設(shè)計(jì)--C++課程設(shè)計(jì)報(bào)告_第2頁
列車時刻查詢系統(tǒng)設(shè)計(jì)--C++課程設(shè)計(jì)報(bào)告_第3頁
列車時刻查詢系統(tǒng)設(shè)計(jì)--C++課程設(shè)計(jì)報(bào)告_第4頁
列車時刻查詢系統(tǒng)設(shè)計(jì)--C++課程設(shè)計(jì)報(bào)告_第5頁
已閱讀5頁,還剩17頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡介

1、.C+課程設(shè)計(jì)報(bào)告課程設(shè)計(jì)題目:列車時刻查詢系統(tǒng)學(xué)生姓名 : 專 業(yè):軟件工程系班 級 : 指導(dǎo)教師 : 2009年6月25日一、 問題分析:i) 具有不同類型的列車類的描述 建立了Train類,利用繼承與派生建立派生類Ttrain(特快列車)類、Ztrain(直達(dá)特快列車)類、Dtrain(動車組)類、Ktrain(快速列車)類ii) 有列表時刻表類的描述 利用鏈表模板類來實(shí)現(xiàn)列車時刻表的存儲,將整個程序運(yùn)行過程中用戶輸入的所有列車信息存儲到鏈表中,以便用戶查詢。iii) 能完成時刻表的輸入、查詢、保存等功能利用鏈表模板存儲信息,調(diào)用函數(shù)對鏈表進(jìn)行處理完成輸入、查詢等功能。利用文件的來實(shí)現(xiàn)列

2、車信息的長久存儲,將信息存儲到磁盤上。二、 結(jié)構(gòu)分析:i) Train類的UML圖 Train- trainNum10:char- Eozoic20:char- Terminus20;char- starTime: Time+Train():+ Train(Num:char,Eo:char,Te:char,Ti:Time)+Train(x:const&Train)+Train()+ operator =( l: const Train &): Train &+ GetNum():char *+ GetEo():char *+ GetTe():char *+ GetTi(

3、):Time+ SelectNum(Num:char):int+SelectPlace(Place1:char,Place2:char):int+ Show():voidii) Ztrain類的UML圖 Ztrain+Ztrain()+Ztrain(Num:char, Eo:char,Te:char,Ti:Time)+Ztrain()ii) Ttrain類的UML圖 Ttrain+Ttrain()+Ttrain(Num:char,Eo:char,Te:char,Ti:Time)+Ttrain()iii) Dtrain類的UML圖 Dtrain+Dtrain()+Dtrain(Num:char,

4、 Eo:char,Te:char,Ti:Time)+Dtrain()iv) Ktrain類的UML圖 Ktrain+Ktrain()+Ktrain(Num:char,Eo:char,Te:char,Ti:Time )+Ktrain()三、 實(shí)現(xiàn)流程分析:i) Train類的聲明與實(shí)現(xiàn):struct Timeint hour;int minute;class Trainprivate:char trainNum10;char Eozoic20;char Terminus20;Time starTime;public:Train()Train(char Num,char Eo,char Te, T

5、ime Ti);Train(const Train & x);Train()Train & operator =(const Train & l); char *GetNum();char *GetEo();char *GetTe();Time GetTi(); int SelectNum(char Num); int SelectPlace(char Place1,char Place2); void Show();iv) Ztrain、Ttrain、Dtrain、Ktrain類的聲明與實(shí)現(xiàn):class Ztrain:virtual public Trainpubli

6、c:Ztrain()Ztrain(char Num,char Eo,char Te, Time Ti);Ztrain();class Ttrain:virtual public Trainpublic:Ttrain()Ttrain(char Num,char Eo,char Te, Time Ti);Ttrain();class Dtrain: public Ttrain,public Ztrainpublic:Dtrain()Dtrain(char Num,char Eo,char Te, Time Ti);Dtrain();class Ktrain: public Trainpublic:

7、Ktrain()Ktrain(char Num,char Eo,char Te, Time Ti);Ktrain();iii) 主函數(shù)的實(shí)現(xiàn):void ShowMenu();/*菜單顯示*/void Creat();/*建立字符串工具箱*/ void SerchAsPlace();/按站臺查詢void SerchAsNum();/按車次查詢void Display();/顯示所有信息void Save();/將鏈表信息保存到文件中void Open();/將文件中的信息讀到鏈表中LinkedList<Train> List;int main(void) char x; bool q

8、uit = false; List.ClearList(); Open(); while(!quit) ShowMenu(); cin>>x; switch(x) case 'a': cout<<"wode" system("cls"); Creat(); system("cls"); break; case 'b': system("cls"); SerchAsPlace(); system("cls"); break; case 

9、9;c': system("cls"); SerchAsNum(); system("cls"); break; case 'd': system("cls"); Display(); system("cls"); break; case 'e': system("cls"); Save(); system("cls"); break; case 'f': quit=true; break; default: break

10、; /system("cls"); return 1; /*主菜單*/void ShowMenu() cout<<"n*n" cout<<"a、添加列車時刻表n" cout<<"b、按始發(fā)站終點(diǎn)站查詢信息n" cout<<"c、按車次查詢列車信息n" cout<<"d、顯示所有列車信息n" cout<<"e、保存列車信息n" cout<<"f、退出n"

11、cout<<"n*n" cout<<"請選擇" void Creat()int m=1;char str110;int hour,minute;char str220,str320;Train p;Time y1;int n;while(m=1) cout<<"請輸入列車的類型:(,直達(dá)快車 2,動車組3,特快車 4,快車)"<<endl;cin>>n;cout<<"請輸入車次:" cin>>str1; cout<<&q

12、uot;請輸入發(fā)車時間(時和分中間用空格隔開):"<<endl; cin>>hour>>minute;y1.hour=hour;y1.minute=minute; cout<<"請輸入始發(fā)站:" cin>>str2; cout<<"請輸入終點(diǎn)站:" cin>>str3;if(n=1)Ztrain t(str1,str2,str3,y1);p=t;else if(n=2)Dtrain t(str1,str2,str3,y1);p=t;else if(n=3)Ttr

13、ain t(str1,str2,str3,y1);p=t;else if(n=4)Ktrain t(str1,str2,str3,y1);p=t;elsecout<<"輸入錯誤!" List.InsertRear(p); cout<<"是否想繼續(xù)輸入:,是.2,否。n" cin>>m; system("pause");void SerchAsPlace()char str220,str320;long pos=0;Train p; cout<<"請輸入始發(fā)站:"cin

14、>>str2;cout<<"請輸入終點(diǎn)站:"cin>>str3;List.Reset(); while(!List.EndOfList()p=List.Data();pos=p.SelectPlace(str2,str3);List.Next();if(pos=0)cout<<"沒有此信息"system("pause"); void SerchAsNum()Train p;long pos=0;char str120;cout<<"請輸入車次:"cin&g

15、t;>str1;List.Reset(); while(!List.EndOfList()p=List.Data();pos=p.SelectNum(str1);List.Next();if(pos=0)cout<<"沒有此信息"system("pause");void Display()Train p;List.Reset(); while(!List.EndOfList()p=List.Data();p.Show();List.Next();system("pause");四、 個性功能介紹:i) 鏈表模板類的聲

16、明與實(shí)現(xiàn):/*節(jié)點(diǎn)類*/ template<class T>class Nodeprivate:Node<T> * next;public:T data;Node (const T & item,Node<T> * ptrnext=NULL);void InsertAfter(Node<T> * p);Node<T> * DeleteAfter();Node<T> * NextNode()const;template<class T>Node<T>:Node(const T& ite

17、m,Node<T> * ptrnext):data(item),next(ptrnext)template<class T>Node<T> * Node<T>:NextNode()constreturn next;template<class T>void Node<T>:InsertAfter(Node<T> *p)p->next=next;next=p;template<class T>Node<T> * Node<T>:DeleteAfter()Node<T

18、> * tempPtr=next;if(next=NULL)return NULL;next=tempPtr->next;return tempPtr;/鏈表類template<class T>class LinkedListprivate:Node<T> * head,* tail;Node<T> * prevPtr,* currPtr;int size;int position;Node<T> * GetNode(const T & item,Node<T> * ptrnext=NULL);void FreeN

19、ode(Node<T> * p);void CopyList(const LinkedList<T> & L);public:LinkedList();LinkedList(const LinkedList<T> & L);LinkedList();LinkedList<T> & operator=(const LinkedList<T> & L);int ListSize()const;int ListEmpty()const;void Reset(int pos=0);void Next();int

20、 EndOfList()const;int CurrentPosition()const;void InsertFront(const T& item);void InsertRear(const T& item);void InsertAt(const T& item);void InsertAfter(const T& item);T DeleteFront();void DeleteAt();T& Data(void);void ClearList(void);template<class T>Node<T>* Linked

21、List<T>:GetNode(const T & item,Node<T> *ptrnext)Node<T> *p; p = new Node<T>(item,ptrnext); if (p = NULL) cout << "Memory allocation failure!n" exit(1); return p;template<class T>void LinkedList<T>:FreeNode(Node<T> *p)delete p;template<

22、class T>void LinkedList<T>:CopyList(const LinkedList<T> & L) /P用來遍歷L Node<T> *p = L.head; int pos; /將L中的每一個元素插入到當(dāng)前鏈表最后 while (p != NULL) InsertRear(p->data); p = p->NextNode(); /如果鏈表空,返回 if (position = -1) return; /在新鏈表中重新設(shè)置prevPtr和currPtr prevPtr = NULL; currPtr = hea

23、d; for (pos = 0; pos != position; pos+) prevPtr = currPtr; currPtr = currPtr->NextNode(); template<class T>LinkedList<T>:LinkedList(void)head=NULL;tail=NULL;size=0;position=0;template<class T>LinkedList<T>:LinkedList(const LinkedList<T> & L)head= tail = NULL; pre

24、vPtr = currPtr = NULL; size = 0; position = -1; CopyList(L);template<class T>void LinkedList<T>:ClearList()Node<T> *currPosition, *nextPosition; currPosition = head; while(currPosition != NULL) /取得下一結(jié)點(diǎn)的地址并刪除當(dāng)前結(jié)點(diǎn) nextPosition = currPosition->NextNode(); FreeNode(currPosition); cu

25、rrPosition = nextPosition; / 移動到下一結(jié)點(diǎn) head = tail = NULL; prevPtr = currPtr = NULL; size = 0; position = -1;template<class T>LinkedList<T>: LinkedList()ClearList();template<class T>LinkedList<T> & LinkedList<T>:operator =(const LinkedList & L)if (this = &L) /

26、不能將鏈表賦值給它自身return *this; ClearList(); CopyList(L); return *this;template<class T>int LinkedList<T>:ListSize()constreturn size;template<class T>int LinkedList<T>:ListEmpty()constif(size=0)return 1;elsereturn 0;template<class T>void LinkedList<T>:Reset(int pos)int s

27、tartPos; / 如果鏈表為空,返回 if (head = NULL) return; / 如果位置不合法,中止程序 if (pos < 0 | pos > size-1) cerr << "The position you set is wrong or out of range!"<< endl; return; / 設(shè)置與遍歷鏈表有關(guān)的成員 if(pos = 0) / 將指針重新設(shè)置到表頭 prevPtr = NULL; currPtr = head; position = 0; else / 重新設(shè)置 currPtr, pre

28、vPtr, 和 position currPtr = head->NextNode(); prevPtr = head; startPos = 1; /移動指針直到 position = pos for(position=startPos; position != pos; position+) / 向前移動遍歷指針 prevPtr = currPtr; currPtr = currPtr->NextNode(); template<class T>void LinkedList<T>:Next()if(currPtr!=NULL)prevPtr=currP

29、tr; currPtr=currPtr->NextNode();position+;template<class T>int LinkedList<T>:EndOfList()constif(currPtr=NULL)return 1;else return 0;template<class T>int LinkedList<T>:CurrentPosition()constreturn position;template<class T>void LinkedList<T>:InsertFront(const T

30、&item)/ 如果鏈表不空則調(diào)用Reset if (head != NULL) Reset(); InsertAt(item); / 在表頭插入template<class T>void LinkedList<T>:InsertRear(const T& item)Node<T> *newNode; prevPtr = tail; newNode = GetNode(item); / 創(chuàng)建新結(jié)點(diǎn) if (head = NULL) / 如果表空則插入在表頭 head = tail = newNode; else tail->Insert

31、After(newNode); tail = newNode; currPtr = tail; position = size; size+;template<class T>void LinkedList<T>:InsertAt(const T& item)Node<T> *newNode; / 兩種情況: 插入在鏈表頭或鏈表之中 if (prevPtr = NULL) / 插入在鏈表頭,包括將結(jié)點(diǎn)插入到空表中 newNode = GetNode(item,head); tail = newNode; else / 插入到鏈表之中. 將結(jié)點(diǎn)置于pr

32、evPtr之后 newNode = GetNode(item); prevPtr->InsertAfter(newNode); / 如果prevPtr = tail, 說明正在向空表中插入, / 或者是插入到非空表的表尾;更新rear 和 position if (prevPtr = tail) tail = newNode; position = size; /更新currPtr并且使size增值 currPtr = newNode; size+; template<class T>void LinkedList<T>:InsertAfter(const T&a

33、mp; item)Node<T> *p; p = GetNode(item); if (head = NULL) / 向空表中插入 head = currPtr = tail = p; position = 0; else / 插入到最后一個結(jié)點(diǎn)之后 if (currPtr = NULL) currPtr = prevPtr; currPtr->InsertNodeAfter(p); else if (currPtr = rear) tail = p; position = size; else position+; prevPtr = currPtr; currPtr =

34、p; size+; / 使鏈表長度增值template<class T>T LinkedList<T>:DeleteFront()T item; Reset(); if (head = NULL) cout << "The list is empty!" << endl; exit(1); item = currPtr->data; DeleteAt(); return item;template<class T>void LinkedList<T>:DeleteAt()Node<T>

35、 *p; / 如果表空或達(dá)到表尾則出錯 if (currPtr = NULL) cout << "The list is empty or it is the last node!" << endl; exit(1); / 刪除將發(fā)生在表頭或鏈表之中 if (prevPtr = NULL) / 保存頭結(jié)點(diǎn)地址并將其從鏈表中分離。 p = head; head = head->NextNode(); else / 分離prevPtr之后的一個內(nèi)部結(jié)點(diǎn). 保存其地址 p = prevPtr->DeleteAfter(); / 如果表尾結(jié)點(diǎn)被刪除, 則新的表尾是prevPtr 并且position自減; / 否則position不變 if (p = tail) tail = prevPtr; position-; / 使currPtr越過被刪除的結(jié)點(diǎn) currPtr = p->NextNode(); /p->NextNode()=prevPtr->NextNode(); / 釋放結(jié)點(diǎn),并使鏈表長度自減 FreeNode(p); size-;template<class T>T& LinkedL

溫馨提示

  • 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

提交評論