您好,登錄后才能下訂單哦!
這篇文章主要介紹“C++如何實(shí)現(xiàn)校園導(dǎo)游系統(tǒng)”,在日常操作中,相信很多人在C++如何實(shí)現(xiàn)校園導(dǎo)游系統(tǒng)問(wèn)題上存在疑惑,小編查閱了各式資料,整理出簡(jiǎn)單好用的操作方法,希望對(duì)大家解答”C++如何實(shí)現(xiàn)校園導(dǎo)游系統(tǒng)”的疑惑有所幫助!接下來(lái),請(qǐng)跟著小編一起來(lái)學(xué)習(xí)吧!
問(wèn)題描述:設(shè)計(jì)一個(gè)校園導(dǎo)游程序,完成校園信息的維護(hù)以及為來(lái)訪的客人提供信息查詢等服務(wù)功能。
設(shè)計(jì)學(xué)校的校園平面圖,所含景點(diǎn)不少于10個(gè),以圖中頂點(diǎn)表示校內(nèi)各景點(diǎn),頂點(diǎn)的信息包括:景點(diǎn)名稱、代號(hào)、簡(jiǎn)介等,以邊表示道路,邊上信息包括:兩點(diǎn)距離、所需時(shí)間等相關(guān)信息。(注:數(shù)據(jù)的輸入可以是鍵盤(pán)輸入或文件輸入兩種方式)
提供對(duì)校園景點(diǎn)信息的編輯(如:添加、刪除、修改等)的功能;
為來(lái)訪客人提供圖中任意景點(diǎn)相關(guān)信息的查詢(可提供多種查詢方式);
為來(lái)訪客人提供從校門(mén)口到圖中任意景點(diǎn)的問(wèn)路查詢(最短路徑);
為來(lái)訪客人提供圖中任意景點(diǎn)間的問(wèn)路查詢。
#include<iostream> using namespace std; int main() { int n; const int MAX=1000; static int r [MAX][MAX]={ {0,100,20,200,MAX,MAX,MAX,MAX,MAX,MAX}, {100,0,MAX,80,MAX,MAX,MAX,90,MAX,MAX}, {20,MAX,0,MAX,MAX,MAX,200,MAX,MAX,MAX}, {200,80,MAX,0,40,MAX,MAX,70,MAX,50}, {MAX,MAX,MAX,40,0,300,MAX,MAX,MAX,60}, {MAX,MAX,MAX,MAX,300,0,50,MAX, MAX,MAX}, {MAX,MAX,200,MAX,MAX,50,0,MAX,MAX,400}, {MAX,90,MAX,70,MAX,MAX,MAX,0,50,50}, {MAX,MAX,MAX,MAX,MAX,MAX,MAX,50,0,70}, {MAX,MAX,MAX,50,60,MAX,400,50,70,0} }; struct vertex {string name; int number; string introduction; }ver[MAX]={ {"校門(mén)",0,"學(xué)校主校門(mén)"}, {"體育場(chǎng)",1,"學(xué)校舉辦體育活動(dòng)的地方"}, {"六號(hào)公寓",2,"校內(nèi)學(xué)生宿舍"}, {"沉思廣場(chǎng)",3,"大草地"}, {"知源亭",4,"小亭子"}, {"圖書(shū)館",5,"書(shū)的棲息地"}, {"綜合實(shí)驗(yàn)樓",6,"實(shí)驗(yàn)室云云"}, {"大學(xué)會(huì)館",7,"舉辦會(huì)議和活動(dòng)的地方"}, {"鵬遠(yuǎn)公寓",8,"鵬遠(yuǎn)學(xué)生宿舍"}, {"工學(xué)館",9,"主教樓"} }; int b; for(b=0;b<1000;b++) { cout<<"|-----------------------------------------------------------------------------|"<<endl; cout<<"| 歡迎來(lái)到校園導(dǎo)游系統(tǒng) |"<<endl; cout<<"| 1.管理員登陸 |"<<endl; cout<<"| 2.游客登錄 |"<<endl; cout<<"| 3.退出校園導(dǎo)游系統(tǒng) |"<<endl; cout<<"|-----------------------------------------------------------------------------|"<<endl; cout<<"校園導(dǎo)游圖:"<<endl; cout<<" 8----------9--------------------------"<<endl; cout<<" | /|| | "<<endl; cout<<" | ---/ | | | "<<endl; cout<<" | / | --- | "<<endl; cout<<" 7 | | | "<<endl; cout<<" | | | | | "<<endl; cout<<" | | | | | "<<endl; cout<<" | ---3-------4--------------5 | "<<endl; cout<<" | ---/| | | "<<endl; cout<<" | / | || "<<endl; cout<<" 1 | ------- 6 "<<endl; cout<<" | | / "<<endl; cout<<" | | ------------ "<<endl; cout<<" | | / "<<endl; cout<<" | | / "<<endl; cout<<" | | 2 "<<endl; cout<<" |/ "<<endl; cout<<" 0 "<<endl; cout<<"景點(diǎn)編號(hào):"<<endl; cout<<"0.校門(mén) 1.體育場(chǎng)"<<endl; cout<<"2.六號(hào)公寓 3.沉思廣場(chǎng)"<<endl; cout<<"4.知源亭 5.圖書(shū)館"<<endl; cout<<"6.綜合實(shí)驗(yàn)樓 7.大學(xué)會(huì)館"<<endl; cout<<"8.鵬遠(yuǎn)公寓 9.工學(xué)館"<<endl; cout<<"請(qǐng)按對(duì)應(yīng)數(shù)字選擇您操作:"; cin>>n; if(n==1) { cout<<"|-----------------------------------------------------------------------------|"<<endl; cout<<"| 管理員您好,歡迎來(lái)到校園導(dǎo)游系統(tǒng) |"<<endl; cout<<"| 1.添加校園景點(diǎn)信息 |"<<endl; cout<<"| 2.刪除校園景點(diǎn)信息 |"<<endl; cout<<"| 3.修改校園景點(diǎn)信息 |"<<endl; cout<<"|-----------------------------------------------------------------------------|"<<endl; cout<<"請(qǐng)輸入您將要進(jìn)行的編輯操作編號(hào):"; int a; cin>>a; if(a==1){ cout<<"請(qǐng)輸入你將要添加的校園景點(diǎn)編號(hào):"; int m; cin>>m; ver[m].number=m; cout<<"請(qǐng)輸入你將要添加的校園景點(diǎn)的名稱:"; string x; cin>>x; ver[m].name=x; cout<<"請(qǐng)輸入你將要添加的校園景點(diǎn)的介紹:"; string y; cin>>y; ver[m].introduction=y; cout<<"添加成功~" <<endl; } if(a==2){ cout<<"請(qǐng)輸入你將要?jiǎng)h除的校園景點(diǎn)編號(hào):"; int m; cin>>m; ver[m]=ver[MAX-1]; cout<<"刪除成功~"<<endl; } if(a==3){ cout<<"請(qǐng)輸入你將要修改的校園景點(diǎn)編號(hào):"; int m; cin>>m; cout<<"你將要修改的景點(diǎn)信息如下:"<<endl; cout<<"景點(diǎn)名稱:"<<ver[m].name<<endl; cout<<"景點(diǎn)介紹:"<<ver[m].introduction<<endl; cout<<"請(qǐng)輸入修改后的景點(diǎn)名稱:"; string x; cin>>x; ver[m].name=x; cout<<"請(qǐng)輸入修改后的景點(diǎn)介紹信息:"; string y; cin>>y; ver[m].introduction=y; cout<<"修改成功~"<<endl; } } else if(n==2) { cout<<"|-----------------------------------------------------------------------------|"<<endl; cout<<"| 游客您好,歡迎來(lái)到校園導(dǎo)游系統(tǒng) |"<<endl; cout<<"| 1.查詢校園景點(diǎn)信息 |"<<endl; cout<<"| 2.校門(mén)問(wèn)路查詢 |"<<endl; cout<<"| 3.任意景點(diǎn)問(wèn)路查詢 |"<<endl; cout<<"|-----------------------------------------------------------------------------|"<<endl; cout<<"請(qǐng)按對(duì)應(yīng)數(shù)字選擇您所需要的服務(wù):"; int o; cin>>o; switch(o) { case 1:{cout<<"查詢校園景點(diǎn)信息"<<endl<<"請(qǐng)輸入所要查詢的景點(diǎn)號(hào)碼:"; int m; cin>>m; cout<<"景點(diǎn)名稱:"<<ver[m].name<<endl; cout<<"景點(diǎn)介紹:"<<ver[m].introduction<<endl; }break; case 2:{ cout<<"校門(mén)問(wèn)路查詢"<<endl; cout<<"請(qǐng)輸入您想要到達(dá)的目的地:"; static int x=0; static int y; cin>>y; cout<<"最短路徑為:" ; static int u; static int v; static int w; static int i; int t; static int s[MAX]; static int D[MAX][MAX]; static bool P[10][10][10]; for(v=0;v<10;v++) for(w=0;w<10;w++){ D[v][w]=r[v][w]; for(u=0;u<10;u++) P[v][w][u]=0; if(D[v][w]<MAX){ P[v][w][v]=1;P[v][w][w]=1; } } for(u=0;u<10;u++) for(v=0;v<10;v++) for(w=0;w<10;w++) if(D[v][u]+D[u][w]<D[v][w]){ D[v][w]=D[v][u]+D[u][w]; for(i=0;i<10;i++) P[v][w][i]=P[v][u][i]||P[u][w][i]; } int q=0; for(t=0;t<10;t++) if(P[x][y][t]==true) { s[q]=t; q++; } int d; int h; int f[10]={100}; static int l=0; int z=x; for(d=0;d<q-1;d++) for(h=0;h<q;h++) if(D[z][s[h]]==r[z][s[h]]&&D[z][s[h]]>0&&s[h]!=f[l]){ cout<<z<<"-->"; l=l+1; f[l]=z; z=s[h]; break; } cout<<y; cout<<"這兩個(gè)地點(diǎn)間的最短距離為"<<D[0][y]<<"m"<<endl; cout<<"從所在地步行到目的地約用時(shí)為"<<D[0][y]/80.0<<"min"<<endl; }break; case 3:{cout<<"任意景點(diǎn)問(wèn)路查詢"<<endl<<"請(qǐng)輸入您現(xiàn)在所在的地點(diǎn)"; static int x; cin>>x; cout<<"請(qǐng)輸入您想要到的地點(diǎn)"; static int y; cin>>y; cout<<"最短路徑為:" ; static int u; static int v; static int w; static int i; int t; static int s[MAX]; static int D[MAX][MAX]; static bool P[10][10][10]; for(v=0;v<10;v++) for(w=0;w<10;w++){ D[v][w]=r[v][w]; for(u=0;u<10;u++) P[v][w][u]=false; if(D[v][w]<MAX){ P[v][w][v]=true;P[v][w][w]=true; } } for(u=0;u<10;u++) for(v=0;v<10;v++) for(w=0;w<10;w++) if(D[v][u]+D[u][w]<D[v][w]){ D[v][w]=D[v][u]+D[u][w]; for(i=0;i<10;i++) P[v][w][i]=P[v][u][i]||P[u][w][i]; } int q=0; for(t=0;t<10;t++) if(P[x][y][t]==true) { s[q]=t; q++; } int d; int h; int f[10]={100}; static int l=0; int z=x; for(d=0;d<q-1;d++) for(h=0;h<q;h++) if(D[z][s[h]]==r[z][s[h]]&&D[z][s[h]]>0&&s[h]!=f[l]){ cout<<z<<"-->"; l=l+1; f[l]=z; z=s[h]; break; } cout<<y; cout<<"這兩個(gè)地點(diǎn)間的最短距離為"<<D[x][y]<<"m"<<endl; cout<<"從所在地步行到目的地約用時(shí)為"<<D[x][y]/80.0<<"min"<<endl; }break; } } else {cout<<"感謝使用校園導(dǎo)游系統(tǒng)"<<endl; exit(0); } } }
到此,關(guān)于“C++如何實(shí)現(xiàn)校園導(dǎo)游系統(tǒng)”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注億速云網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)?lái)更多實(shí)用的文章!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。