C#实现排队叫号
以下是一个简单的C#排队叫号程序,可以根据用户输入的服务类型、姓名和电话号码生成一个唯一的排队号码,并将其添加到队列中。
using System;
using System.Collections.Generic;
namespace QueueSystem
{
class Program
{
static void Main(string[] args)
{
Queue<Customer> queue = new Queue<Customer>();
int queueNum = 1;
while (true)
{
Console.WriteLine("请选择服务类型:");
Console.WriteLine("1. 业务咨询");
Console.WriteLine("2. 产品购买");
Console.WriteLine("3. 服务投诉");
int serviceType = int.Parse(Console.ReadLine());
Console.WriteLine("请输入姓名:");
string name = Console.ReadLine();
Console.WriteLine("请输入电话号码:");
string phone = Console.ReadLine();
string queueId = string.Format("{0}-{1}-{2}", queueNum, serviceType, DateTime.Now.ToString("yyyyMMddHHmmss"));
Customer customer = new Customer(queueId, serviceType, name, phone);
queue.Enqueue(customer);
Console.WriteLine("您的排队号码为:{0}", queueId);
Console.WriteLine("当前等待人数为:{0}", queue.Count);
queueNum++;
}
}
}
class Customer
{
public string QueueId { get; set; }
public int ServiceType { get; set; }
public string Name { get; set; }
public string Phone { get; set; }
public Customer(string queueId, int serviceType, string name, string phone)
{
QueueId = queueId;
ServiceType = serviceType;
Name = name;
Phone = phone;
}
}
}
在上面的程序中,我们使用了一个Queue
当顾客输入完信息后,程序会输出当前的排队号码和等待人数。顾客可以根据自己的排队号码来等待服务,同时也可以根据等待人数来大致估计自己需要等待的时间。
当有客服处理完一个顾客的服务后,程序可以使用queue.Dequeue()方法将该顾客从队列中移除,以便让下一个顾客接受服务
原文地址: https://www.cveoy.top/t/topic/fySG 著作权归作者所有。请勿转载和采集!