C++實現景區信息管理系統

景區信息管理系統ios

實現了:算法

 

1.1 創建主程序應用菜單選項spa

主程序應用菜單選項包含所實現的全部功能,而且對選項採用數字標識進行選擇,對其餘錯誤輸入能夠進行判別,提示輸入錯誤。rest

1.2 導遊線路圖的建立級景區分佈圖的輸出code

用鄰接鏈表存儲景點分佈圖的信息,(帶權無向)圖的鄰接鏈表。輸出景區景點分佈圖(鄰接矩陣)。圖中邊的權值∞用32767表示。blog

1.3  輸出導遊線路圖排序

景區旅遊信息管理系統中制訂旅遊景點導遊線路策略,首先經過遍歷景點,給出一個入口景點,創建一個導遊線路圖,導遊線路圖用有向圖表示。ip

1.4  輸出導遊線路圖中是否有迴路ci

景區旅遊信息管理系統中,建立好導遊路線圖後,判斷該圖中是否存在迴路。string

1.5 查找及排序

l  查找功能: 能夠根據用戶輸入的關鍵字進行景點的查找,關鍵字能夠在景點名稱也能夠在景點介紹中。查找成功則返回景點的相關簡介,若是查找不成功請給予正確提示。

l  排序功能:按景點歡迎度,景點的岔路數對景點進行排序並打印出來排序順序。

1.6  輸出兩個景點之間最短路徑和最短距離

求出兩個景點間的最短路徑和最短距離,而且輸出道路修建規劃圖。 算法採用迪傑斯特拉算法。

1.7   輸出道路修建規劃圖

道路建設首先要保證能連通全部景點,但又要花最小的代價。

1.8  輸出車輛的進出信息

1.8.1 具體需求:

停車場是一個能夠停放n輛汽車,且只有一個大門可供汽車進出。汽車在停車場內按車輛到達時間的前後順序,依次排列,若車場內已停滿n輛車,後來的車只能在門外的便道上等候,一旦有車開走,則排在便道上的第一輛車便可開入;當停車場內某輛車要離開時,在它以後進入的車輛必須先退出車場爲它讓路,待該輛車開出大門外,其它車輛再按原次序進入車場,每輛停放在車場的車在它離開停車場時必須按它停留的時間長短交納費用。輸出每輛車到達後的停車位置(停車場或便道上),以及某輛車離開停車場時應繳納的費用和它在停車場內停留的時間。

1.8.2  停車場的管理流程以下:

A.當車輛要進入停車場時,檢查停車場是否已滿,若是未滿則車輛進入停車場;若是停車場已滿,則車輛進入便道等候。

B.當車輛要求出棧時,先讓在它以後進入停車場的車輛退出停車場爲它讓路,再讓該車退出停車場,讓路的全部車輛再按其原來進入停車場的次序進入停車場。以後,再檢查在便道上是否有車等候,有車則讓最早等待的那輛車進入停車場。

1.8.3 車輛出入清單:

每一組輸入數據包括三個數據項:汽車「到達」或「離去」信息、汽車牌照號碼以及到達或離去的時刻。對每一組輸入數據進行操做後的輸出信息爲:如果車輛到達,則輸出汽車在停車場內或便道上的停車位置;如果車輛離去,則輸出汽車在停車場內停留的時間和應交納的費用(在便道上停留的時間不收費)。

1.9

退出整個程序。

 

完整代碼以下(直接編譯可運行):

 

  1 #include <iostream>
  2 #include <fstream>
  3 #include <time.h> 
  4 #include <stdio.h>
  5 #include <cstring>
  6 #include <iomanip>
  7 #include <stack>
  8 #include <queue>
  9 #define MAX 20
 10 #define MAX2 2
 11 #define INFINITY 32767
 12 int arr1[MAX][MAX];
 13 
 14 using namespace std;
 15 double arr[MAX][MAX];
 16 
 17 class ArcNode {
 18     public:
 19         int adjvex;
 20         ArcNode *nextarc;
 21         double weight;
 22 };
 23 
 24 
 25 class VNode {
 26     public:
 27         string data1;
 28         string data2;
 29         int wel;
 30         bool wc;
 31         bool rest; 
 32         ArcNode *firstarc;
 33 };
 34 
 35 class ALGraph {
 36     public:
 37         VNode *vertices;
 38         int vexnum, arcnum;
 39         ArcNode *arcNode;
 40 };
 41 
 42 class zanlind
 43 {
 44 public:
 45     int number;
 46     int hour;
 47     int minute;
 48 };
 49 
 50 
 51 int LocateVex(ALGraph G, string v) {
 52     int i; 
 53     for(i = 0; v != G.vertices[i].data1 && i < G.vexnum; i++)
 54         ;
 55     if(i >= G.vexnum)
 56         return -1;
 57     return i;
 58 }
 59 
 60 int LocateW(ALGraph G, int wel) {
 61     int i;
 62     for(i = 0; wel != G.vertices[i].wel && i < G.vexnum; i++)
 63         ;
 64     if(i >= G.vexnum)
 65         return -1;
 66     return i;
 67 }
 68 
 69 void CreateUDN(ALGraph &G) {
 70     G.arcNode=new ArcNode[MAX];
 71     G.vertices=new VNode[MAX];
 72     
 73     fstream file("info.txt");
 74     if(file.fail())
 75     {
 76         cout << "error open!" << endl;
 77     }
 78     int  j;
 79     ArcNode *s, *t;
 80     cout<<"請輸入頂點數和邊數:";
 81     cin>>G.vexnum>>G.arcnum;
 82     int i=0;
 83     cout<<endl;
 84     while(!file.eof()) 
 85     {
 86         file >>G.vertices[i].data1>>G.vertices[i].data2 >> 
 87         G.vertices[i].wel>> G.vertices[i].rest>>G.vertices[i].wc;
 88         G.vertices[i].firstarc = NULL;
 89         i++;
 90     }    
 91     cout<<endl;    
 92     fstream file1("edge.txt");
 93     if(file.fail())
 94     {
 95         cout << "error open!" << endl;
 96     }
 97     while(!file1.eof()) 
 98     {
 99         int weight;
100         string v1, v2;
101         file1>>v1>>v2>>weight;
102         
103         int i = LocateVex(G, v1);
104         int j = LocateVex(G, v2);
105 
106         s = new ArcNode();
107         t = new ArcNode();
108 
109         s->adjvex = j;
110         s->nextarc = G.vertices[i].firstarc;
111         s->weight=weight;
112         G.vertices[i].firstarc =s;
113 
114         t->adjvex = i;
115         t->nextarc = G.vertices[j].firstarc;
116         t->weight=weight;
117         G.vertices[j].firstarc =t;
118     }
119     file1.close();
120     file.close(); 
121 
122 }
123 
124 
125 void  PrintAdjList(ALGraph &G) {
126     cout<<"下面是圖的鄰接鏈表輸出:" <<endl;
127     ArcNode *p;
128     cout<<"  編號 "<<"頂點"<<"   相鄰邊編號"<<endl;
129     for(int i = 0; i < G.vexnum; i++) {
130         cout<<"   "<<i<<"    "<<G.vertices[i].data1;
131         for(p = G.vertices[i].firstarc; p; p = p->nextarc)
132             cout<<"--------->"<<p->adjvex;
133         cout<<endl;
134     }
135 
136 
137 }
138 
139 void OutputGraph(ALGraph G) {
140     cout<<"下面是圖的鄰接矩陣輸出:"<<endl;
141     int m1=G.vexnum;
142     int m2=G.vexnum;
143 
144     for(int i=0; i<m1; i++) {
145         for(int j=0; j<m2; j++) {
146             arr[i][j]=32767;
147         }
148     }
149 
150     for(int k=0; k<m1; k++) {
151         ArcNode *p=G.vertices[k].firstarc;
152         for(int i2=0; i2<m2; i2++) {
153             if(k==i2) {
154                 arr[k][i2]=0;
155             }
156             if(p) {
157                 arr[k][p->adjvex]=p->weight;
158                 p=p->nextarc;
159             }
160 
161         }
162     }
163     cout<<"        ";
164     for(int n1=0; n1<m1; n1++) {
165         cout<<setiosflags(ios::left)<<setw(11)<<G.vertices[n1].data1;
166 
167     }
168     cout<<endl;
169     for(int n2=0; n2<m1; n2++) {
170         cout<<setiosflags(ios::left)<<setw(10)<<G.vertices[n2].data1;
171         for(int n3=0; n3<m1; n3++) {
172             cout<<setiosflags(ios::left)<<setw(10)<<arr[n2][n3];
173 
174         }
175         cout<<endl;
176 
177 
178     }
179 
180 
181 }
182 
183 bool visited[MAX];
184 stack<int> *s=new stack<int>();
185 
186 bool isOver(ALGraph G,bool a[MAX]) {
187     for(int i=0; i<G.vexnum; i++) {
188         if(a[i]!=1) {
189             return false;
190         }
191     }
192     return true;
193 
194 
195 }
196 
197 void DFSTraverse(ALGraph G)
198 {
199     bool sta[20];
200     int v;
201     for (v = 0; v<G.vexnum; v++)
202     {
203         sta[v] =true;
204     }
205      stack<int>status;
206      int n=0;
207      int num = -1;
208      int pk;
209      ArcNode *e;
210      cout << G.vertices[0].data1 << "->";
211      sta[0] =false;
212      status.push(0);
213      int aa, bb;
214      aa = 0;
215 
216      while (n < G.vexnum-1){
217          e = NULL;
218          num = status.top();
219          e = G.vertices[num].firstarc;
220          while (e){
221              if (sta[e->adjvex] == false){
222                  e = e->nextarc;
223              }
224              else{
225                  status.push(e->adjvex);
226                  cout << G.vertices[e->adjvex].data1<<"->";
227                  aa = e->adjvex;
228                  sta[e->adjvex] = false;
229                  n++;
230                  break;
231              }
232                  }
233          if (e == NULL){
234              pk = status.top();
235              bb = pk;
236              if (aa != bb){
237                  cout << G.vertices[pk].data1<<"->";
238              }
239             
240              status.pop();
241          }
242          if (status.top() == 0){
243              cout << G.vertices[0].data1 << "->";
244          }
245      }
246      cout << endl;
247 }
248 
249 bool IsEdge(ALGraph G) {
250     string s1, s2;
251     cin>>s1>>s2;
252     int iA=LocateVex(G,s1);
253     int jA=LocateVex(G,s2);
254 
255     ArcNode *p=G.vertices[iA].firstarc;
256     while(p) {
257         if(p->adjvex==jA) {
258             return 1;
259         } else {
260             p=p->nextarc;
261         }
262     }
263     return 0;
264 
265 
266 }
267 
268 int adjlist[MAX];
269 void FindInDegree( ALGraph &g) {
270     int i;
271     ArcNode *p;
272     for (i=0; i<g.vexnum; i++)
273         adjlist[i]=0;
274     for (i=0; i<g.vexnum; i++) {
275         p=g.vertices[i].firstarc;
276         while(p) {
277             adjlist[p->adjvex]++;
278             p=p->nextarc;
279         }
280     }
281 }
282 void JudgeCir(ALGraph G) {
283     FindInDegree(G);
284     int count=0;
285     int Q[MAX];
286     int front,rear,v;
287     front=rear=-1;
288     for(int i=0; i<G.vexnum; i++) {
289         if((adjlist[i]==0)||(adjlist[i]==1)) {
290             Q[++rear]=i;
291             count++;
292         }
293     }
294 
295     while(front!=rear) {
296         v=Q[++front];
297         if(adjlist[v]==1) {
298             adjlist[v]=-1;
299             for(int j=0; j<G.vexnum; j++) {
300                 if(arr[v][j]>0 && arr[v][j]<32767) {
301                     adjlist[j]--;
302                     if(adjlist[j]==1) {
303                         Q[++rear]=j;
304                         count++;
305                     }
306                 }
307             }
308         } else {
309             adjlist[v]=-1;
310         }
311     }
312 
313     if(count<G.vexnum) {
314         cout<<"圖中有迴路"<<endl;
315     } else
316         cout<<"圖中無迴路"<<endl;
317 }
318 
319 int in[MAX];
320 
321 void LocateVex2(ALGraph G, string v) {
322     for(int i = 0;i < MAX; i++)
323     {
324         in[i]=10000;
325     }
326     for(int i = 0;i < G.vexnum; i++)
327     {
328         if(G.vertices[i].data1.find(v)<G.vertices[i].data1.length() ||
329         G.vertices[i].data2.find(v)<G.vertices[i].data2.length())    
330         {
331             in[i]=i;
332         }
333     } 
334 }
335 
336 void Search(ALGraph G,string s) {
337     FindInDegree(G);
338     LocateVex2(G, s);
339     for(int i=0;i<G.vexnum;i++)
340     {
341         if(in[i]!=10000)
342         {
343             cout<<"您所要查詢的景點介紹爲:"<<endl
344                 <<endl<<"該景點名字是:"
345                 <<G.vertices[in[i]].data1
346                 <<" "<<endl
347                 <<"該景點介紹爲:"<<G.vertices[in[i]].data2<<endl
348                 <<"該景點歡迎度爲:"
349                 <<G.vertices[in[i]].wel<<endl<<"有無休息區爲:"
350                 <<G.vertices[in[i]].rest
351                 <<endl<<"有無廁所爲:"<<G.vertices[in[i]].wc
352                 <<endl<<endl;
353         }
354 
355     }
356 
357 }
358 
359 void SortWel(ALGraph G) {
360     int ary[G.vexnum];
361 
362     for(int i=0; i<G.vexnum; i++) {
363         ary[i]=G.vertices[i].wel;
364     }
365 
366     int i, j, tmp;
367     for(i=0; i<G.vexnum; i++) {
368         tmp = ary[i];
369         for(j=G.vexnum-1; j>i; j--) {
370             if(tmp < ary[j]) {
371                 ary[i] = ary[j];
372                 ary[j] = tmp;
373                 tmp = ary[i];
374             }
375         }
376     }
377 
378     for(int j=0; j<G.vexnum; j++) {
379         int m=LocateW(G,ary[j]);
380         cout<<j+1<<""<<G.vertices[m].data1<<endl;
381     }
382 }
383 
384 bool isInN(ALGraph G,int a[MAX],int n)
385 {
386     for(int i=0;i<G.vexnum;i++)
387     {
388         if(a[i]==n)
389         {
390             return true;
391         }
392     }
393     return false;
394 }
395 
396 void SortN(ALGraph G) {
397     int ary[G.vexnum];
398     int a[G.vexnum];
399 
400     for(int j=0; j<G.vexnum; j++) {
401         a[j]=10000;
402     }
403     
404     FindInDegree(G);
405     for(int i=0; i<G.vexnum; i++) {
406         ary[i]=adjlist[i];
407     }
408     
409     int i, j, tmp;
410     for(i=0; i<G.vexnum; i++) {
411         tmp = ary[i];
412         
413         for(j=G.vexnum-1; j>i; j--) {
414             if(tmp <= ary[j]) {
415                 a[i]=j;
416                 ary[i] = ary[j];
417                 a[i]=j;
418                 ary[j] = tmp;
419                 tmp = ary[i];
420             }    
421             
422             
423         }
424     }
425 
426     for(int j=0;j<G.vexnum;j++)
427     {
428         for(int i=0;i<G.vexnum;i++)
429         {
430             if(ary[j]==adjlist[i])
431             {
432                 if(!isInN(G,a,i))
433                 {
434                     a[j]=i;
435                 }
436                 else
437                 {
438                     continue;
439                 }
440             }
441         }
442     }    
443         for(int i=0;i<G.vexnum;i++)
444     {
445         cout<<i+1<<""<<G.vertices[a[i]].data1<<endl;
446     }
447 
448 
449 }
450 
451 void ShortestPath_DIJ(ALGraph G,int v0, int p[][MAX], int D[]) {
452     int v, w, i, j, min;
453     bool final[10];
454     for(v=0; v<G.vexnum; v++) {
455         final[v]=false;
456         D[v]=arr[v0][v];
457         for(w=0; w<G.vexnum; w++)
458             p[v][w]=-1;
459         if(D[v]<INFINITY) {
460             p[v][0]=v0;
461             p[v][1]=v;
462         }
463     }
464 
465     D[v0]=0;
466     final[v0]=true;
467 
468     for(i=1; i<G.vexnum; i++) {
469         min=INFINITY;
470         for(w=0; w<G.vexnum; w++)
471             if(!final[w] && D[w]<min) {
472                 v=w;
473                 min=D[w];
474             }
475         final[v]=true;
476         for(w=0; w<G.vexnum; w++) {
477             if(!final[w] && min<INFINITY && arr[v][w]<INFINITY
478              && (min+arr[v][w]<D[w])) {
479                 D[w]=min+arr[v][w];
480                 for(j=0; j<G.vexnum; j++) {
481                     p[w][j]=p[v][j];
482                     if(p[w][j]==-1) {
483                         p[w][j]=w;
484                         break;
485                     }
486                 }
487 
488             }
489         }
490     }
491 }
492 
493 bool isInVe(ALGraph G,string va)
494 {
495     for(int i=0;i<G.vexnum;i++)
496     {
497         if(G.vertices[i].data1==va)
498         {
499             return true;
500         }
501     }
502     return false;
503 }
504 
505 void printShortestPath(ALGraph G)
506 {
507     
508     int iA,jA;
509     string s1,s2;
510     int p[MAX][MAX];
511     int D[MAX];
512     cout<<"請輸入要查詢距離的兩個景點的名稱:";
513     cin>>s1>>s2;
514     if(isInVe(G,s1) && isInVe(G,s2))
515     {
516         iA=LocateVex(G,s1);
517         jA=LocateVex(G,s2);
518         ShortestPath_DIJ(G,iA, p, D);
519         cout<<"到各頂點的最短路徑及長度爲:"<<endl;
520         
521         if(jA!=0 && D[jA]!=INFINITY) {
522             cout<<"最短路徑爲:";
523             for(int j=0; j<G.vexnum; j++) {
524                 if(p[jA][j]>-1)
525                     cout<<G.vertices[p[jA][j]].data1
526                         <<" ";
527                 }
528                 cout<<endl;
529                 cout<<"最短距離爲:"<<D[jA];
530         } else if(D[jA]==INFINITY)
531                     cout<<G.vertices[iA].data1<<"-"
532                     <<G.vertices[jA].data1
533                     <<":"<<"不可達"<<endl;    
534     }
535     else
536     {
537         cout<<"您輸入的景點名稱不存在,請輸入正確的景點名稱:"<<endl;
538         printShortestPath(G);
539     }
540 
541  } 
542  
543 void prim(ALGraph G,int v,double arr[MAX][MAX]) {
544 
545     int lowcost[MAX];
546     int min;
547     int closest[MAX],i,j,k;
548     for(i=0; i<G.vexnum; i++) {
549         lowcost[i]=arr[v][i];
550         closest[i]=v;
551     }
552     for(i=1; i<G.vexnum; i++) {
553         min=INFINITY;
554         for(j=0; j<G.vexnum; j++) {
555             if(lowcost[j]!=0&&lowcost[j]<min) {
556                 min=lowcost[j];
557                 k=j;
558             }
559         }
560         cout<<""<<G.vertices[closest[k]].data1<<""
561         <<G.vertices[k].data1<<"修一條路"<<endl;
562         lowcost[k]=0;
563 
564         for(j=0; j<G.vexnum; j++) {
565             if(arr[k][j]!=0 && arr[k][j]<lowcost[j]) {
566                 lowcost[j]=arr[k][j];
567                 closest[j]=k;
568             }
569         }
570 
571     }
572 }   
573    
574 stack<zanlind> parking;  
575 stack<zanlind> cars;  
576 queue<zanlind> waits;
577 int z[MAX2];
578 bool isInZan(int zan[],int number)
579 {
580     for(int i=0;i<MAX2;i++)
581     {
582         if(zan[i]==number)
583         {
584             return true;
585         }
586     }
587     return false;
588 }
589 
590 int indexZ(int z[],int n)
591 {
592     for(int i=0;i<MAX2;i++)
593     {
594         if(z[i]==n)
595         {
596             return i;
597         }
598     }
599     return -1;
600 }
601 void goIn()
602 {
603     int k1=0;
604     zanlind zan;
605     cout<<"車牌號爲:";
606     cin>>zan.number;
607     cout<<endl;
608     /*
609     time_t t = time(0);
610     char tmp[64]; 
611     strftime(tmp,sizeof(tmp),"%X ",localtime(&t));
612     zan.time=tmp;
613     */
614     struct tm *newtime;
615     time_t long_time;
616     time( &long_time ); //Get time as long integer
617     newtime = localtime( &long_time ); 
618     int h = newtime->tm_hour;//獲得當前時間的小時
619     int m = newtime->tm_min;//獲得當前時間的分鐘
620     zan.hour=h;
621     zan.minute=m;
622     
623     
624     cout<<"進場時間爲:";
625     if(zan.minute>=1 && zan.minute<10)
626     {
627         cout<<zan.hour<<":0"<<zan.minute<<endl;
628     }
629     else
630     {
631         cout<<zan.hour<<":"<<zan.minute<<endl;
632     }
633     
634     
635     if(parking.size()<MAX2)
636     {
637         for(int m=0;m<MAX2;m++)
638         {
639             if(z[m]==0)
640             {
641                 z[m]=zan.number;
642                 break;
643             }
644         }
645         parking.push(zan);
646         cout<<"該車已進入停車場在: "<<k1++<<"號車道";    
647     }
648     else
649     {
650         cout<<"停車場已滿,請等待其餘車輛離開:"; 
651         waits.push(zan);
652     }
653 }
654 
655 void goOut()
656 {
657     if(parking.size()<=0)
658     {
659         cout<<"停車場爲空,沒有車要離開!";
660     }
661     else 
662     {
663         cout<<"請輸入您的車牌號:";
664         int number;
665         cin>>number;
666         if(isInZan(z,number))
667         {
668             while(parking.top().number!=number)
669             {
670                 cars.push(parking.top());
671                 parking.pop();
672             }
673             
674             int num=indexZ(z,parking.top().number);
675             z[num]=0;
676             /*
677             time_t t = time(0);
678               char tmp[64]; 
679               strftime(tmp,sizeof(tmp),"%X ",localtime(&t));
680               */
681               struct tm *newtime;
682             time_t long_time;
683             time( &long_time ); //Get time as long integer
684             newtime = localtime( &long_time ); 
685             int h = newtime->tm_hour;//獲得當前時間的小時
686             int m = newtime->tm_min;//獲得當前時間的分鐘
687               cout<<"車牌號爲:"<<parking.top().number<<"的車要離開了"<<endl
688               <<"停車時間爲: "
689               <<(h*60+m)-(parking.top().hour*60+parking.top().minute)<<"分鐘"<<endl
690               <<"停車費用爲:"
691               <<((h*60+m)-(parking.top().hour*60+parking.top().minute))*5<<""<<endl; 
692                   parking.pop();
693               
694               while(!cars.empty()) 
695               {
696                   parking.push(cars.top());
697                 cars.pop();    
698             }
699             
700             while(parking.size()<MAX2)
701             {
702                 if(waits.size()!=0)
703                 {    
704                     for(int m=0;m<MAX2;m++)
705                     {
706                         if(z[m]==0)
707                         {
708                             z[num]=waits.front().number;
709                         }
710                     }
711                     parking.push(waits.front());        
712                     waits.pop();
713                 }
714                 else
715                 {
716                     break;
717                 }
718 
719             } 
720         }    
721         
722         else
723         {
724             cout<<"沒有該輛車!請輸入正確的車牌號:"<<endl;    
725         }                
726         
727     }
728         
729 }
730 
731 void parkinglot()
732 {
733     r2:
734         cout<<endl<<"            **停車場管理程序**          "<<endl
735         <<"--------------------------------------------------"<<endl
736         <<"**"
737         <<"** A---汽車進車場  D---汽車出車場  E---退出程序 **"<<endl 
738         <<"--------------------------------------------------"<<endl
739         <<"請選擇:<A ,D ,E>:";
740         char choose;
741         cin>>choose;
742         if(choose=='A' || choose=='D' || choose=='E')
743         {
744             switch(choose)
745             {
746                 case 'A':
747                     goIn(); 
748                     goto r2;
749                 case 'D':
750                     goOut();
751                     goto r2;
752                 case 'E':
753                     break;
754                 }
755         }
756         else
757         {
758             cout<<"您的輸入有誤,請輸入  <A D E>  其中的一項。";
759             goto r2;
760         }
761 }
762 
763 int main() {
764     int i, j;
765     int iAA;
766     ALGraph *G=new ALGraph();
767     int choose=0;
768     cout<<endl;
769     
770     while(true) {
771 r:
772         cout<<"------------------------------------------"<<endl
773             <<"          歡迎使用景區信息管理系統        "<<endl
774             <<"              ***請選擇菜單***            "<<endl
775             <<"------------------------------------------"<<endl
776             <<"   一、建立景區景點分佈圖                  "<<endl
777             <<"   二、輸出景區景點分佈圖                  "<<endl
778             <<"   三、輸出導遊線路圖                      "<<endl
779             <<"   四、輸出導遊線路圖的迴路                "<<endl
780             <<"   五、查找及排序                          "<<endl
781             <<"   六、求兩個景點間的最短路徑和最短距離    "<<endl
782             <<"   七、輸出道路修建規劃圖                  "<<endl
783             <<"   八、停車場車輛進出記錄信息              "<<endl
784             <<"   0、退出系統                            "<<endl
785             <<"請輸入您要選擇的菜單項: ";
786             
787         cin>>choose;
788         
789         if(choose<=8 && choose>=0) {
790             if(choose>1 && G->vexnum==0 &&choose!=8) {
791                 cout<<endl<<"************您的圖爲空,請先建立您的圖**********:"
792                 <<endl<<endl;
793                 goto r;
794             } else {
795                 switch(choose) {
796 
797                     case 1:
798                         CreateUDN(*G);
799 
800                         break;
801                     case 2:
802                         PrintAdjList(*G);
803                         cout<<endl;
804                         OutputGraph(*G);
805                         break;
806                     case 3:
807                         cout<<"導遊路線爲:";
808                         //CreatTourSortGraph(*G);
809                         //DFSTraverse(*G);
810                         break;
811                     case 4:
812                         JudgeCir(*G);
813                         break;
814                     case 5:
815                         
816                     while(true)
817                     {
818                         int ch;
819                         cout<<"您須要"
820                             <<"  查找(0),"
821                             <<"按歡迎度排序(1),"
822                             <<"按景點岔路數排序(2),"
823                             <<"退出此目錄(3) :" ;
824                         cin>>ch;
825                         string sA;
826                         switch(ch)
827                         {
828                             case 0:
829                                 cout<<"請輸入您要查找的有關景點的關鍵字:" ;
830                                 cin>>sA;
831                                 Search(*G,sA);
832                                 break;
833                             case 1:
834                                 SortWel(*G);
835                                 break;
836                             case 2:
837                                 SortN(*G);
838                                 break;
839                             case 3:
840                                 goto r;
841                             default :
842                                 cout<<"您的輸入有誤,請從新輸入:"<<endl;
843                         }
844                     }
845                     case 6:    
846                         printShortestPath(*G);
847                         break;
848                     case 7:
849                         prim(*G,0,arr);
850                         break;
851                     case 8:
852                         parkinglot();
853                         break;
854                     case 0:
855                         exit(0);
856                 }
857 
858             }
859             cout<<endl;
860         }
861         else {
862             cout<<"您的輸入有誤,請從新輸入0-8之間的數字"<<endl;
863 
864         }
865 
866 
867     }
868     return 0;
869 }
870  

 

所須要的兩個edge.txt和info.txt文件。(很重要、必定要有!!!)

 

相關文章
相關標籤/搜索