?? 渡口管理.cpp
字號:
#include<iostream.h>
#include<stdlib.h>
#include<string.h>
#include<time.h>
struct che
{
char che1[10];
};
typedef che DataType ;
const int MaxQueueSize=200;
#include"SeqQueue.h"
void main()
{ int order,i,j,n=0; //n紀錄船上的車的數量
che temp;
char p[]="#";
char ship[10][10]; //記錄船上的車,車牌號為長度小于10的字符串
int mark=0; //標記渡口有無船只
long t1,t2,t0; //記錄時間
SeqQueue kequeue; //客車隊列
SeqQueue huoqueue; //貨車隊列
cout<<"口令:1 有車來到。 2 有船來到。3 察看船的裝載情況。 4 超時,手動發船。 5 退出系統。 "<<endl;
start:
cout<<endl;
cout<<"請輸入口令:";
cin>>order;
switch(order)
{
case 1:cout<<"車牌號首字母為'h'的為貨車,首字母為'k'的為客車。輸入#結束。"<<endl;
cout<<"請輸入車牌號:";
cin>>temp.che1;
while( strcmp(temp.che1,p)!=0)
{
if(temp.che1[0]=='k') kequeue.Append(temp);
else if(temp.che1[0]=='h')huoqueue.Append(temp);
else cout<<"無此種車"<<endl;
cin>>temp.che1;
}
if(mark==0)
{cout<<"渡口無船,車輛在渡口等待。"<<endl;
goto start;
}
case 2:
mark=1; //標記渡口有船
while(kequeue.NotEmpty()||huoqueue.NotEmpty()) //讓車上船
{
i=0;
while(kequeue.NotEmpty() && n<10 && i<4) //先上四輛客車
{ temp=kequeue.Delete();
strcpy(ship[n++],temp.che1);
i++;
}
if(n==10)
{cout<<"船滿發船。船上有車:"<<endl;
for( j=0;j<n;j++)
cout<<ship[j]<<" ";
cout<<endl;
n=0;mark=0;
goto start;
}
if(i==4)
{
if(huoqueue.NotEmpty())
{
temp=huoqueue.Delete();
strcpy(ship[n++],temp.che1);
}
}
else
while(huoqueue.NotEmpty() && n<10 && i<5)
{
temp=huoqueue.Delete();
strcpy(ship[n++],temp.che1);
i++;
}
if(n==10)
{cout<<"船滿發船。船上有車:"<<endl;
for( int j=0;j<n;j++)
cout<<ship[j]<<" ";
cout<<endl;
n=0;mark=0; //標記渡口無船
goto start;
}
}
if(n<10)
{
cout<<"船尚未滿,等待。船上有車:"<<endl;
for( j=0;j<n;j++)
cout<<ship[j]<<" ";
cout<<endl;
t1=time(0); //取系統時間
cout<<"計時開始時刻為: "<<ctime(&t1)<<endl;
}
goto start;
case 3: if(mark==0)
{ cout<<"渡口無船!"<<endl;}
else
{
cout<<"船上有車:"<<endl;
for( j=0;j<n;j++)
cout<<ship[j]<<" ";
cout<<endl;
t2=time(0);
cout<<"此時時刻為: "<<ctime(&t2)<<endl;
t0=t2-t1;
cout<<"已等待時間: "<<t0/60<<"分"<<t0%60<<"秒"<<endl;
cout<<"是否手動發船?若是,請輸入口令4。"<<endl;
}
goto start;
case 4:if(mark==0)
{ cout<<"渡口無船!"<<endl;}
else
{
cout<<"手動發船,";
cout<<"船上有車:"<<endl;
for( j=0;j<n;j++)
cout<<ship[j]<<" ";
n=0; mark=0;
}
goto start;
case 5:cout<<"謝謝使用本系統 !"<<endl; exit(0);break;
default:cout<<"無此口令!"<<endl;
goto start;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -