C++實現(xiàn)校園導(dǎo)游系統(tǒng)
本文實例為大家分享了C++實現(xiàn)校園導(dǎo)游系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
校園導(dǎo)游系統(tǒng)
問題描述:設(shè)計一個校園導(dǎo)游程序,完成校園信息的維護以及為來訪的客人提供信息查詢等服務(wù)功能。
基本要求:
設(shè)計學(xué)校的校園平面圖,所含景點不少于10個,以圖中頂點表示校內(nèi)各景點,頂點的信息包括:景點名稱、代號、簡介等,以邊表示道路,邊上信息包括:兩點距離、所需時間等相關(guān)信息。(注:數(shù)據(jù)的輸入可以是鍵盤輸入或文件輸入兩種方式)
提供對校園景點信息的編輯(如:添加、刪除、修改等)的功能;
為來訪客人提供圖中任意景點相關(guā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]={ ? ? ? {"校門",0,"學(xué)校主校門"},? ? ? ? {"體育場",1,"學(xué)校舉辦體育活動的地方"}, ? ? ? {"六號公寓",2,"校內(nèi)學(xué)生宿舍"}, ? ? ? {"沉思廣場",3,"大草地"}, ? ? ? {"知源亭",4,"小亭子"}, ? ? ? {"圖書館",5,"書的棲息地"}, ? ? ? {"綜合實驗樓",6,"實驗室云云"}, ? ? ? {"大學(xué)會館",7,"舉辦會議和活動的地方"}, ? ? ? {"鵬遠公寓",8,"鵬遠學(xué)生宿舍"}, ? ? ? {"工學(xué)館",9,"主教樓"} ? ?}; ? ? ?int b; ? ? ?for(b=0;b<1000;b++) { ? ? ? ? ?cout<<"|-----------------------------------------------------------------------------|"<<endl; ? ? ? ? ?cout<<"| ? ? ? ? ? ? ? ? ? ? ? ? ? ? 歡迎來到校園導(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<<"景點編號:"<<endl; ?? ? cout<<"0.校門 ? ? ? ? ? ? ?1.體育場"<<endl; ?? ? cout<<"2.六號公寓 ? ? ? ? ?3.沉思廣場"<<endl; ?? ? cout<<"4.知源亭 ? ? ? ? ? ?5.圖書館"<<endl;? ?? ? cout<<"6.綜合實驗樓 ? ? ? ?7.大學(xué)會館"<<endl; ?? ? cout<<"8.鵬遠公寓 ? ? ? ? ?9.工學(xué)館"<<endl; ?? ? cout<<"請按對應(yīng)數(shù)字選擇您操作:"; ?? ? cin>>n; ? ? if(n==1) ?? ?{?? ??? ? ?? ? ? ?cout<<"|-----------------------------------------------------------------------------|"<<endl; ? ? ? ? ? ? cout<<"| ? ? ? ? ? ? ? ? ? ? ? ?管理員您好,歡迎來到校園導(dǎo)游系統(tǒng) ? ? ? ? ? ? ? ? ? ? |"<<endl;? ?? ? ? ?cout<<"| ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?1.添加校園景點信息 ? ? ? ? ? ? ? ? ? ? ? ? ? ? |"<<endl; ?? ? ? ?cout<<"| ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?2.刪除校園景點信息 ? ? ? ? ? ? ? ? ? ? ? ? ? ? |"<<endl; ? ? ? ? ? ? cout<<"| ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?3.修改校園景點信息 ? ? ? ? ? ? ? ? ? ? ? ? ? ? |"<<endl; ?? ? ? ?cout<<"|-----------------------------------------------------------------------------|"<<endl; ?? ??? ?cout<<"請輸入您將要進行的編輯操作編號:"; ?? ??? ?int a; ?? ??? ?cin>>a; ?? ??? ?if(a==1){ ?? ??? ?cout<<"請輸入你將要添加的校園景點編號:"; ?? ??? ?int m; ?? ??? ?cin>>m; ?? ??? ?ver[m].number=m; ?? ??? ?cout<<"請輸入你將要添加的校園景點的名稱:"; ?? ??? ?string x; ?? ??? ?cin>>x; ?? ??? ?ver[m].name=x;? ?? ??? ?cout<<"請輸入你將要添加的校園景點的介紹:"; ?? ??? ?string y; ?? ??? ?cin>>y; ?? ??? ?ver[m].introduction=y; ?? ??? ?cout<<"添加成功~" <<endl;? ?? ??? ?} ?? ??? ?if(a==2){ ?? ??? ??? ?cout<<"請輸入你將要刪除的校園景點編號:"; ?? ??? ??? ?int m; ?? ??? ??? ?cin>>m; ?? ??? ??? ?ver[m]=ver[MAX-1]; ?? ??? ??? ?cout<<"刪除成功~"<<endl; ?? ??? ?} ?? ??? ?if(a==3){ ?? ??? ?cout<<"請輸入你將要修改的校園景點編號:";? ?? ??? ?int m; ?? ??? ?cin>>m; ?? ??? ?cout<<"你將要修改的景點信息如下:"<<endl; ?? ??? ?cout<<"景點名稱:"<<ver[m].name<<endl; ?? ??? ?cout<<"景點介紹:"<<ver[m].introduction<<endl; ?? ??? ?cout<<"請輸入修改后的景點名稱:"; ?? ??? ?string x; ?? ??? ?cin>>x; ?? ??? ?ver[m].name=x; ?? ??? ?cout<<"請輸入修改后的景點介紹信息:"; ?? ??? ?string y; ?? ??? ?cin>>y; ?? ??? ?ver[m].introduction=y; ?? ??? ?cout<<"修改成功~"<<endl; ?? ??? ?} ?? ??? ??? ? ?? ??? ??? ? ?? ?}? ?? ?else if(n==2) ?? ??? ?{ ? ? ? ? ? ? cout<<"|-----------------------------------------------------------------------------|"<<endl; ? ? ? ? ? ? cout<<"| ? ? ? ? ? ? ? ? ? ? ? ? 游客您好,歡迎來到校園導(dǎo)游系統(tǒng) ? ? ? ? ? ? ? ? ? ? ?|"<<endl;? ?? ? ? ?cout<<"| ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?1.查詢校園景點信息 ? ? ? ? ? ? ? ? ? ? ? ? ? ? |"<<endl; ?? ? ? ?cout<<"| ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?2.校門問路查詢 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? |"<<endl; ? ? ? ? ? ? cout<<"| ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?3.任意景點問路查詢 ? ? ? ? ? ? ? ? ? ? ? ? ? ? |"<<endl; ?? ? ? ?cout<<"|-----------------------------------------------------------------------------|"<<endl; ?? ? ? ?cout<<"請按對應(yīng)數(shù)字選擇您所需要的服務(wù):"; ?? ? ? ?int o; ?? ? ? ?cin>>o; ?? ? ?? ?switch(o)? ?? ?{ ?? ??? ?case 1:{cout<<"查詢校園景點信息"<<endl<<"請輸入所要查詢的景點號碼:"; ?? ??? ?int m; ?? ??? ?cin>>m; ?? ??? ?cout<<"景點名稱:"<<ver[m].name<<endl; ?? ??? ?cout<<"景點介紹:"<<ver[m].introduction<<endl;?? ? ?? ??? ?}break; ?? ??? ?case 2:{ ?? ??? ?cout<<"校門問路查詢"<<endl; ?? ??? ?cout<<"請輸入您想要到達的目的地:"; ?? ??? ?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<<"這兩個地點間的最短距離為"<<D[0][y]<<"m"<<endl; ? ? ?cout<<"從所在地步行到目的地約用時為"<<D[0][y]/80.0<<"min"<<endl; ? ? ? ?? ??? ?}break; ?? ??? ?case 3:{cout<<"任意景點問路查詢"<<endl<<"請輸入您現(xiàn)在所在的地點"; ?? ??? ?static int x; ?? ??? ?cin>>x; ?? ??? ?cout<<"請輸入您想要到的地點"; ?? ??? ?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<<"這兩個地點間的最短距離為"<<D[x][y]<<"m"<<endl; ? ? ?cout<<"從所在地步行到目的地約用時為"<<D[x][y]/80.0<<"min"<<endl; ? ? ? ?? ?? ??? ?}break; ? ?? ?} ?? ?} ?? ?else {cout<<"感謝使用校園導(dǎo)游系統(tǒng)"<<endl; ?? ??? ?exit(0);?? ? ?? ?} ?? ? ? ? ?} }?
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
linux c++ 服務(wù)器端開發(fā)面試必看書籍整理
這篇文章主要介紹了linux c++ 服務(wù)器端開發(fā)面試必看書籍整理,需要的朋友可以參考下2020-02-02輸入一個字符串,取出其中的整數(shù)(實現(xiàn)代碼)
輸入一個字符串,內(nèi)含所有數(shù)字和非數(shù)字字符。將其中連續(xù)的數(shù)字作為一個整數(shù),依次存放到一個數(shù)組中,統(tǒng)計共有多少個整數(shù),并輸出這些數(shù)2013-09-09