采用先来先办理的排队方式,假设取号时编码是连续的,但由于同一个时段有3个窗口,其中50岁以上在第一窗口,50岁以下女士在第二窗口,其他在第三窗口。功能要求: 1.录号:输入姓名及取号码(假设已取号) 2.显示在队列中第一位排队者姓名、号码编号; 3.进行窗口分配 4.按队列顺序显示各窗口排队人的姓名、编号及诊室 5.统计当天排队人数(按性别或年龄进行统计) 执行一个具体的功能之后,程序将重新显示菜单
时间: 2024-02-12 20:05:44 浏览: 60
好的,这是一个排队系统的问题,需要使用编程语言来实现。以下是 Python 语言的一个简单实现,供参考:
```
class Queue:
def __init__(self):
self.items = []
def is_empty(self):
return len(self.items) == 0
def enqueue(self, item):
self.items.append(item)
def dequeue(self):
if self.is_empty():
return None
return self.items.pop(0)
class Customer:
def __init__(self, name, age, gender, number):
self.name = name
self.age = age
self.gender = gender
self.number = number
class Counter:
def __init__(self, name):
self.name = name
self.queue = Queue()
def is_empty(self):
return self.queue.is_empty()
def enqueue(self, customer):
self.queue.enqueue(customer)
def dequeue(self):
return self.queue.dequeue()
counter1 = Counter("50岁以上")
counter2 = Counter("50岁以下女士")
counter3 = Counter("其他")
customers = []
while True:
print("请选择功能:")
print("1. 录号")
print("2. 显示第一位排队者")
print("3. 进行窗口分配")
print("4. 按队列顺序显示各窗口排队人")
print("5. 统计当天排队人数")
print("6. 退出")
choice = input("请选择操作:")
if choice == "1":
name = input("请输入姓名:")
number = input("请输入号码编号:")
age = int(input("请输入年龄:"))
gender = input("请输入性别(男/女):")
customer = Customer(name, age, gender, number)
customers.append(customer)
print("录号成功")
elif choice == "2":
if len(customers) > 0:
print("第一位排队者姓名:{},号码编号:{}".format(customers[0].name, customers[0].number))
else:
print("当前队列为空")
elif choice == "3":
for customer in customers:
if customer.age >= 50:
counter1.enqueue(customer)
elif customer.gender == "女":
counter2.enqueue(customer)
else:
counter3.enqueue(customer)
customers = []
print("窗口分配成功")
elif choice == "4":
print("窗口1(50岁以上):")
while not counter1.is_empty():
customer = counter1.dequeue()
print("姓名:{},号码编号:{},诊室:{}".format(customer.name, customer.number, counter1.name))
print("窗口2(50岁以下女士):")
while not counter2.is_empty():
customer = counter2.dequeue()
print("姓名:{},号码编号:{},诊室:{}".format(customer.name, customer.number, counter2.name))
print("窗口3(其他):")
while not counter3.is_empty():
customer = counter3.dequeue()
print("姓名:{},号码编号:{},诊室:{}".format(customer.name, customer.number, counter3.name))
elif choice == "5":
age_count = 0
gender_count = 0
for customer in customers:
if customer.age >= 50:
age_count += 1
elif customer.gender == "女":
gender_count += 1
print("当天排队人数:")
print("50岁以上:{}".format(age_count))
print("女士:{}".format(gender_count))
print("其他:{}".format(len(customers) - age_count - gender_count))
elif choice == "6":
break
else:
print("请输入正确的选项")
```
这个程序使用了三个类:`Queue` 表示队列,`Customer` 表示顾客,`Counter` 表示窗口。在主循环中,根据用户的选择执行相应的操作。具体的实现细节可以参考代码中的注释。
阅读全文