• 《实时控制软件设计》第二周作业


    停车场门禁系统状态机:

                                                      

    代码如下:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace qichemenjin
    {
        /// <summary>
        /// 判断起降杆状态
        /// </summary>
        class LiftLever
        {
            public bool llstate;
            public LiftLever()
            {
                llstate = false;
            }
           
            
            public void Showllstate()
            {
                if (llstate == true)
                    Console.WriteLine("起落杆升");
                else
                    Console.WriteLine("起落杆降");
            }
        }
        /// <summary>
        /// 判断等的状态
        /// </summary>
        class TrafficLight
        {
            public bool tlstate;
            public TrafficLight()
            {
                tlstate = false;
            }
           
            
            public void Showtlstate()
            {
                if (tlstate == true)
                    Console.WriteLine("绿灯亮");
                else
                    Console.WriteLine("红灯亮");
            }
        }
        /// <summary>
        /// 判断车的状态
        /// </summary>
        class Car
        {
            public bool carstate;
            public Car()
            {
                carstate = false;
            }
            public void Showcarstate()
            {
                if (carstate == true)
                    Console.WriteLine("有车入闸");
                else
                    Console.WriteLine("车已出闸");
            }
        }
    
        class Program
        {
            static void Main(string[] args)
            {
                Car car = new Car();
                LiftLever lever = new LiftLever();
                TrafficLight light = new TrafficLight();
                car.Showcarstate();
                lever.Showllstate();
                light.Showtlstate();            
                while (car.carstate=true)
                {
                    Console.WriteLine("是否有车入闸(y/n)");
                    var input = Console.Read();
                    if(input=='y')
                    {
                        car.carstate = true;
                        car.Showcarstate();
                        lever.llstate = true;
                        lever.Showllstate();
                        light.tlstate = true;
                        light.Showtlstate();
                        Console.Read();
                    }
                    else
                    {
                        Console.WriteLine("车已出闸");
                        Console.WriteLine("起落杆降");
                        Console.WriteLine("红灯亮");
                        
                        Console.Read();
                    }
                    Console.Read();
                }           
            }
        }
    }

    运行结果如下:

  • 相关阅读:
    cpuset
    top
    path-lookup
    strace
    IDR算法[原理]
    cgroup
    转载
    std::reverse_iterator::base
    可重入、不可重入
    chromium code 中 普遍使用的 C++11 语法
  • 原文地址:https://www.cnblogs.com/syth/p/6137797.html
Copyright © 2020-2023  润新知