0% found this document useful (0 votes)
22 views2 pages

Airline Reservation System

The document is a C program for an Airline Reservation System that allows users to view available flights and make reservations. It defines a structure for flights, initializes sample flights, and provides functions to display flights and handle reservations. The program runs in a loop until the user chooses to exit.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views2 pages

Airline Reservation System

The document is a C program for an Airline Reservation System that allows users to view available flights and make reservations. It defines a structure for flights, initializes sample flights, and provides functions to display flights and handle reservations. The program runs in a loop until the user chooses to exit.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <stdio.

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

#define MAX_FLIGHTS 10
#define MAX_NAME_LENGTH 50

// Structure to represent a flight


struct Flight {
int flightNumber;
char destination[MAX_NAME_LENGTH];
int seatsAvailable;
float fare;
};

// Function to display the list of available flights


void displayFlights(struct Flight flights[], int numFlights) {
printf("Available Flights:\n");
printf("Flight Number | Destination | Seats Available | Fare\n");
for (int i = 0; i < numFlights; i++) {
printf("%d | %s | %d | $%.2f\n", flights[i].flightNumber,
flights[i].destination, flights[i].seatsAvailable, flights[i].fare);
}
printf("\n");
}

// Function to make a reservation


void makeReservation(struct Flight flights[], int numFlights) {
int flightChoice;
printf("Enter the flight number you want to book: ");
scanf("%d", &flightChoice);

if (flightChoice >= 1 && flightChoice <= numFlights) {


int numPassengers;
printf("Enter the number of passengers: ");
scanf("%d", &numPassengers);

if (flights[flightChoice - 1].seatsAvailable >= numPassengers) {


// Update the available seats
flights[flightChoice - 1].seatsAvailable -= numPassengers;
printf("Reservation successful!\n");
} else {
printf("Not enough seats available for this flight.\n");
}
} else {
printf("Invalid flight number.\n");
}
}

int main() {
struct Flight flights[MAX_FLIGHTS];
int numFlights = 3; // You can change this to the desired number of flights

// Initialize some sample flights


flights[0].flightNumber = 1;
strcpy(flights[0].destination, "New York");
flights[0].seatsAvailable = 50;
flights[0].fare = 500.0;
flights[1].flightNumber = 2;
strcpy(flights[1].destination, "Los Angeles");
flights[1].seatsAvailable = 30;
flights[1].fare = 400.0;

flights[2].flightNumber = 3;
strcpy(flights[2].destination, "Chicago");
flights[2].seatsAvailable = 20;
flights[2].fare = 350.0;

int choice;
do {
printf("Airline Reservation System:\n");
printf("1. Display available flights\n");
printf("2. Make a reservation\n");
printf("3. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);

switch (choice) {
case 1:
displayFlights(flights, numFlights);
break;
case 2:
makeReservation(flights, numFlights);
break;
case 3:
printf("Goodbye!\n");
break;
default:
printf("Invalid choice. Please try again.\n");
}
} while (choice != 3);

return 0;
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy