飞机订票管理系统C语言代码
时间: 2024-05-22 10:07:25 浏览: 188
飞机订票管理系统是一个用于管理航班信息、乘客信息和机票信息的系统。以下是一个简单的飞机订票管理系统的C语言代码示例:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_FLIGHTS 100
#define MAX_PASSENGERS 100
typedef struct {
int flightNumber;
char destination[50];
char departureTime[20];
} Flight;
typedef struct {
int ticketNumber;
char passengerName[50];
int flightNumber;
} Passenger;
Flight flights[MAX_FLIGHTS];
Passenger passengers[MAX_PASSENGERS];
int numFlights = 0;
int numPassengers = 0;
void addFlight() {
if (numFlights >= MAX_FLIGHTS) {
printf("已达到最大航班数!\n");
return;
}
Flight newFlight;
printf("请输入航班号:");
scanf("%d", &newFlight.flightNumber);
printf("请输入目的地:");
scanf("%s", newFlight.destination);
printf("请输入起飞时间:");
scanf("%s", newFlight.departureTime);
flights[numFlights++] = newFlight;
printf("航班添加成功!\n");
}
void addPassenger() {
if (numPassengers >= MAX_PASSENGERS) {
printf("已达到最大乘客数!\n");
return;
}
Passenger newPassenger;
printf("请输入乘客姓名:");
scanf("%s", newPassenger.passengerName);
printf("请输入航班号:");
scanf("%d", &newPassenger.flightNumber);
int flightIndex = -1;
for (int i = 0; i < numFlights; i++) {
if (flights[i].flightNumber == newPassenger.flightNumber) {
flightIndex = i;
break;
}
}
if (flightIndex == -1) {
printf("找不到对应的航班!\n");
return;
}
newPassenger.ticketNumber = numPassengers + 1;
passengers[numPassengers++] = newPassenger;
printf("乘客添加成功!\n");
}
void displayFlights() {
printf("航班列表:\n");
for (int i = 0; i < numFlights; i++) {
printf("航班号:%d,目的地:%s,起飞时间:%s\n", flights[i].flightNumber, flights[i].destination, flights[i].departureTime);
}
}
void displayPassengers() {
printf("乘客列表:\n");
for (int i = 0; i < numPassengers; i++) {
printf("票号:%d,乘客姓名:%s,航班号:%d\n", passengers[i].ticketNumber, passengers[i].passengerName, passengers[i].flightNumber);
}
}
int main() {
int choice;
do {
printf("\n飞机订票管理系统\n");
printf("1. 添加航班\n");
printf("2. 添加乘客\n");
printf("3. 显示航班列表\n");
printf("4. 显示乘客列表\n");
printf("0. 退出\n");
printf("请选择操作:");
scanf("%d", &choice);
switch (choice) {
case 1:
addFlight();
break;
case 2:
addPassenger();
break;
case 3:
displayFlights();
break;
case 4:
displayPassengers();
break;
case 0:
printf("感谢使用飞机订票管理系统!\n");
break;
default:
printf("无效的选择!\n");
break;
}
} while (choice != 0);
return 0;
}
```
这段代码实现了一个简单的飞机订票管理系统,可以添加航班信息、乘客信息,并显示航班列表和乘客列表。你可以根据需要进行修改和扩展。
阅读全文