Li June Granville U201310747
State machine Diagram:
The position status of the landing bar and the light signal as two classes of objects, the car gate sensor signal as input, write code:
1 //Qichemenjin.cpp2 //Copy right by Justin.3 4#include"stdafx.h"5#include <iostream>6 using namespacestd;7 classLiftlever8 {9 Public:Ten BOOLLeverstate;//position of landing rod One voidchangeleverstate () A { -Leverstate =!leverstate; - }; the }; - - class Light - { + Public: - BOOLLightstate;//Traffic light Signal + voidchangelightstate () A { atLightstate =!lightstate; - }; - }; - - voidShowleverstate (BOOLState ) - { in if(state==true) -cout <<"The landing bar rises"<<Endl; to Else +cout <<"Landing lever falling down"<<Endl; - }; the * voidShowlightstate (BOOLState ) $ {Panax Notoginseng if(state = =true) -cout <<"green light"<<Endl; the Else +cout <<"Red Light"<<Endl; A }; the + liftlever Liftleverdemo; - Light Lightdemo; $ $ BOOLControlsystem (Charcar) - { - Switch(CAR) the { - Case 'y':Wuyi liftleverdemo.changeleverstate (); the Break; - Case 'N': Wu Break; - }; About $ showleverstate (liftleverdemo.leverstate); - - Switch(liftleverdemo.leverstate) - { A Case true: +Lightdemo.lightstate =true; thecout <<"green light"<<Endl; - Break; $ Case false: theLightdemo.lightstate =false; thecout <<"Red Light"<< endl<<Endl; the Break; the }; - returnlightdemo.lightstate; in }; the the About intMain () the { the CharCarin; the Charcarout; + while(1) - { thecout <<"is there a vehicle coming in? (y/n)"<<Endl;BayiCIN >>Carin; the BOOLNeXTSTEP =Controlsystem (Carin); the while(NeXTSTEP) - { -cout <<"has the vehicle been driven out? (y/n)"<<Endl; theCIN >>carout; theNeXTSTEP =Controlsystem (carout); the }; the }; - return 0; the}
Operation Result:
Real-time control software second operation--parking access control System state machine