航班订票系统C程序代码
时间: 2023-10-15 14:04:05 浏览: 27
抱歉,我没有办法提供完整的航班订票系统C程序代码,因为这是一个大型项目需要进行具体的设计和实现。但是,我可以提供一些可以帮助您开始编写航班订票系统的代码部分:
1. 定义结构体表示航班信息:
```
typedef struct {
char flight_num[10]; // 航班号
char departure[20]; // 出发地
char destination[20]; // 目的地
char departure_time[10]; // 出发时间
char arrival_time[10]; // 到达时间
int price; // 价格
int seats_left; // 剩余座位数
} Flight;
```
2. 定义一个数组来存储航班信息:
```
Flight flights[100];
int num_flights = 0;
```
3. 编写函数来添加新的航班信息到数组中:
```
void add_flight() {
Flight new_flight;
printf("请输入航班号:");
scanf("%s", new_flight.flight_num);
printf("请输入出发地:");
scanf("%s", new_flight.departure);
printf("请输入目的地:");
scanf("%s", new_flight.destination);
printf("请输入出发时间:");
scanf("%s", new_flight.departure_time);
printf("请输入到达时间:");
scanf("%s", new_flight.arrival_time);
printf("请输入价格:");
scanf("%d", &new_flight.price);
printf("请输入座位数:");
scanf("%d", &new_flight.seats_left);
flights[num_flights] = new_flight;
num_flights++;
}
```
4. 编写函数来查询航班信息:
```
void search_flight() {
char flight_num[10];
printf("请输入要查询的航班号:");
scanf("%s", flight_num);
int found = 0;
for (int i = 0; i < num_flights; i++) {
if (strcmp(flights[i].flight_num, flight_num) == 0) {
found = 1;
printf("航班号:%s\n", flights[i].flight_num);
printf("出发地:%s\n", flights[i].departure);
printf("目的地:%s\n", flights[i].destination);
printf("出发时间:%s\n", flights[i].departure_time);
printf("到达时间:%s\n", flights[i].arrival_time);
printf("价格:%d\n", flights[i].price);
printf("剩余座位数:%d\n", flights[i].seats_left);
break;
}
}
if (!found) {
printf("没有找到航班号为 %s 的航班\n", flight_num);
}
}
```
这些代码只是航班订票系统的基本部分,您需要根据具体的需求进行设计和实现。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![-](https://csdnimg.cn/download_wenku/file_type_lunwen.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)