people.cpp

来自「这个程序是对电梯的模拟」· C++ 代码 · 共 79 行

CPP
79
字号
// 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 + =
减小字号Ctrl + -
显示快捷键?