下面展示一些 内联代码片
。
参考源码
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// 定义航班结构体
struct Flight
{
char flight_number[10];
char airplane_number[10];
char departure_station[50]; // 添加起飞站名
char destination[50];
char departure_day[40];
char latest_flight[40];
int available_seats;
};
// 全局航班数组,存储所有航班信息
struct Flight flights[100];
int num_flights = 0;
// 函数声明
void addFlight();
void displayFlights();
void searchFlight();
void bookTicket();
void cancelTicket();
void saveFlightDataToFile();
void readFlightDataFromFile();
int main()
{
// 从文件中读取航班数据
readFlightDataFromFile();
int choice;
while (1)
{
printf("************************************************************************\n");
printf("* 民航售票处计算机系统 *\n");
printf("************************************************************************\n");
printf("* 1. 添加航班 *\n");
printf("* 2. 显示所有航班信息 *\n");
printf("* 3. 查询航线 *\n");
printf("* 4. 订票 *\n");
printf("* 5. 退票 *\n");
printf("* 6. 退出系统 *\n");
printf("************************************************************************\n");
printf("请选择操作(1-6): ");
scanf("%d", &choice);
switch (choice)
{
case 1:
addFlight();
break;
case 2:
displayFlights();
break;
case 3:
searchFlight();
break;
case 4:
bookTicket();
break;
case 5:
cancelTicket();
break;
case 6:
// 在退出前保存航班数据到文件
saveFlightDataToFile();
printf("谢谢使用!\n");
exit(0);
default:
printf("无效的选择,请重新输入。\n");
}
}
return 0;
}
// 添加航班信息
void addFlight()
{
if (num_flights >= 100)
{
printf("航班信息已满,无法添加新航班。\n");
return;
}
struct Flight new_flight;
printf("请输入航班号: ");
scanf("%s", new_flight.flight_number);
printf("请输入飞机号: ");
scanf("%s", new_flight.airplane_number);
printf("请输入起飞站名: ");
scanf("%s", new_flight.departure_station);
printf("请输入终点站名: ");
scanf("%s", new_flight.destination);
printf("请输入星期几飞行: ");
scanf("%s", new_flight.departure_day);
printf("请输入最近一天航班的日期: ");
scanf("%s", new_flight.latest_flight);
printf("请输入余票额: ");
scanf("%d", &new_flight.available_seats);
flights[num_flights++] = new_flight;
printf("航班添加成功!\n");
}