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

📄 lift.cpp

📁 非常完整的电梯模拟系统 欢迎大家提出宝贵建议
💻 CPP
字号:
#include "Lift.h"

Lift::Lift()
{
	state=LEISURE;
	weight=0;
	count=0;
	Building B;
}

void Lift::EnterLift(int floor,int state)
{
	assert(floor>=0);
	Person p;
	if(state==UP)
	{
		while(!B.Up[floor].IsEmpty())
		{
			cout<<endl;
			p=B.Up[floor].DeQueue();
			if(weight<MAXW&&count<=MAXN)
			{
				lift.EnQueue1(p,p.to);
			    weight+=p.weight;
			    count++;
			    cout<<p;
			    cout<<"\t该人进入了电梯"<<endl;
			}
			else
				break;
		}
	}
	if(state==DOWN)
	{
		while(!B.Down[floor].IsEmpty())
		{
			cout<<endl;
			p=B.Down[floor].DeQueue();
			if(weight<MAXW&&count<=MAXN)
			{
				lift.EnQueue2(p,p.to);
			    weight+=p.weight;
				count++;
				cout<<p;
				cout<<"\t该人进入了电梯"<<endl;
			}
			else
				break;
		}
	}
}

void Lift::OutLift(int floor,int state)
{
	assert(floor>=0);
	Person p;
	if(state==UP||state==DOWN)
	{
		while(!lift.IsEmpty())
		{
			cout<<endl;
			p=lift.Get();
			if(p.to==floor+1)
			{
				lift.DeQueue();
				weight-=p.weight;
				count--;
				cout<<p;
				cout<<"\t该人走出了电梯"<<endl;
			}
			else
				break;
		}
	}
}

void Lift::Run()
{
	while(1)
	{
		Lift l;
		for(int i=0;i<TOTAL_FLOOR;i++)
		{
			for(long j=0;j<500000000;j++);
		    cout<<"\t***************************"<<endl;
		    cout<<"\t第"<<i+1<<"层"<<endl;
		    l.EnterLift(i,1);
		    l.OutLift(i,1);
		    cout<<"\t电梯现有人数"<<l.GetCount()<<endl;
		    cout<<"\t电梯现在载重"<<l.GetWeight()<<endl;
			cout<<"\t***************************"<<endl;
		}
		for(i=9;i>=0;i--)
		{
			for(long j=0;j<500000000;j++);
			cout<<"\t***************************"<<endl;
			cout<<"\t第"<<i+1<<"层"<<endl;
			l.EnterLift(i,2);
			l.OutLift(i,2);
			cout<<"\t电梯现有人数"<<l.GetCount()<<endl;
			cout<<"\t电梯现在载重"<<l.GetWeight()<<endl;
			cout<<"\t***************************"<<endl;
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -