航空订票管理系统的C语言代码有管理员功能代码示例

以下是一个简单的航空订票管理系统的C语言代码,包括管理员功能。代码实现了航班信息的添加、查询、修改和删除,以及乘客信息的查询。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX_FLIGHTS 100
#define MAX_PASSENGERS 1000

struct Flight {
    char number[10];
    char origin[20];
    char destination[20];
    int seats;
};

struct Passenger {
    char name[20];
    char flight[10];
};

struct Flight flights[MAX_FLIGHTS];
int num_flights = 0;

struct Passenger passengers[MAX_PASSENGERS];
int num_passengers = 0;

void add_flight() {
    struct Flight f;
    printf("Enter flight number: ");
    scanf("%s", f.number);
    printf("Enter origin: ");
    scanf("%s", f.origin);
    printf("Enter destination: ");
    scanf("%s", f.destination);
    printf("Enter number of seats: ");
    scanf("%d", &f.seats);
    flights[num_flights++] = f;
    printf("Flight added successfully.\n");
}

void list_flights() {
    printf("Flight\tOrigin\tDestination\tSeats\n");
    for (int i = 0; i < num_flights; i++) {
        printf("%s\t%s\t%s\t\t%d\n", flights[i].number, flights[i].origin, flights[i].destination, flights[i].seats);
    }
}

void edit_flight() {
    char number[10];
    printf("Enter flight number to edit: ");
    scanf("%s", number);
    int found = 0;
    for (int i = 0; i < num_flights; i++) {
        if (strcmp(flights[i].number, number) == 0) {
            printf("Enter new origin: ");
            scanf("%s", flights[i].origin);
            printf("Enter new destination: ");
            scanf("%s", flights[i].destination);
            printf("Enter new number of seats: ");
            scanf("%d", &flights[i].seats);
            found = 1;
            printf("Flight edited successfully.\n");
            break;
        }
    }
    if (!found) {
        printf("Flight not found.\n");
    }
}

void delete_flight() {
    char number[10];
    printf("Enter flight number to delete: ");
    scanf("%s", number);
    int found = 0;
    for (int i = 0; i < num_flights; i++) {
        if (strcmp(flights[i].number, number) == 0) {
            for (int j = i; j < num_flights - 1; j++) {
                flights[j] = flights[j + 1];
            }
            num_flights--;
            found = 1;
            printf("Flight deleted successfully.\n");
            break;
        }
    }
    if (!found) {
        printf("Flight not found.\n");
    }
}

void add_passenger() {
    struct Passenger p;
    printf("Enter passenger name: ");
    scanf("%s", p.name);
    printf("Enter flight number: ");
    scanf("%s", p.flight);
    passengers[num_passengers++] = p;
    printf("Passenger added successfully.\n");
}

void list_passengers() {
    printf("Passenger\tFlight\n");
    for (int i = 0; i < num_passengers; i++) {
        printf("%s\t\t%s\n", passengers[i].name, passengers[i].flight);
   
}

void search_passengers() {
char flight[10];
printf("Enter flight number: ");
scanf("%s", flight);
int found = 0;
printf("Passenger\tFlight\n");
for (int i = 0; i < num_passengers; i++) {
if (strcmp(passengers[i].flight, flight) == 0) {
printf("%s\t\t%s\n", passengers[i].name, passengers[i].flight);
found = 1;
}
}
if (!found) {
printf("No passengers found for this flight.\n");
}
}

int main() {
int choice;
do {
printf("1. Add flight\n");
printf("2. List flights\n");
printf("3. Edit flight\n");
printf("4. Delete flight\n");
printf("5. Add passenger\n");
printf("6. List passengers\n");
printf("7. Search passengers\n");
printf("8. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);

    switch (choice) {
        case 1:
            add_flight();
            break;
        case 2:
            list_flights();
            break;
        case 3:
            edit_flight();
            break;
        case 4:
            delete_flight();
            break;
        case 5:
            add_passenger();
            break;
        case 6:
            list_passengers();
            break;
        case 7:
            search_passengers();
            break;
        case 8:
            printf("Goodbye!\n");
            break;
        default:
            printf("Invalid choice.\n");
    }
} while (choice != 8);

return 0;

}

管理员功能包括添加、查询、修改和删除航班信息。管理员还可以添加乘客信息,查询某个航班的乘客信息。这个代码非常基础,可以根据需要进行修改和扩展。

 
匿名

发表评论

匿名网友
:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:
确定