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

📄 people.cpp

📁 这个程序是对电梯的模拟
💻 CPP
字号:
// People.cpp: implementation of the People class.
//
//////////////////////////////////////////////////////////////////////

#include "People.h"
#include <stdlib.h>
#include <time.h>

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

People::People()
{
     up=true;
	 to=-1;
}

People::~People()
{

}

void People::IntoElevator()
{
     cout<<SPACE2<<"People Into elevator ";
}

void People::OutElevator()
{
      cout<<SPACE2<<"People Go out elevator!"<<endl;
}

int People::PressButton()
{
    return 1;
}

int People::PressButton(int f1, int f2, int b)
{
	if(b==-1) //up and down
	{
        tm.CurTime();
		//f1=-1 down; f1=0 random; f1=1 up
		switch(f1){
		case -1: up=false;
			     return -1;
				 break;
		case  0: f2=rand() % 2;
			     if(f2){  up=true; f2=1; }
			     else  {  up=false; f2=-1; } 
				 return f2;
			     break;
		case  1: up=true;
			     return 1;
				 break;
		}
      
	}
	if(b==0) //Door Open and Close
	{
		//f1=1 f2=1 open | f1=-1 f2=-1 close		
		if(f1 & f2)
			return 1;
		else 
			return -1;
	}
	if(b==2)//which floor will go to?
	{
		int a;
		do{
		    a=rand()%(f2+1);//make a random number between f1 to f2;
		}while(a<f1);
		to=a;
	}

    return 1;
}

⌨️ 快捷键说明

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