大二上学期做的不入眼的导航系统。
生活随笔
收集整理的這篇文章主要介紹了
大二上学期做的不入眼的导航系统。
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
大二上學期,數據結構老師說要讓我們做一個課程設計,記得是從民航管理系統、導航系統、和電話管理系統三個系統里選擇其中一個,而我就因為看會了floyd,就決定寫寫導航系統把,事實并沒有非常熟練地掌握,一拖再拖之后到現在也不是太明白,大二第二學期剛考完試,我決定把以前沒有掌握的知識再復習一遍。
話不多說直接上圖:
對你們沒有看錯,我就是做了這樣一個只有黑框框的程序,實際上他就是沒有什么實際價值,因為我將平度(一個縣級市)的每個地區抽象成每個點,而現實世界上這個點是一塊區域
,根本與現實結合不起來,如果要做一個真正能用的導航系統,估計要用到定位系統吧,這一點也不是太清楚,在這里筆者只跟大家談論這個算法和這個程序。
?
沒啥說的了直接上程序代碼吧
1 #include<bits/stdc++.h> 2 #include<windows.h>3 using namespace std; 4 const int maxN=35,INF=5e5,MAX=30; 5 int G[maxN][maxN]; 6 int path[maxN][maxN]; 7 map<int,string>information,maping; 8 queue<int>way,nearby; 9 void initinformation(){ 10 information[1]="這里是本市的一個特色地區"; 11 information[2]="北接大澤,東鄰崮山,最高峰海拔560米。占地面積約10平方公里。"; 12 information[3]="三合山,因由三座東西向連接而又各自獨立的山峰組成而得名。"; 13 information[4]="因“孤峰秀峙、高冠霄星、拔地而起、如柱擎天”而得名。"; 14 information[5]="北有廓落崮,背北面南;左有石山,鰲山蜿蜒向前;右有長嶺環繞西南,似一顆明珠鑲嵌其中。"; 15 information[6]="是國家農業部命名的首家“中國葡萄之鄉”。"; 16 information[7]="是近幾年剛建的景區,2008年開始投資建成占地300多畝的青島盛躍農業科技生態園區。"; 17 information[8]="云山境內有名山,曰云山,云山上有古觀,曰云山觀。"; 18 information[9]="山映水波,秀麗如畫;遠處煙籠四野,霧漫湖面,為一勝景。"; 19 information[0]="由三座東西向連接而又各自獨立的山峰組成而得名。"; 20 } 21 void init(){ 22 printf("\t\t|\t N \t|\t\t\n"); 23 printf("\t\t|\t _ _ _ _ _ _ _ _ _ _ _ _ _ __ _ __ _ _ _ /|\\ \t|\t\t\n"); 24 printf("\t\t|\t _ _ _ _ _ _ _ _ _ _ __ _ __ _ _ _ | \t|\t\t\n"); 25 printf("\t\t|\t /1.新 |-----/3.長樂鎮) /4.大澤山鎮 /5.大 \\_ _ _ \t|\t\t\n"); 26 printf("\t\t|\t \\ 河鎮 |2.灰埠鎮/ 13. \\ / 田 \\6.舊店鎮\\ \t|\t\t\n"); 27 printf("\t\t|\t \\---------- \\ 店子鎮 \\ / 鎮 \\------- \t|\t\t\n"); 28 printf("\t\t|\t \\ 14.張舍鎮 --------- \\| 10.| ------- | /7.祝溝鎮 \t|\t\t\n"); 29 printf("\t\t|\t // -------/------| 12.門村 | | 城 | 9.崔昭 |----------- | \t|\t\t\n"); 30 printf("\t\t|\t \\16.馬戈莊鎮 / 15.田莊 | 鎮 |11.| 關 | 鎮 | 8.云山鎮 | \t|\t\t\n"); 31 printf("\t\t|\t ------------ 鎮 |-----| 李園---| /// / ------------ \t|\t\t\n"); 32 printf("\t\t|\t \\ 17.民村鎮 \\ ------- 19. | -----------|21.麻蘭鎮 / 22. \\ \t|\t\t\n"); 33 printf("\t\t|\t \\ -------- 18.白埠| 同和 |-----| 20.香店 |- - - - - 古峴鎮\\ \t|\t\t\n"); 34 printf("\t\t|\t \\ 29.崔 \\ 鎮 |-- 30.琴蘭鎮 |----- 24.張戈莊 | 23.仁\\ \t|\t\t\n"); 35 printf("\t\t|\t \\ 家 \\ / /28.萬/----------//--- 25. ----- \\ 兆 \\ \t|\t\t\n"); 36 printf("\t\t|\t \\ 集 \\ 家 / 27. // 26. \\ 郭莊 \\ ------- \t|\t\t\n"); 37 printf("\t\t|\t \\ 鎮 \\ 鎮 / 藍底鎮 // 南 \\ -------- \t|\t\t\n"); 38 printf("\t\t|\t ------ - ---- - ----// 村 \\ \t|\t\t\n"); 39 printf("\t\t|\t \\ 鎮 \\ \t|\t\t\n"); 40 printf("\t\t|\t ---- \t|\t\t\n"); 41 } 42 void floy(){ 43 memset(path,-1,sizeof(path)); 44 for(int k=1;k<=MAX;k++) 45 for(int i=1;i<=MAX;i++) 46 for(int j=1;j<=MAX;j++){ 47 if(G[i][k]+G[k][j]<G[i][j]){ 48 G[i][j]=G[i][k]+G[k][j]; 49 path[i][j]=k; 50 } 51 } 52 } 53 54 void get_way(int s,int e){ 55 if(path[s][e]!=-1){ 56 get_way(s,path[s][e]); 57 get_way(path[s][e],e); 58 } 59 else way.push(e); 60 } 61 void initmapping(){ 62 maping[ 1]="新河鎮" ;maping[ 2]="灰埠鎮" ;maping[ 3]="長樂鎮" ;maping[ 4]="大澤山鎮" ; 63 maping[ 5]="舊店鎮" ;maping[ 6]="大田鎮" ;maping[ 7]="祝溝鎮" ; 64 maping[ 8]="云山鎮" ;maping[ 9]="崔昭鎮" ;maping[ 10]="城關" ;maping[ 11]="李園" ; 65 maping[ 12]="門村鎮" ;maping[ 13]="店子鎮" ;maping[ 14]="張舍鎮" ;maping[ 15]="田莊鎮" ; 66 maping[ 16]="馬戈莊鎮" ;maping[ 17]="民村鎮" ;maping[ 18]="白埠鎮";maping[ 19]="同和"; 67 maping[ 20]="香店";maping[ 21]="麻蘭鎮" ;maping[ 22]="古峴鎮" ;maping[ 23]="仁兆鎮" ; 68 maping[ 24]="張戈莊鎮" ;maping[ 25]="郭莊鎮" ;maping[ 26]="南村鎮" ;maping[ 27]="蘭底鎮" ; 69 maping[ 28]="萬家鎮";maping[ 29]="崔家集鎮" ;maping[ 30]="琴蘭鎮" ; 70 } 71 72 void initG() 73 { 74 memset(G,INF,sizeof(G)); 75 for(int i=1;i<=MAX;i++)G[i][i]=0; 76 G[1][2]=G[2][1]=10;G[1][14]=G[14][1]=30;G[2][3]=G[3][2]=15;G[2][13]=G[13][2]=25; 77 G[2][13]=G[13][2]=40;G[3][4]=G[4][3]=5;G[3][13]=G[13][3]=9;G[4][5]=G[5][4]=14; 78 G[4][13]=G[13][4]=8;G[4][9]=G[9][4]=19;G[5][9]=G[9][5]=10;G[5][6]=G[6][5]=8; 79 G[5][7]=G[7][5]=6;G[5][8]=G[8][5]= 16;G[6][7]=G[7][6]= 2;G[7][8]=G[8][7]= 3; 80 G[8][9]=G[9][8]=14;G[8][21]=G[21][8]=14;G[8][22]=G[22][8]=13;G[9][13]=G[13][9]=40; 81 G[9][10]=G[10][9]=6;G[9][20]=G[20][9]=9;G[9][21]=G[21][9]=14;G[10][13]=G[13][10]=21; 82 G[10][11]=G[11][10]=3;G[10][20]=G[20][10]=5;G[11][13]=G[13][11]=10;G[11][12]=G[12][11]=3; 83 G[11][19]=G[19][11]=6;G[11][20]=G[20][11]=10;G[12][13] =G[13][12]=20;G[12][14] =G[14][12]=21; 84 G[12][15]=G[15][12]=8;G[12][18]=G[18][12]=22;G[12][19]=G[19][12]=30;G[13][14]=G[14][13]= 6; 85 G[14][16]=G[16][14]=11;G[14][15]=G[15][14]=7;G[15][16]=G[16][15]=9;G[15][17]=G[17][15]= 10; 86 G[15][18]=G[18][15]=13;G[16][17]=G[17][16]=21;G[17][18]=G[18][17]=31;G[17][29]=G[29][17]= 40; 87 G[18][19]=G[19][18]=11;G[18][29]=G[29][18]=30;G[18][30]=G[30][18]=11;G[19][20]=G[20][19]= 4; 88 G[19][30]=G[30][19]=7;G[20][21]=G[21][20]= 3;G[20][24]=G[24][20]= 9;G[20][30] =G[30][20]=17; 89 G[21][22]=G[22][21]=7;G[21][24]=G[24][21]= 9;G[22][23]=G[23][22]= 18;G[23][24]=G[24][23]= 7; 90 G[23][25]=G[25][23]=4;G[23][26]=G[26][23]= 20;G[24][30]=G[30][24]= 38;G[24][25] =G[25][24]=4; 91 G[24][28]=G[28][24]=36;G[24][27]=G[27][24]=30;G[25][27]=G[27][25]= 14;G[25][26]=G[26][25]= 17; 92 G[26][27]=G[27][26]=7;G[27][28]=G[28][27]= 19;G[28][29]=G[29][28]= 35;G[28][30]=G[30][28]= 14;G[29][30]=G[30][28]=15; 93 } 94 void show(){ 95 system("cls"); 96 printf("\t\t|\t \t|\t\t\n"); 97 printf("\t\t|\t 平度智能導游 :小浩人 \t|\t\t\n"); 98 printf("\t\t|\t \t|\t\t\n"); 99 printf("\t\t|\t 走進平度,不會迷路,小浩人為你服務 \t|\t\t\n"); 100 printf("\t\t|\t \t|\t\t\n"); 101 printf("\t\t|\t 1.地圖一覽 \t|\t\t\n"); 102 printf("\t\t|\t \t|\t\t\n"); 103 printf("\t\t|\t 2.查詢地區信息 \t|\t\t\n"); 104 printf("\t\t|\t \t|\t\t\n"); 105 printf("\t\t|\t 3.智能問路系統 \t|\t\t\n"); 106 printf("\t\t|\t \t|\t\t\n"); 107 printf("\t\t|\t 4.查找附近的地區 \t|\t\t\n"); 108 printf("\t\t|\t \t|\t\t\n"); 109 printf("\t\t|\t 5.退出系統 \t|\t\t\n"); 110 printf("\t\t|\t \t|\t\t\n"); 111 printf("\t\t|\t \t|\t\t\n"); 112 printf("\t\t|\t \t|\t\t\n"); 113 printf("\t\t|請按1~5鍵進行選擇操作\t \t|\t\t\n"); 114 printf("\t\t|\t 本程序最終解釋權歸隨風風衣所有|\n"); 115 } 116 void process(){ 117 for(int i=1;i<=4;i++){ 118 system("cls"); 119 printf("小浩人正在計算"); 120 for(int j=1;j<=4;j++){ 121 Sleep(100); 122 printf("."); 123 } 124 } 125 system("cls"); 126 } 127 void errorhanding(){ 128 printf("輸入錯誤,請重新輸入:\n"); 129 } 130 void print(){ 131 char order; 132 system("cls"); 133 printf("\t\t|\t \t|\t\t\n"); 134 printf("\t\t|\t 小浩人辛辛苦苦把地圖畫在了終端對話框中 \t|\t\t\n"); 135 init(); 136 printf("看不清小浩人畫的地圖,可以按O(字母)鍵打開地圖圖片,看明白了想返回主界面按回車鍵返回主界面:\n"); 137 order=getchar(); 138 if(order=='O'||order=='o')system("D:\map.jpg"); 139 if(!(order=='O'||order=='o')){ 140 system("cls"); 141 show(); 142 } 143 else{ 144 getchar(); 145 system("cls"); 146 show(); 147 } 148 149 } 150 void init_demand(int num){ 151 152 printf(" \n"); 153 printf("_________________________\n"); 154 printf("| |\n"); 155 cout<<"| "<<num<<maping[num]<<" | "<<information[rand()%10]<<endl; 156 printf("| |\n"); 157 printf("|________________________|\n"); 158 159 } 160 void demand(){ 161 char order; 162 system("cls"); 163 int num; 164 init(); 165 printf("請您輸入你要查詢地區的標號:\n"); 166 scanf("%d",&num); 167 init_demand(num); 168 printf("是否要繼續查詢 Y/N:\n"); 169 getchar();//接受num的回車 170 scanf("%c",&order); 171 getchar(); 172 173 if(order=='N'||order=='n'){ 174 show(); 175 return; 176 } 177 else demand(); 178 } 179 void seekpaths(){ 180 int Begin,End; 181 system("cls"); 182 init(); 183 printf("請輸入你現在所在的位置的編號:\n"); 184 scanf("%d",&Begin); 185 cout<<"您輸入的地點是:"<<maping[Begin]<<endl; 186 printf("請您輸入你要去的位置的編號:\n"); 187 scanf("%d",&End); 188 getchar(); 189 cout<<"您輸出的終點是:"<<maping[End]<<endl; 190 printf("按回車鍵,小浩人就要開始算了:\n"); 191 getchar(); 192 process(); 193 printf("\n\n\n"); 194 cout<<" 小浩人 經過詳細地計算,您開始的地點是 "<<maping[Begin]<<" 您結束的地點是 " 195 <<maping[End]<<" ,全程一共 "<<G[Begin][End]<<" 公里\n\n\n"; 196 printf("具體路徑為:\n\n"); 197 way.push(Begin); 198 get_way(Begin,End); 199 printf("Begin:\n\n"); 200 printf(" "); 201 202 cout<<maping[way.front()]; 203 way.pop(); 204 while(!way.empty()){ 205 cout<<"————>>"<<maping[way.front()]; 206 way.pop(); 207 } 208 printf("\n\n\n"); 209 210 printf("按回車鍵返回主菜單:\n"); 211 getchar(); 212 system("cls"); 213 show(); 214 } 215 void seeks(){ 216 system("cls"); 217 init(); 218 int order,m; 219 printf("請您輸入你所在位置的編號:\n"); 220 scanf("%d",&order); 221 cout<<"您輸入的地點是 "<<maping[order]<<"。\n"; 222 printf("請您輸入公里數,在這個距離能夠到達的地點:\n"); 223 scanf("%d",&m); 224 getchar(); 225 printf("按回車鍵,小浩人就要開始算了:\n"); 226 getchar(); 227 for(int i=1;i<=30;i++) 228 if(G[order][i]!=0&&G[order][i]<=m)nearby.push(i); 229 process(); 230 printf("\n\n\n"); 231 cout<<"小浩人經過詳細地計算,您開始的地點是 "<<maping[order]<<" 在"<<m 232 <<"公里內,能夠到達以下地點"<<endl<<endl<<endl; 233 while(!nearby.empty()){ 234 cout<<nearby.front()<<". "<<maping[nearby.front()]<<" 距離:"<<G[order][nearby.front()]<<"公里"<<endl; 235 nearby.pop(); 236 } 237 char order_; 238 printf("是否要繼續查詢 Y/N:\n"); 239 //接受m的回車 240 scanf("%c",&order_); 241 getchar(); 242 if(order_=='N'||order_=='n'){ 243 show(); 244 return; 245 } 246 else seeks(); 247 } 248 void exits(){ 249 printf("期待與你下次相見 bey bey~"); 250 printf("\n\t\t\t\t (按回車鍵確認退出)\n"); 251 getchar(); 252 exit(0); 253 } 254 void changecolor(){ 255 Sleep(100); 256 system("color 0B"); 257 Sleep(100); 258 system("color 01"); 259 Sleep(100); 260 system("color 0C"); 261 Sleep(100); 262 system("color 03"); 263 Sleep(100); 264 system("color 06"); 265 Sleep(100); 266 system("color 02"); 267 Sleep(100); 268 system("color 0F"); 269 } 270 int main(){ 271 //system("mode con cols=120 lines=30"); 272 show(); 273 initG(); 274 floy(); 275 initmapping();//初始對應信息(城市編號) 276 initinformation();//初始化城市信息 277 changecolor(); 278 char order; 279 while(scanf("%c",&order)==1){ 280 getchar(); 281 switch (order) 282 { 283 case '1':print();break; 284 case '2':demand();break;//查詢地點信息 285 case '3':seekpaths();break; 286 case '4':seeks();break;//查詢給定距離的地點 287 case '5':exits();break; 288 default:errorhanding(); 289 } 290 } 291 process(); 292 return 0; 293 }
?
?
轉載于:https://www.cnblogs.com/suifengfengyi/p/11137177.html
總結
以上是生活随笔為你收集整理的大二上学期做的不入眼的导航系统。的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SpringBoot+layUI上传图片
- 下一篇: session、token、jwt、oa