c语言飞机票订票系统不要超过350行
时间: 2023-08-24 16:16:04 浏览: 219
c语言 飞机订票系统
5星 · 资源好评率100%
好的,我可以为您提供一个简单的飞机票订票系统的 C 语言代码实现,不过可能会超过 350 行。
代码如下:
```c
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct ticket {
char name[30];
int age;
char gender[10];
char flight_no[10];
char date[15];
char source[20];
char destination[20];
int seat_no;
int pnr;
};
struct passenger {
char name[30];
int age;
char gender[10];
};
int main() {
int choice, i, j, seat_no = 0, pnr_no = 1001;
char flight_no[10], date[15], source[20], destination[20];
struct ticket t[100];
struct passenger p;
while (1) {
printf("\nWelcome to Airline Ticket Booking System\n");
printf("---------------------------------------\n");
printf("1. Book a ticket\n");
printf("2. View ticket details\n");
printf("3. Cancel a ticket\n");
printf("4. Exit\n");
printf("---------------------------------------\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
printf("\nEnter flight no: ");
scanf("%s", flight_no);
printf("Enter date of journey(dd/mm/yyyy): ");
scanf("%s", date);
printf("Enter source station: ");
scanf("%s", source);
printf("Enter destination station: ");
scanf("%s", destination);
for (i = 0; i < 100; i++) {
if (strlen(t[i].name) == 0) {
printf("\nEnter passenger name: ");
scanf("%s", p.name);
printf("Enter passenger age: ");
scanf("%d", &p.age);
printf("Enter passenger gender(M/F): ");
scanf("%s", p.gender);
strcpy(t[i].name, p.name);
t[i].age = p.age;
strcpy(t[i].gender, p.gender);
strcpy(t[i].flight_no, flight_no);
strcpy(t[i].date, date);
strcpy(t[i].source, source);
strcpy(t[i].destination, destination);
t[i].seat_no = ++seat_no;
t[i].pnr = pnr_no++;
printf("\nTicket booked successfully!\n");
printf("PNR no: %d\n", t[i].pnr);
printf("Seat no: %d\n", t[i].seat_no);
printf("Name: %s\n", t[i].name);
printf("Age: %d\n", t[i].age);
printf("Gender: %s\n", t[i].gender);
printf("Flight no: %s\n", t[i].flight_no);
printf("Date of journey: %s\n", t[i].date);
printf("Source station: %s\n", t[i].source);
printf("Destination station: %s\n", t[i].destination);
break;
}
}
if (i == 100) {
printf("\nAll tickets have been booked for this flight!\n");
}
break;
case 2:
printf("\nEnter PNR no: ");
scanf("%d", &pnr_no);
for (j = 0; j < 100; j++) {
if (t[j].pnr == pnr_no) {
printf("\nPNR no: %d\n", t[j].pnr);
printf("Seat no: %d\n", t[j].seat_no);
printf("Name: %s\n", t[j].name);
printf("Age: %d\n", t[j].age);
printf("Gender: %s\n", t[j].gender);
printf("Flight no: %s\n", t[j].flight_no);
printf("Date of journey: %s\n", t[j].date);
printf("Source station: %s\n", t[j].source);
printf("Destination station: %s\n", t[j].destination);
break;
}
}
if (j == 100) {
printf("\nInvalid PNR no!\n");
}
break;
case 3:
printf("\nEnter PNR no: ");
scanf("%d", &pnr_no);
for (j = 0; j < 100; j++) {
if (t[j].pnr == pnr_no) {
strcpy(t[j].name, "");
t[j].age = 0;
strcpy(t[j].gender, "");
strcpy(t[j].flight_no, "");
strcpy(t[j].date, "");
strcpy(t[j].source, "");
strcpy(t[j].destination, "");
t[j].seat_no = 0;
t[j].pnr = 0;
printf("\nTicket cancelled successfully!\n");
break;
}
}
if (j == 100) {
printf("\nInvalid PNR no!\n");
}
break;
case 4:
printf("\nThank you for using Airline Ticket Booking System!\n");
exit(0);
default:
printf("\nInvalid choice!\n");
break;
}
}
return 0;
}
```
这个系统使用结构体来存储每张机票的信息,包括乘客姓名、年龄、性别、航班号、日期、出发地和目的地、座位号和 PNR 号。系统提供了预订、查看和取消机票的功能。
希望这个代码对您有所帮助!
阅读全文