• 大小: 26KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-10
  • 语言: C#
  • 标签: C#  

资源简介

这是老师给的代码,可以运行的出来的 这是老师给的代码,可以运行的出来的 这是老师给的代码,可以运行的出来的

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ParkingSystem
{
    class Car
    {
        public string carNum;          //车牌号
        public static DateTime parkingTime;         //停车时间
        public DateTime leavingTime;                //离开时间
        private double cost;                        //费用
        private const double costPerHour=6;         //单价
        public Car(string carnum)
        {
            carNum=carnum;
          DateTime  parkingTime = new System.DateTime();
           parkingTime = System.DateTime.Now ;
           DateTime  leavingTime = new System.DateTime();
            cost = 0;
        }
        public double ParkingCost()               //计算停车费
        {
            leavingTime =System.DateTime.Now;
            //TimeSpan time = leavingTime - parkingTime;
            cost=costPerHour*(leavingTime.Second  - parkingTime.Second );
            return cost;
        }
    }
    
    class Program
    { 
        static Queue WaitingCars = new Queue();
        static Stack ParkingCars = new Stack();
        static int n;                     //停车场容量
        static void Main(string[] args)
        {
            bool flag=false;
            Console.WriteLine(“请输入停车长的大小:“n);
            n=int.Parse(Console.ReadLine());
            do{ 
                Console.WriteLine(“请输入操作指令:1、停车;2、离开;3、退出系统。“);
                //int instruct;
                try
                {
                  int   instruct = int.Parse(Console.ReadLine());
                
               
                switch (instruct){
                    case 1:

                        Parking();
                        flag = false;
                        break;
                    case 2:
                        Leaving();
                        flag = false;
                        break;
                    case 3:
                        flag=true;
                        break;
                    default:
                        Console.WriteLine(“请输入操作指令:1、停车;2、离开;3、退出系统。“);
                        flag = false;
                        break;}
                }
                 catch { Console.WriteLine(“重新输入:“); }
               
            }while(flag==false);
        }
        public static void Parking()                                      //停车
        {
            bool Exit = false;
            do
            {
                Console.WriteLine(“请输入5位车牌号:“);
                string carNum = Console.ReadLine();                       //如果停车场已满,进入等待队列
                if (ParkingCars.Count >= n)
                {
                    Car WaitingCar = new Car(carNum);

                    Console.WriteLine(“停车场已满,车已进入等待队列。“);
                    Console.WriteLine(“前面还有{0}辆车正在等待!“ WaitingCars.Count);

                    WaitingCars.Enqueue(WaitingCar);

                    Exit = true;
          

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       7168  2012-10-10 10:10  ParkingSystem\ParkingSystem\bin\Debug\ParkingSystem.exe

     文件      15872  2012-10-10 10:10  ParkingSystem\ParkingSystem\bin\Debug\ParkingSystem.pdb

     文件      14328  2002-10-12 13:39  ParkingSystem\ParkingSystem\bin\Debug\ParkingSystem.vshost.exe

     文件        490  2007-07-21 01:33  ParkingSystem\ParkingSystem\bin\Debug\ParkingSystem.vshost.exe.manifest

     文件       2841  2002-10-12 13:39  ParkingSystem\ParkingSystem\obj\Debug\ParkingSystem.csproj.FileListAbsolute.txt

     文件       7168  2012-10-10 10:10  ParkingSystem\ParkingSystem\obj\Debug\ParkingSystem.exe

     文件      15872  2012-10-10 10:10  ParkingSystem\ParkingSystem\obj\Debug\ParkingSystem.pdb

     文件       2499  2012-09-13 21:50  ParkingSystem\ParkingSystem\ParkingSystem.csproj

     文件       6341  2002-10-12 15:08  ParkingSystem\ParkingSystem\Program.cs

     文件       1376  2012-09-13 21:50  ParkingSystem\ParkingSystem\Properties\AssemblyInfo.cs

     文件        929  2012-09-13 21:50  ParkingSystem\ParkingSystem.sln

    ..A..H.     16896  2012-10-10 12:26  ParkingSystem\ParkingSystem.suo

     目录          0  2002-10-12 16:27  ParkingSystem\ParkingSystem\obj\Debug\TempPE

     目录          0  2012-10-12 21:54  ParkingSystem\ParkingSystem\bin\Debug

     目录          0  2012-10-12 21:54  ParkingSystem\ParkingSystem\obj\Debug

     目录          0  2012-10-12 21:54  ParkingSystem\ParkingSystem\bin

     目录          0  2012-10-12 21:54  ParkingSystem\ParkingSystem\obj

     目录          0  2012-10-12 21:54  ParkingSystem\ParkingSystem\Properties

     目录          0  2012-10-12 21:54  ParkingSystem\ParkingSystem

     目录          0  2012-10-12 21:54  ParkingSystem

----------- ---------  ---------- -----  ----

                91780                    20


评论

共有 条评论