zoukankan      html  css  js  c++  java
  • 第二次作业

    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;
    

    }

    运行结果:

  • 相关阅读:
    java线程池笔记
    java多线程简单用法
    Java 常用工具类整理
    Linux nohup命令详解
    Java八种基本类型
    isms项目tomcat运行配置
    2017计划
    ES6 Reflect 与 Proxy
    ES6 Map与Set
    ES6 Symbol类型
  • 原文地址:https://www.cnblogs.com/New-Lee/p/6140575.html
Copyright © 2011-2022 走看看