C++實(shí)現(xiàn)校園導(dǎo)游系統(tǒng)
本文實(shí)例為大家分享了C++實(shí)現(xiàn)校園導(dǎo)游系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
校園導(dǎo)游系統(tǒng)
問(wèn)題描述:設(shè)計(jì)一個(gè)校園導(dǎo)游程序,完成校園信息的維護(hù)以及為來(lái)訪的客人提供信息查詢(xún)等服務(wù)功能。
基本要求:
設(shè)計(jì)學(xué)校的校園平面圖,所含景點(diǎn)不少于10個(gè),以圖中頂點(diǎn)表示校內(nèi)各景點(diǎn),頂點(diǎn)的信息包括:景點(diǎn)名稱(chēng)、代號(hào)、簡(jiǎn)介等,以邊表示道路,邊上信息包括:兩點(diǎn)距離、所需時(shí)間等相關(guān)信息。(注:數(shù)據(jù)的輸入可以是鍵盤(pán)輸入或文件輸入兩種方式)
提供對(duì)校園景點(diǎn)信息的編輯(如:添加、刪除、修改等)的功能;
為來(lái)訪客人提供圖中任意景點(diǎn)相關(guān)信息的查詢(xún)(可提供多種查詢(xún)方式);
為來(lái)訪客人提供從校門(mén)口到圖中任意景點(diǎn)的問(wèn)路查詢(xún)(最短路徑);
為來(lái)訪客人提供圖中任意景點(diǎn)間的問(wèn)路查詢(xú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)的名稱(chēng):"; ?? ??? ?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)名稱(chēng):"<<ver[m].name<<endl; ?? ??? ?cout<<"景點(diǎn)介紹:"<<ver[m].introduction<<endl; ?? ??? ?cout<<"請(qǐng)輸入修改后的景點(diǎn)名稱(chēng):"; ?? ??? ?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.查詢(xún)校園景點(diǎn)信息 ? ? ? ? ? ? ? ? ? ? ? ? ? ? |"<<endl; ?? ? ? ?cout<<"| ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?2.校門(mén)問(wèn)路查詢(xún) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? |"<<endl; ? ? ? ? ? ? cout<<"| ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?3.任意景點(diǎn)問(wèn)路查詢(xún) ? ? ? ? ? ? ? ? ? ? ? ? ? ? |"<<endl; ?? ? ? ?cout<<"|-----------------------------------------------------------------------------|"<<endl; ?? ? ? ?cout<<"請(qǐng)按對(duì)應(yīng)數(shù)字選擇您所需要的服務(wù):"; ?? ? ? ?int o; ?? ? ? ?cin>>o; ?? ? ?? ?switch(o)? ?? ?{ ?? ??? ?case 1:{cout<<"查詢(xún)校園景點(diǎn)信息"<<endl<<"請(qǐng)輸入所要查詢(xún)的景點(diǎn)號(hào)碼:"; ?? ??? ?int m; ?? ??? ?cin>>m; ?? ??? ?cout<<"景點(diǎn)名稱(chēng):"<<ver[m].name<<endl; ?? ??? ?cout<<"景點(diǎn)介紹:"<<ver[m].introduction<<endl;?? ? ?? ??? ?}break; ?? ??? ?case 2:{ ?? ??? ?cout<<"校門(mén)問(wèn)路查詢(xú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)路查詢(xú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);?? ? ?? ?} ?? ? ? ? ?} }?
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Qt+OpenCV實(shí)現(xiàn)目標(biāo)檢測(cè)詳解
這篇文章主要介紹了如何利用Qt和OpenCV中自帶xml文件實(shí)現(xiàn)目標(biāo)檢測(cè),文中的實(shí)現(xiàn)過(guò)程講解詳細(xì),感興趣的小伙伴可以動(dòng)手試一試2022-03-03從頭學(xué)習(xí)C語(yǔ)言之for語(yǔ)句和循環(huán)嵌套
這篇文章主要為大家詳細(xì)介紹了C語(yǔ)言之for語(yǔ)句和循環(huán)嵌套,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來(lái)幫助2022-01-01C語(yǔ)言詳細(xì)解析有符號(hào)數(shù)與無(wú)符號(hào)數(shù)的表示
我們知道,在C語(yǔ)言中存在無(wú)符號(hào)數(shù)和有符號(hào)數(shù),但是對(duì)于計(jì)算機(jī)而言,其本身并不區(qū)別有符號(hào)數(shù)和無(wú)符號(hào)數(shù),因?yàn)樵谟?jì)算機(jī)里面都是O或者1,但是在我們的實(shí)際使用中有時(shí)候需要使用有符號(hào)數(shù)來(lái)表示一個(gè)整數(shù),因此我們規(guī)定,當(dāng)最高位為1的時(shí),表示為負(fù)數(shù),最高位為0時(shí),表示為正數(shù)2022-04-04linux c++ 服務(wù)器端開(kāi)發(fā)面試必看書(shū)籍整理
這篇文章主要介紹了linux c++ 服務(wù)器端開(kāi)發(fā)面試必看書(shū)籍整理,需要的朋友可以參考下2020-02-02輸入一個(gè)字符串,取出其中的整數(shù)(實(shí)現(xiàn)代碼)
輸入一個(gè)字符串,內(nèi)含所有數(shù)字和非數(shù)字字符。將其中連續(xù)的數(shù)字作為一個(gè)整數(shù),依次存放到一個(gè)數(shù)組中,統(tǒng)計(jì)共有多少個(gè)整數(shù),并輸出這些數(shù)2013-09-09