第二次作业

include

using namespace std;

bool Undercart_UP=1,Undercart_DOWN=0;
bool green=1,red=0;
bool carIn = false, carOut = false;
bool light = red;
bool Undercart= Undercart_DOWN;

bool switchUndercartUp()
{
cout << "......杆上升......" << endl;
Undercart=Undercart_UP ;
return Undercart;
}

bool switchUndercartDOWN()
{
cout << "......杆下降......" << endl;
Undercart=Undercart_DOWN ;
return Undercart;
}

void turnGreen()
{
cout << "--------------------------绿灯,请通行------------------------" << endl;
light = green;
}

void turnRed()
{
cout << "-----------------------红灯,禁止通行--------------------------" << endl;
light = red;
}

int main()
{
while (1)
{
cout << "是否有车进入(1代表进入,其余代表没有):";
cin >> carIn;
if(carIn!=1)
{
cout<<"无车进入!等待中...";
cout << "是否有车进入(1代表进入,其余代表没有):";
cin >> carIn;
}
if (carIn == 1)
{
if (switchUndercartUp()) turnGreen();
}

    while (light)
    {
        cout << "车是否离开:";
        cin >> carOut;
		if(carOut!=1)
	{
		cout<<"车还未离开!等待中...";
		cout << "车是否离开:";
		cin >> carIn;
	}
        if (carOut == 1)
        {
            if (!switchUndercartDOWN())         turnRed();
        }
	
	}
    
}
return 0;

}

运行结果:

posted @ 2016-12-07 11:46  New_Lee  阅读(175)  评论(2编辑  收藏  举报