出售本站【域名】【外链】

电梯控制模拟代码简析(MFC)

文章正文
发布时间:2024-09-13 05:53

C++源代码 重视类的交互 片段 #include using namespace std; #include "eleZZZator.h" //EleZZZator class definition #include "person.h" //Person class definition #include "floor.h" //Floor class definition //constants that represent time required to traZZZel //between floors and direction of the eleZZZator const int EleZZZator::ELExATOR_TRAxEL_TIME = 5; const int EleZZZator::UP = 0; const int EleZZZator::DOWN = 1; //constructor EleZZZator::EleZZZator( Floor &firstFloor, Floor &secondFloor) : eleZZZatorButton( * this ), currentBuildingClockTime( 0 ), moZZZing( false ), direction( UP ), currentFloor( Floor::FLOOR1 ), arriZZZalTime( 0 ), floor1NeedsSerZZZice( false ), floor2NeedsSerZZZice( false ), floor1Ref( firstFloor ), floor2Ref( secondFloor ), passengerPtr( 0 ) { cout << "eleZZZator constrcuted" <<endl; }// end EleZZZator constructor //destructor EleZZZator::~EleZZZator() { delete passengerPtr; cout << "eleZZZator destructed" << endl; }//end EleZZZator destructor //giZZZe time to eleZZZator ZZZoid EleZZZator::processTime( int time ) { currentBuildingClockTime = time; if ( moZZZing ) //eleZZZator is moZZZing processPossibleArriZZZal(); else processPossibleDeparture(); if ( !moZZZing ) cout << "eleZZZator at rest on floor " << currentFloor << endl; }// end function processTime // when eleZZZator is moZZZing, determine if it should stop ZZZoid EleZZZator::processPossibleArriZZZal() { //if eleZZZator arriZZZes at destination floor if ( currentBuildingClockTime == arriZZZalTime ) { currentFloor = ( currentFloor == Floor::FLOOR1 ? Floor::FLOOR2 : Floor::FLOOR1); //update current floor direction = ( currentFloor == Floor::FLOOR1 ? UP : DOWN ); //update direction cout << "eleZZZator arriZZZes on floor " << currentFloor <<endl; // process arriZZZal at currentFloor arriZZZeAtFloor( currentFloor == Floor::FLOOR1 ? floor1Ref : floor2Ref); return; }//end if //eleZZZator still moZZZing cout << "eleZZZator moZZZing " << ( direction == UP ? "UP" : "DOWN"