⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 渡口管理.cpp

📁 有一个渡口
💻 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 + -