数据结构飞机票订票系统
时间: 2023-12-28 16:05:31 浏览: 114
飞机订票系统(数据结构).doc
飞机票订票系统可以使用以下数据结构来管理和存储数据:
1. 航班信息:可以使用字典或者类来表示每个航班的信息,包括航班号、起飞时间、到达时间、出发地、目的地等。
2. 客户信息:可以使用字典或者类来表示每个客户的信息,包括姓名、证件号、订票数量等。
3. 订单信息:可以使用字典或者类来表示每个订单的信息,包括订单编号、航班信息、客户信息等。
4. 航班数据文件:可以使用文件来存储航班信息,可以使用CSV、JSON等格式进行存储和读取。
5. 排队等候列表:可以使用队列来管理排队等候的客户,先进先出的原则。
6. 数据结构示例代码:
```python
class Flight:
def __init__(self, flight_number, departure_time, arrival_time, origin, destination):
self.flight_number = flight_number
self.departure_time = departure_time
self.arrival_time = arrival_time
self.origin = origin
self.destination = destination
class Customer:
def __init__(self, name, id_number, ticket_quantity):
self.name = name
self.id_number = id_number
self.ticket_quantity = ticket_quantity
class Order:
def __init__(self, order_number, flight, customer):
self.order_number = order_number
self.flight = flight
self.customer = customer
class FlightBookingSystem:
def __init__(self):
self.flights = []
self.customers = []
self.orders = []
self.waiting_list = []
def add_flight(self, flight):
self.flights.append(flight)
def add_customer(self, customer):
self.customers.append(customer)
def add_order(self, order):
self.orders.append(order)
def add_to_waiting_list(self, customer):
self.waiting_list.append(customer)
def modify_flight_info(self, flight_number, new_info):
for flight in self.flights:
if flight.flight_number == flight_number:
# 修改航班信息
flight.departure_time = new_info['departure_time']
flight.arrival_time = new_info['arrival_time']
flight.origin = new_info['origin']
flight.destination = new_info['destination']
break
def book_ticket(self, flight_number, customer):
for flight in self.flights:
if flight.flight_number == flight_number:
if len(self.orders) < flight.ticket_quantity:
# 生成订单编号
order_number = len(self.orders) + 1
order = Order(order_number, flight, customer)
self.add_order(order)
else:
self.add_to_waiting_list(customer)
break
```
阅读全文