First Test the vehicle's entry and exit, define the rise and fall of the rod, through the state of the bar different lights are not the same, in judging the vehicle has no access.
Code
Main function:
#include "./head.h"
#include <iostream>
using namespace Std;
int main () {
Gurdsystem GS;
cout << "Test Vehicle entry:" << Endl;
Gs.carin ();
cout << "Test vehicle out ..." << Endl;
Gs.carout ();
return 0;
}
Header file:
#include <iostream>
using namespace Std;
Class lifter{//landing lever
Private
BOOL state;//Private value indicates its own state, 0 fall 1 rise
Public
Lifter () {
State = false;//constructor, the default landing lever is lowered
}
void SetState (bool s) {//function method The parameter
State=s;
}
BOOL GetState () {//Get parameter function
return state;
}
void Change () {//main function lifting and landing lever
if (GetState () ==0) {
cout << "___________ rise ___________" << Endl;
SetState (TRUE);
}
else{
cout << "___________ lowered landing lever ___________" << endl;
SetState (FALSE);
}
}
};
Class light{//Lamp
Private
BOOL state;//Private value indicates its status, 0 red: 1 green
Public
Light () {
State = false;//constructor, default false indicates red light status
}
void SetState (bool s) {//function method Change parameter
State=s;
}
BOOL GetState () {//function method Get parameters
return state;
}
void Change () {//main function lifting and landing lever
if (GetState () ==0) {
cout << "___________ green light ___________" << Endl;
SetState (TRUE);
}
else{
cout << "___________ red light ___________" << Endl;
SetState (FALSE);
}
}
};
Class Gurdsystem {
Private
Lifter Lifter;
Light light;
BOOL state;//Indicates whether a car enters
Public
Gurdsystem () {
initialization lever and lamp class
Lifter Lifter;
Light light;
state=false;//default means no car entry
}
void SetState (bool s) {//function method Change parameter
State=s;
}
void CarIn () {//Test cart entry
SetState (TRUE);
cout << "___________ car prep ___________" << Endl;
Light.change ();//Change the Light
Lifter.change ();//Change the landing lever
}
void Carout () {//test car out
SetState (FALSE);
cout << "___________ car ready to go out ___________" << Endl;
Light.change ();
Lifter.change ();
}
};
Test results:
Second week homework