Real-time control software second operation--parking access control System state machine

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.