?? intmain.cpp
字號:
#include"diaodu.h"
GRaph net;//全局變量,存儲站點信息
int cusmenu()//乘客選擇菜單
{
ElemType h[100],t[100];//e[i][j]為線路i上的站點j
int i,countt[4],counth[4],change[4];//一開始counth是從起點出發的線路數,countt是進入終點的線路數
int choice1;
int path[3];
for(i=0;i<4;i++)
countt[i]=counth[i]=0;
while(1)
{
cout<<right<<setfill('-')<<setw(25)<<"乘客選擇菜單"<<setfill('-')<<setw(25)<<"-"<<endl;
cout<<setfill(' ')<<setw(30)<<left<<"1:輸入起點和終點。"<<endl<<endl;
cout<<setfill(' ')<<setw(30)<<left<<"2:求直達或只轉一次車的路線。"<<endl<<endl;
cout<<setfill(' ')<<setw(30)<<left<<"3:求換乘多次的路線。"<<endl<<endl;
cout<<setfill(' ')<<setw(30)<<left<<"4:求時間最短的線路。"<<endl<<endl;
cout<<setfill(' ')<<setw(30)<<left<<"5:提供幾條時間較短線路。"<<endl<<endl;
cout<<0<<":返回主菜單."<<endl;
cout<<setw(50)<<setfill('-')<<'-'<<endl<<endl;
cout<<"請選擇n:";
cin>>choice1;
switch(choice1)
{
case 0:return 0;
case 1:
cout<<"輸入起點(S+小于3957的四位數):";
cin>>vhead;
counth[0]=net.findpathout(h,vhead);
cout<<"輸入終點(S+小于3957的四位數):";
cin>>vtail;
countt[0]=net.findpathin(t,vtail);
for(i=0;i<4;i++)
change[i]=0;
break;
case 2:
cout<<"不需換車的線路為:"<<endl;
change[0]=net.directpath(h,t,counth[0],countt[0]);//如果有直接路線,計算然后輸出。
if(change[0]==0)cout<<"沒有直達路線。"<<endl;
//然后再看轉車一次的路線。找到線路h[i],t[j]上的站點e[i][u],f[j][k],看有沒有相同的公共站點,有就是路線h[i]->e[i][j]->t[j]
cout<<"轉一次車的線路為:"<<endl;
change[1]=net.oncepath(h,t,counth[0],countt[0]);
if(change[1]==0)cout<<"沒有轉一次車的線路。"<<endl;
cout<<endl;
break;
case 3:
cout<<"轉多次車的所有線路為:"<<endl;
change[2]=net.twiceandthreepath(h,t,counth[0],countt[0],counth[1],countt[1]);
if(change[2]==0)cout<<"沒有轉多次車的所有線路。"<<endl;
cout<<endl;
break;
case 4:
cout<<"換乘次數為2次以內的最快路線為:"<<endl;
path[0]=net.oncepathtime(h,t,counth[0],countt[0]);
path[1]=net.twiceandthreepathtime(h,t,counth[0],countt[0],counth[1],countt[1]);
if(!path[0]&&!path[1])cout<<"兩個站點沒有路線到達。"<<endl;
cout<<endl;
break;
case 5:
cout<<"換乘次數為2次以內的多條較快路線為:"<<endl;
path[0]=net.oncepathsometime(h,t,counth[0],countt[0]);
path[1]=net.twiceandthreepathsometime(h,t,counth[0],countt[0],counth[1],countt[1]);
if(!path[0]&&!path[1])cout<<"兩個站點沒有路線到達。"<<endl;
cout<<endl;
break;
}
}
}
int guanli()//管理員菜單
{
char filename[10];
char str[10]=".txt";
net.initiate();
int i,k,choice1;
ElemType busname;
ARcType *p;
while(1)
{
cout<<right<<setfill('-')<<setw(25)<<"管理員菜單"<<setfill('-')<<setw(25)<<"-"<<endl;
cout<<setfill(' ')<<setw(30)<<left<<"1:初始化公交查詢系統。"<<endl<<endl;
cout<<setfill(' ')<<setw(30)<<left<<"2:查看某站點的出入站情況。"<<endl<<endl;
cout<<setfill(' ')<<setw(30)<<left<<"3:查看所有線路(由于線路過多一開始會出現閃屏)。"<<endl<<endl;
cout<<setfill(' ')<<setw(30)<<left<<"4:根據統計的線路的數據對該線路進行公車的調度"<<endl<<endl;
cout<<setfill(' ')<<setw(30)<<left<<"0:返回主菜單。"<<endl;
cout<<setw(50)<<setfill('-')<<'-'<<endl<<endl;
cout<<"請選擇n:";
cin>>choice1;
switch(choice1)
{
case 0:return 0;
case 1:
if(net.getdata())cout<<"初始化公交查詢系統成功。"<<endl<<endl;
break;
case 2:
cout<<"輸入站點名(S+小于3957的四位數):";
while(1)
{
cin>>busname;
k=changel(busname);
if(k<1||k>3977){cout<<"輸入有誤,請重新輸入(S+3957以下的四位數):";}
else break;
}
cout<<"從站點"<<busname<<"出發的線路情況為:"<<endl;
for(p=net.graph[k].firstarc;p;p=p->nextarc)
{
cout<<net.graph[k].vertexname<<"->";
cout<<p->lname<<"-->"<<net.graph[p->adjvertex].vertexname<<endl;
}
cout<<"進入站點"<<busname<<"的線路情況為:"<<endl;
for(p=net.graph1[k].firstarc;p;p=p->nextarc)
{
cout<<net.graph[p->adjvertex].vertexname<<"->";
cout<<p->lname<<"-->"<<net.graph[k].vertexname<<endl;
}
cout<<endl;
break;
case 3:
Showall();
cout<<endl;
break;
case 4:
cout<<"請輸入公交調度所需數據所在的文件名(目前只有“xianlu1”這個文件)。"<<endl;
cin>>filename;
strcat(filename,str);
while(1)
{
cout<<"根據文件的數據可以得出公交調度及相關數據如下:"<<endl;
if(getdata1(filename))break;
else cout<<"請重新輸入:";
cin>>filename;
strcat(filename,str);
}
for(i=0;i<5;i++)
findbestBi(i,b1);
cout<<endl;
break;
}
}
}
int main()
{
string str;
char ch;
int choice1;
while(1)
{
cout<<right<<setfill('-')<<setw(25)<<"主菜單"<<setfill('-')<<setw(25)<<"-"<<endl;
cout<<setfill(' ')<<setw(30)<<left<<"1:管理員菜單。"<<endl<<endl;
cout<<setfill(' ')<<setw(30)<<left<<"2:乘客菜單。"<<endl<<endl;
cout<<setfill(' ')<<setw(30)<<left<<"0:結束程序。"<<endl;
cout<<setw(50)<<setfill('-')<<'-'<<endl<<endl;
cout<<"請選擇n:";
cin>>choice1;
switch(choice1)
{
case 0:return 0;
case 1:
while(1)
{
cout<<"輸入管理員密碼(為:111):"<<endl;
cin>>str;
if(str=="111")if(!guanli())break;
else
cout<<"密碼錯誤,重新輸入Y|N:";
cin>>ch;
if(ch=='Y'||ch=='y')continue;
else break;
}
break;
case 2:
if(!cusmenu())break;
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -