Second week homework

Source: Internet
Author: User

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

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.