數據結構課程設計之全國鐵路最佳路徑問題_第1頁
數據結構課程設計之全國鐵路最佳路徑問題_第2頁
已閱讀5頁,還剩35頁未讀, 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

1、聽題救築為n金購,厠的耀僥牌參躇儷風才c 02數據關系: R1=| ai-1,ai D,i=1,2,3,n基本操作:void readviews()初始條件: views.txt 已經存在。操作結果: 將 views.txt 里面的數據一次存入數組 viewsSIZE_view 里,并將數組里的存儲 數據的個數賦值給全局變量 view_count ;void readways()初始條件: ways.txt 已經存在。操作結果: 將 ways.txt 里面的數據一次存入數組 waysSIZE_view 里,并將數組里的存儲數 據的個數賦值給全局變量 way_count ;void readli

2、nes()初始條件: lines.txt 已經存在。操作結果: 將 lines.txt 里面的數據一次存入數組 linesSIZE_view 里,并將數組里的存儲 數據的個數賦值給全局變量 line_count.void search();初始條件: viewsSIZE_view 存在,且里面放有相關的數據。 操作結果:根據用戶輸入的車站名查找該車站的相關信息并輸出; void addview();初始條件: views.txt 已經存在。操作結果: 將 views.txt 里面的數據一次存入數組 viewsSIZE_view 里,并將數組里的存儲 數據的個數賦值給全局變量 view_coun

3、t ;void addway();初始條件: ways.txt 已經存在。操作結果: 將 ways.txt 里面的數據一次存入數組 waysSIZE_view 里,并將數組里的存儲數 據的個數賦值給全局變量 way_count ;void addline();初始條件: lines.txt 已經存在。操作結果: 將 lines.txt 里面的數據一次存入數組 linesSIZE_view 里,并將數組里的存儲 數據的個數賦值給全局變量 line_count.void floyed();初始條件: viewsSIZE_view 、 waysSIZE_view 、 linesSIZE_view存在

4、并且存有相關的信息操作結果:把每個車站到人一個車的最短經由路徑及此路徑的距離存儲在 path_infopath_listSIZE_viewSIZE_view 數組里;void shortest_path()初始條件: path_info path_listSIZE_viewSIZE_view存在且存儲相關的數據;操作結果:輸出輸入的兩個站的最短距離及經過的所有站;void adddata( int menu)初始條件: views.txt 、 ways.txt 、 lines.txt 已經存在。操作結果:如果 menu=1,則添加車站數據,如果 menu=2 則添加路線數據;3. 軟件結構設計

5、:3三、詳細設計1.定義程序中所有用到的數據及其數據結構,及其基本操作的實現;struct view_info/* 車站信息結構 */int id;/車站的 id 編號char name20;/車站的名字int code;/車站的編碼char shortname20;/ 車站的簡稱char LName100; /經過此站的鐵路線名稱viewsSIZE_view;struct line_info/鐵路線信息結構int Lid;/鐵路線的 id 編號char LName20; /鐵路線的名字int start_id;/鐵路線的始發(fā)站int end_id;/鐵路線的終點站int dist;/鐵路線長

6、char sig n 5;/鐵路線的通行標志li nesSIZE_li ne;struct way_i nfoint station1;/鐵路線上站與站之間的信息結構/前一個站int station2;/后一個站int dist;/前后站之間的距離waysSIZE_way;struct path_i nfoint count;/用于最短路徑的查詢/用于存最短路徑的站的個數int pathSIZE_view;2.主函數和其他函數的代碼算法;(1)voidreadviews();王 l mvoidreadli nes();a。氣 t)(rea 牆 s();)rAvoid search();void

7、 floyed();voidshort_path();void addway();void addview();void addline(); J 7 J4void main()5readviews();/* coutendlendl;*/ readlines();/* coutendlendl;*/ readways();while (1)int menu;coutendlendl;cout 全國鐵路運輸網經由系統(tǒng) endl;coutIl*endl;cout 1cout 2cout 3cout 4cout 5、增加車站信息 endl; 、增加鐵路線信息 endl;、查詢車站信息 endl;、

8、查詢最短路徑 endl; 、退出界面 endl;cout *cout 請選擇你要的操作代碼( 1-5): menu;while (menu5)coutmenu;switch (menu)case 1:endl;case 2: adddata(menu); break ;case 3: while (1)search(); coutcon; if (con= y );elseendl;break ;break ;case 4:while (1)6short_path();cout do you want to continue?(y/n) con;if (con= y );/* addline(

9、);*/elsebreak ;break ;case 5:cout 謝謝使用,再會! endl;exit(1);(2)void readviews()int i;ifstream infile(views.txt ,ios:in);/ 打開文件if (!infile) / 打開文件失敗cerr cant open views.txt! viewsi.codeviewsi.shortnameview si.LName;if (i!=0&viewsi.id=0) break ;view_count=i;infile.close();/ 下面是測試用的代碼co

10、utsetiosflags(ios:left);coutsetw(8) id setw(9) name setw(8) code setw(12) shortname setw(10) LNameendl;for (i=0;iview_count;i+)7coutsetw(8)viewsi.idsetw(9)setw(8)viewsi.code setw(12);coutviewsi.shortnameviewsi.LNameendl;coutresetiosflags(ios:left);(3)void readways() / 讀文件 ways.txtint i;if

11、stream infile(ways.txt ,ios:in);/ 打開文件if (!infile) / 打開文件失敗cerr cant open ways.txt! waysi.station1waysi.station2waysi.dist;if (i!=0&waysi.station1=0) break ;way_count=i;infile.close();/ 測試用,輸入路段的信息/coutsetiosflags(ios:left);/coutsetw(12)station1setw(12)station2distendl;/for(i=0;iway_count;i+)/coutse

12、tw(12)waysi.station1setw(12)waysi.station2;/coutwaysi.distendl;/coutresetiosflags(ios:left);(4)void readlines() / 讀文件 lines.txtint i;ifstream infile(lines.txt ,ios:in); / 打開文件if (!infile) / 打開文件失敗cerr cant open lines.txt! linesi.Lidlinesi.LNamelinesi.start_id;infilelinesi.end_idlinesi.distlinesi.sig

13、n;if (i!=0&linesi.Lid=0) break ;8line_count=i;infile.close();/ 下面的代碼為測試時用的 coutsetiosflags(ios:left);coutsetw(8) Lid setw(12) LNamesetw(10) start_id ; coutsetw(10)end_id setw(8) dist sign endl; for (i=0;iline_count;i+)coutsetw(8)linesi.Lidsetw(12)linesi.LNamesetw(10)linesi.s tart_id;coutsetw(10)line

14、si.end_idsetw(8)linesi.distlinesi.signendl;coutresetiosflags(ios:left); / 這里輸出文本中的信息(5)void search() / 查詢車站信息(所在的鐵路線)coutsta_name; / 輸入要查詢的名字 coutendl;int i,mark;for (i=0;iview_count;i+)if (strcmp(sta_name,)=0)cout the station informations is:nendl;coutsetiosflags(ios:left);coutsetw(8) id

15、 setw(9) name setw(8) code setw(12) shortname setw(10) LNameendl;coutsetw(8)viewsi.idsetw(9)setw(8)viewsi.code setw(12);coutviewsi.shortnameviewsi.LNameendl; coutresetiosflags(ios:left);break ;mark=i;if (mark=view_count-1) / 若沒找到,輸出提示 cout sorry, the station is not in here!endl;(6) void a

16、ddview()cout Please enter the new views informations:endl; / 輸入新的車站信息cout viewsview_count-1.idviewsview_count.id;while (1)if (viewsview_count.idviewsview_count-1.id)coutviewsview_count.id;else break ;9coutviewsview_;cout viewsview_count-1.codeviewsview_count.code;while (1)if (viewsview_cou

17、nt.codeviewsview_count-1.code)coutviewsview_count.id;else break ;coutviewsview_count.shortname;coutviewsview_count.LName;ofstream outfile( views.txt ,ios:app);/ 打開 views 文件,并寫入數據if (!outfile)cerr cant open views.txt! ; exit(1);10outfileendlviewsview_count.id viewsview_outfileviewsview_coun

18、t.code viewsview_count.shortname; outfile viewsview_count.LNameendl;/ 在文件末尾添加 view_count+;outfile.close(); / 關閉文件 cout Successfully!the new station is addedendl;cout new station number is :view_countendl;7) void addway()cout Please enter the new ways informations: endl; coutwaysway_count.station1; c

19、outwaysway_count.station2; coutwaysway_count.dist;ofstream outfile( ways.txt ,ios:app);/* outfileway_countendl;*/if (!outfile)cerr cant open ways.txt!;exit(1);outfileendlwaysway_count.station1 waysway_count.station1;outfile waysway_count.dist;/ 在文件末尾添加 way_count+;outfile.close(); / 關閉文件 coutSuccessf

20、ully!the new way is addedcout new station number is :way_countendl;(8)void addline()cout Please enter the new lines informations:endl; / 輸入新鐵路信息cout linesline_count-1.Lidlinesline_count.Lid;/ 輸入新的車站信息/station1的 id/station2 的 id/ 路段的長度/ 打開 ways.txt 文件,并寫入數據 waysway_count.station2outfilewaysway_count.

21、dist waysway_count.station211while (1)if (linesline_count.Lidlinesline_count-1.Lid)coutlinesline_count.Lid;elsebreak ;coutlinesline_count.LName;coutlinesline_count.start_id;coutlinesline_count.end_id;coutlinesline_count.dist; coutlinesline_count.sign;ofstream outfile(lines.txt ,ios:app);/* outfileli

22、ne_count+1endl;*/if (!outfile)cerr cant open lines.txt! exit(1);cout new station number is : line_countendl;(9)void floyed() / 弗洛伊德算法int i,j,k,m;for (int t=0;t=way_count;t+) i=wayst.station1;j=wayst.station2; dist_listij=wayst.dist; / 把文件中的數據付給 dist_listij=wayst.dist;形式for (i=0;i=view_count;i+)for (

23、j=0;j=view_count;j+)if (i=j) / 車站到本車站的距離賦值為零dist_listij=0;continue ;dist_listij=-1; / 先設置任意兩點之間的距離為 -1 ;表示這兩點不通/ 打開文件,并寫入數據outfileendllinesline_count.Lid linesline_count.LName linesline_count.start_id;outfile linesline_count.end_idoutfilelinesline_count.sign;/ 在文件末尾添加line_count+;outfile.close(); / 關

24、閉文件 coutSuccessfully!the new line is added linesline_count.distendl;II IIdist_listij=dist_listik+dist_listkj;/ 求出 i 、12path_listij.count=0; / 先設置任意兩點之間的的路徑的車站數為零 for (k=0;kway_count;k+) /ways文件的數據賦給 dist_list 數組、并記 下其中任兩站的路徑if (waysk.station1=i&waysk.station2=j)dist_listij=waysk.dist; path_listij.co

25、unt=2; path_listij.path0=i;path_listij.path1=j;break ;/ 下面是計算最短路徑的代碼for (k=0;k=view_count;k+)for (i=0;i=view_count;i+)for (j=0;j=view_count;j+)if (i=k|j=k|i=j) / 三個站中至兩個站是相同的的話就是繼續(xù)循 環(huán)continue ;if (dist_listik=-1|dist_listkj=-1)i 、k 不通或者 k、j 不通繼續(xù)循環(huán)continue ;if (dist_listij=-1)|(dist_listij != -1)&(di

26、st_listik+dist_listkjdist_listij) /i 、 j 不通,或者是 i 、 j 通但是不是最短路徑,執(zhí)行下面語句13j 的最短距離/shortestij=shortestik+shortestkj;path_listij.count=path_listik.count+path_listkj.count-1;/ 求出 i 、j 路徑的站的個數/path_listij=k;for (m=0;mpath_listik.count;m+) / 下面兩個 for 語句標出 i、j 路徑的每個站的 id 號,以便后面的輸出最短經由路徑用path_listij.pathm=pa

27、th_listik.pathm;for (m=0;mpath_listkj.count;m+)path_listij.pathm+path_listik.count=path_listkj.pathm+1;(10)void shortest_path()floyed();int i,k,m;int start_num=-1,end_num=-1;string start_station,end_station; / 定義起始站、終點站/ 下面便是輸出最短經由路徑的代碼cout Floyed table:n ;cout All cities in the table:n ;for (i=0;iv

28、iew_count;i+)/ 輸出可以查看的站的名稱和 id 號coutsetiosflags(ios:left);coutsetw(2)i+1 : setw(10);if (1+i)%5)=0&i!=0)coutendl;coutresetiosflags(ios:left);coutendl;coutstart_station;for (i=0;iview_count;i+)if (start_station=)start_num=i;while (start_num=-1) / 容錯處理cout 你的輸入有誤,請重新輸入! endl; cout

29、start_station;for (i=0;iview_count;i+)if (start_station=) start_num=i;coutend_station;for (i=0;iview_count;i+)dist_listij=dist_listik+dist_listkj;/ 求出 i 、14if (end_station=)end_num=i;while (end_num=-1) / 容錯處理cout 你的輸入有誤,請重新輸入! endl;coutend_station;for (i=0;iview_count;i+)if (en

30、d_station=) end_num=i;coutendlendl;cout From viewsstart_ to viewsend_; / 輸出最短經由路 徑if (dist_liststart_num+1end_num+1=-1) / 沒有找到的情況的回應 cout no way. endl;elsecout distance is dist_liststart_num+1end_num+1 , and path is: endl;k=path_liststart_num+1end_num+1.path0-1;coutviewsk.

31、name;for (m=1;mpath_liststart_num+1end_num+1.count;m+)k=path_liststart_num+1end_num+1.pathm-1;cout ;coutendl;(11)void adddata( int menu)if (menu=1)while (1)addview(); cout do you want to continue?(y/n) con;if (con= y ); else break ;if (menu=2)while (1)addline(); addway();cout do you want

32、to continue?(y/n) con; if (con= y );else break ;153. 主要函數的程序流程圖,實現設計中主程序和其他子模塊的算法,以流程圖 的形式表示。整個程序的流程圖:164.主要算法 floyed 算法的流程圖開始main()readviews();readlines();readways();17開始接上面的出口18dist_listik=1|dist_listkj=-1N_“ != -1)&(dist_listik+dist_listkj0;m0;k0;i0;jO;m =the start stat ion nainiE:南丁the end_stati

33、on nNme;咕爾濱Fron南丁to占爾済distance is 3953北京-天津-沈陽-長春-哈爾濱do 011 want to continue?C/nPlease Input the start stat ion name sPlease input the end_station nante: .ITgpFrom北早to咸都distance is 2048, and path”:北丘鄭州-西,do pou i?an t to cont inue?n全國鐵路運輸網經由系統(tǒng)Floyed table: Allcities逸濱11=fg16:21:;福州in the table:;韓浩特1

34、2咲附17:22:齊木陽負界讀:i;i3 3技3 33 3 8 8 1 1- -1 12 2連宀若那蓬=盞4 4 9 9 4 44 4 9 9 1 11 12 2津州洛曰寧0 0 5 5 0 0 5 55 5 1 11 12 2 2 2息垛信路站路站短面界加加詢詢岀退4、Please input Pleaseinput連宀At訓大西上需_4 4 9 9 4 4津州醫(yī)寧衣三武南南! ! * * W W 0 0 5 5 0 0 5 5 5 5 1 11 12 22 2Ployed table:All cities in the table:全國鐵路運輸網經曰系統(tǒng)21請選擇你要的操作代碼1Pleas

35、e enter the new id25:26 n ane:桂林code125:126shortname:GL LNane:桂柳線Successfullytthe neu neu(1-55:views infornations:do you want to continue? n全國鐵路運輸網經由系統(tǒng)請選擇你要的操作代碼(1-5X2Please enter the net? LireJs infovnat ions:Lid1123?:1124LNane :桂樓戔stationl:26stations:24aist:128Successfulli/?the neu way is addedneu

36、 stat ion nunbei Is:: Clde you uant to Gontxrwue? Cy/n全國鐵路運輸網經由系統(tǒng)請選擇禰要的操作代碼lcA&e entei1the &tat ionhe stat ion inFopnat iori?name桂林cade12tshotnant GLo you uant to tontInue? Qj/nLNAFI&桂柳線station is addedstat ion numbei* is : 26息息心徑亠一H.-電沖亠一一號-u站路砧矩面車反界加加詢詢出查退、1 12 2 3 3 4 4 5 51 12 2 3 3 4 4 5 5息自信自4

37、徑1 11 1踐亠耳路舉期面取界加加詢詢岀增豐杳_退nane:桂林全國鐵路運輸網經由系統(tǒng)22幘選擇你要的操作代碼(1-5 =4From柱林to成都distance is 1702, and path is林-柳州-貴卩do you uant to continue? 全國鐵路運輸網經由系統(tǒng)隹選擇你要的操作代碼(1-5:全國鐵路運輸網經臼系統(tǒng)情選擇你要的操作代碼(1-5 =六、用戶手冊1 初始界面2、選擇 1州曙曰宀丁蘭武南南 ! ! !0 0 5 5 0 0 5 51 11 12 2 2 2宀麗西上需:4 4 9 9 4 49 9 1 11 12 2齊木烏糞深S S3 38 83 38 8 1

38、 11 12 2X X4 4八/日呼鄭昆廣2 2 7 7 2 2the stap七 尊七at ion name :TY- theend_tation name :lease input leaseInput息息徑辣信路站路站短面爭瓦界加加詢詢出查退、1 12 2 3 3 4 4 5 5自息一心徑士二R戔亠- -_ _R R各站路站短面J全國鐵路運輸網經由系統(tǒng)231Please enter the new vieu1s i id25):26name i彳圭林code 125 5126 lshai*tname: GLLNane:桂柳線SuccessFullv?the neu stat ion ne

39、w stat ionnumbei is & do you uant to cantinue? nII24、選擇 33、選擇 245、選擇 43Please enter the stat ion name: jM the stat ioninformat ions Is:idnanecodeshoptname14上海114SHHdo youi uant to continne? Please enter the stat ion namg:海南sorry, the stat ion is not in here ? do vou vant tocontinue?Flowed table:All

40、citiea16丄1.16212irine e: :特b bl l浩t ta a畫州霜血需耆; ;F F t t 2 2 7 7 2 2 2 2 7 7 1 11 12 23 3 8 8- -3 33 3 8 8 1 11 12 2津州洛曰寧吠宀羸誦誦0 0 5 5 0 0 5 5 5 5 1 11 12 2 2 2Piease input Pleaseinputstat ion name: riS誠都the start the endstation name成都distance is 2353and pathFro m上丫上海- 徐州鄭州- 西安 T 咸都ant to continue? t

41、odo 90 uyFlowednil ci1table: les弦濱in the table:3:沈陽8:烏簣木齊18:fF23:Sill津州洛B B丁天蘭武南南一 | : 5 50 05 5 5 5 1 11 12 2 2 2浩特?:呼和12:鄭辦傭淮歩22:p JT2126Please in put_ l爾的輸入肴誤,請重薪輸入!PeasePle as e in puttlie startstat ionnane-青1Sthe start stat ion theerd_sttttion namenane:Jt京,哈東濱Fron北呆to哈爾浜distance is 1368, and pa

42、th is:北京-沃津-沈陽-疋春哈爾濱do uoiti uant to continue?II25全國鐵路運輸網經由系統(tǒng)266、選擇 5晴選擇你要的操作代碼(i-s =七、體會與自我評價這次的程序軟件基本上運行成功,可以簡單的對已經輸入的數據進行計算,求全國鐵路運輸網最佳經由。但是程序較小,功能不全面,只是理論,并未實踐。同時,這次數據結構課程設計讓我們感觸很深, 使我們每個人都了解到的學 習不應該只局限于我們的課本,因為課本上告訴我們的只是很有限的一部分, 所 涉及的面也是狹窄的。但是怎樣在有限的范圍內學習到無限的知識呢?那就要我 們自己懂得競爭,懂得自學,懂得充分利用身邊的任何資源。應該

43、說,我們在這 次的課程設計中學到了很多知識, 這并不僅僅包括書本上的知識,更重要的是我 們學會了如何去和別人交流,怎樣用語言去實現自己的想法,在這個過程中使我 懂得了勤學好問的重要性。雖然在我的程序中有一部分是從網上搜索得來的, 但我竭力將所獲得的信息 變成自己的資源。在了解和看懂的基礎上有所改變和創(chuàng)新,但是在我的程序軟件 中還有部分的不足。同時,通過這次課程設計,我們都意識到了自己動手實踐的 弱勢,特別是在編程方面,只有通過上機編程才能充分的了解自己的不足。相信通過這次的課程設計,更讓我深刻意識到自己在學習中的弱點, 同時也 找到了克服這些弱點的方法,這也是一筆很大的資源。在以后的時間中,我

44、應該 利用更多的時間去上機實驗,多編寫程序,相信不久后我的編程能力都會有很大 的提高。經過這次課程設計,通過對程序的編制,調試和運行,使我更好的掌握 了圖基本性質和關于選址問題的解決方法, 熟悉了各種調用的數據類型,在調試 和運行過程中使我更加的了解和熟悉程序運行的環(huán)境, 提高了我對程序調試分析 的能力和對錯誤的糾正能力。這次數據結構的程序設計,對于我來說是一個挑戰(zhàn)。 我對數據結構的學習在程序的設計中也有所體現。 課程設計是培養(yǎng)學生綜合運用 所學知識、發(fā)現、提出、分析和解決實際問題,鍛煉實踐能力的重要環(huán)節(jié),是對 學生實際工作能力的具體訓練和考察過程。 隨著科學技術發(fā)展的日新月異,當今 計算機應

45、用在生活中可以說得是無處不在。 因此作為二十一世紀的大學來說掌握 計算機開發(fā)技術是十分重要的。在整個課程程序中,我們充分應用和調用各個程序模塊,從而實現了此次程 序設計的所應該有的功能。在本組看來這就是我們在課程設計是比較成功的, 而 在這個過程中,讓我們感覺收獲最大的就是我們都能利用這次課程設計學到很多 我們在課本上沒有的知識(Floyd 算法),充分的發(fā)揮了我們的主動性,使我們 自主的去學習。自.2息一心徑亠耳戔亠耳各站路站短面車界加加詢詢岀香一退、S SI I址、*1 12 2 3 3 4 4 5 527源代碼#include #include #include #include #in

46、clude #include #define SIZE_view 50 #define SIZE_line 100 #defineSIZE_way 300#define MAXNODE 30 / 定義最多節(jié)點數 #define MAXCOST 10000 using namespace std;struct view_info/* 城市信息結構 */int id;char name20;int code;char shortname20;char LName100;/ 經過此站的鐵路線名稱 viewsSIZE_view;struct line_info/ 鐵路線信息結構int Lid;char

47、 LName20;int start_id;/ 始發(fā)站int end_id; / 終點站int dist; / 鐵路線長char sign5; / 通行標志 linesSIZE_line;struct way_info/ 鐵路度的信息結構int station1;int station2;int dist; waysSIZE_way;28struct path_info / 用于最短路徑的查詢int count;int pathSIZE_view;int view_count,line_count,way_count; / 用來存儲文件中有多少條記錄int dist_listSIZE_view

48、SIZE_view; / 定義一個數組struct path_info path_listSIZE_viewSIZE_view; / 定義一個 path_info 結構體變量,void readviews();void readways();void readlines();void search();void addview();void addway();void addline();void shortest_path();void floyed();void adddata(int menu);void main()readviews();/* coutendlendl;*/ read

49、lines();/* coutendlendl;*/readways();while(1)int menu;coutendlendl;cout 全國鐵路運輸網經由系統(tǒng) endl;cout 請選擇你要的操作代碼( 1-5):menu;while(menu5)coutmenu;switch(menu)case 1:case 2:*endl;coutcoutcoutcoutcout1、增加車站信息 endl;2、增加鐵路線信息 endl;3、查詢車站信息 endl;4、查詢最短路徑 endl;5、退出界面 endl;endl;coutcout*29adddata(menu);break;case 3

50、:while(1)search();coutdo you want to continue?(y/n)con;if(con=y);elsebreak;break;case 4:while(1)shortest_path();coutdo you want to continue?(y/n)con;if(con=y);/* addline();*/elsebreak;break;case 5:cout 謝謝使用,再會! view_count; */if(!infile) / 打開文件失敗cerrcant open views.txt!view_count;/ 先讀入文件個數for(i=0;i+)

51、viewsi.codeviewsi.shortnameviewsi.LName;if(i!=0&viewsi.id=0)break;view_count=i;/view_count=i;/ 給出源文件中車站的個數infile.close();/ 下面是測試用的代碼 coutsetiosflags(ios:left);coutsetw(8)idsetw(9)namesetw(8)codesetw(12)shortnamesetw(10)LNameendl;for(i=0;iview_count;i+)coutsetw(8)viewsi.idse

52、tw(9)setw(8)viewsi.codesetw(12);coutviewsi.shortnameviewsi.LNameendl;coutway_count;*/ / 把文件中的記錄付給 way_countif(!infile) / 打開文件失敗cerrcant open ways.txt!waysi.station1waysi.station2waysi.dist; if(i!=0&waysi.station1=0)break;way_count=i;infile.close();/ 測試用,輸入路段的信息/coutsetiosflags(ios:left);/

53、coutsetw(12)station1setw(12)station2distendl;/for(i=0;iway_count;i+)/coutsetw(12)waysi.station1setw(12)waysi.station2;/coutwaysi.distendl;/31/coutresetiosflags(ios:left);void readlines()/ 讀文件 lines.txtint i;ifstream infile(lines.txt,ios:in);/ 打開文件/ 把文件中的記錄付給 line_countif(!infile) / 打開文件失敗cerrcant op

54、en lines.txt!line_count; */for(i=0;i+)infilelinesi.Lidlinesi.LNamelinesi.start_id;infilelinesi.end_idlinesi.distlinesi.sign; if(i!=0&linesi.Lid=0)break;line_count=i;infile.close();/ 下面的代碼為測試時用的coutsetiosflags(ios:left);coutsetw(8)Lidsetw(12)LNamesetw(10)start_id;coutsetw(10)end_idsetw(8)distsignendl

55、;for(i=0;iline_count;i+)coutsetw(8)linesi.Lidsetw(12)linesi.LNamesetw(10)linesi.start_id;coutsetw(10)linesi.end_idsetw(8)linesi.distlinesi.signendl;coutresetiosflags(ios:left);/ 這里輸出文本中的信息void search() / 查詢車站信息(所在的鐵路線)coutsta_name; / 輸入要查詢的名字 coutview_count;*/ 讀出文件記錄的個數/ if(!infile) / 打開文件失敗/ /cerrc

56、ant open views.txt!endl;/exit(1);/ int i,mark;/ for(i=0;viewsi.codeviewsi.shortnameviewsi.LName;/ infile.close(); for(i=0;iview_count;i+)if(strcmp(sta_name,)=0)coutthe station informations is:nendl; coutsetiosflags(ios:left);32coutsetw(8)idsetw(9)namesetw(8)codesetw(1

57、2)shortnamesetw(10)LNameendl;coutsetw(8)viewsi.idsetw(9)setw(8)viewsi.codesetw(12);coutviewsi.shortnameviewsi.LNameendl; coutresetiosflags(ios:left);break;mark=i;if(mark=view_count-1) / 若沒找到,輸出提示 coutsorry, the station is not in here!endl;void addview()coutPlease enter the new views infor

58、mations:endl;/ 輸入新的車站信息coutviewsview_count-1.idviewsview_count.id;while(1)if(viewsview_count.idviewsview_count-1.id)coutviewsview_count.id;elsebreak;coutviewsview_; coutviewsview_count-1.codeviewsview_count.code;while(1)if(viewsview_count.codeviewsview_count-1.code)coutviewsview_count.id;e

59、lsebreak;coutviewsview_count.shortname; coutviewsview_count.LName;ofstream outfile(views.txt,ios:app);/ 打開 views 文件,并寫入數據/* outfileview_countendl;*/if(!outfile)cerrcant open views.txt!; exit(1);outfileendlviewsview_count.id viewsview_ ;outfileviewsview_count.code viewsview_count.shortname;

60、 outfileviewsview_count.LNameendl;/ 在文件末尾添加 view_count+;outfile.close(); / 關閉文件 coutSuccessfully!the new station is addedendl; coutnewstation number is :view_countendl;33void addway()34coutPlease enter the new ways informations:endl; / 輸入新的車站信息coutstation1:;outfileendlwaysway_count.station1 waysway_

溫馨提示

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

評論

0/150

提交評論