C Language Project (Airline Booking)
C Language Project (Airline Booking)
PROJECT REPORT
ON
“AIRLINE BOOKING”
SUBMITTED TO
DIPLOMA IN
COMPUTER ENGINEERING
UNDER GUIDENCE OF
PROF. DHONDE. S.A
DEPARTMENT of Computer
A.C.S.’S
DIPLOMA IN ENGINEERING AND TECHNOLOGY, ASHTI
(2022-2023)
A.C.S.’S
CERTIFICATE
This is to Certify that the project report entitled
“Airline Booking”
Submitted by
1. Mr. Manmode Aniruddha Badrinath 2215020052
2. Mr. Kharat Chetan Sanjay 2215020051
3. Miss. Khote Ashwini Ankush 2215020038
In the academic year 2022-2023 in the partial fulfilment of second semester diploma in computer
engineering. It is certified that all suggestion indicated for internal assessment have been incorporated in report.
The project has been approved as it satisfies the academic requirement in respect work prescribed for the said
degree.
1. Introduction
Specialties
The program uses a struct data type to store booking information, including
the passenger's name and the flight number.
The program restricts the number of bookings to a maximum of five and the
length of passenger names to a maximum of 50 characters.
The program includes input validation to ensure that valid flight numbers are
entered, and it prevents double-booking by checking for duplicate bookings
before adding a new booking.
The program uses several predefined constants, including MAX_FLIGHTS (the maximum
number of flights that can be booked), and MAX_NAME_LEN (the maximum length of a
passenger's name).
It also defines a Booking structure that contains two fields, name (a character array of length
MAX_NAME_LEN) and flight_num (an integer representing the flight number).
The program also declares two global variables, bookings (an array of Booking structures)
and num_bookings (an integer representing the number of bookings made so far).
The program includes three functions: book_flight, view_bookings, and cancel_booking. The
book_flight function allows the user to book a flight by entering their name and the flight
number they want to book.
If the flight is already booked or if the maximum number of flights has been reached, the
function informs the user and returns. If the booking is successful, the function adds the
booking to the bookings array and increments num_bookings.
The view_bookings function simply displays all the bookings that have been made so far. If
there are no bookings, the function informs the user and returns.
The cancel_booking function allows the user to cancel a booking by entering their name and
the flight number they want to cancel. If the booking is found, the function removes it from
the bookings array and decrements num_bookings.
If the booking is not found, the function informs the user and returns.
2.7 Exit
Finally, the main function provides a menu-driven interface for the user. The user can choose
to book a flight, view bookings, cancel a booking, or exit the program. Invalid choices are
handled gracefully by informing the user and returning to the menu.
Source Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_FLIGHTS 6
#define MAX_NAME_LEN 50
typedef struct {
char name[MAX_NAME_LEN];
int flight_num;
} Booking;
Booking bookings[MAX_FLIGHTS];
int num_bookings = 0;
void book_flight() {
if (num_bookings >= MAX_FLIGHTS) {
printf("All flights are booked. Please try again later.\n");
return;
}
char name[MAX_NAME_LEN];
int flight_num;
printf("Enter your name: ");
scanf("%s", name);
printf("Enter the flight number you want to book (1-5): ");
scanf("%d", &flight_num);
int i;
// Check if flight is already booked
for (i = 0; i < num_bookings; i++) {
if (bookings[i].flight_num == flight_num) {
printf("Flight %d is already booked by %s.\n", flight_num, bookings[i].name);
return;
}
}
// Add booking
Booking new_booking;
strcpy(new_booking.name, name);
new_booking.flight_num = flight_num;
bookings[num_bookings] = new_booking;
num_bookings++;
void view_bookings() {
if (num_bookings == 0) {
printf("No flights have been booked.\n");
int i;
printf("Booked flights:\n");
for ( i = 0; i < num_bookings; i++) {
printf("Flight %d booked by %s.\n", bookings[i].flight_num, bookings[i].name);
}
}
void cancel_booking() {
if (num_bookings == 0) {
printf("No flights have been booked.\n");
return;
}
char name[MAX_NAME_LEN];
int flight_num;
printf("Enter your name: ");
scanf("%s", name);
printf("Enter the flight number you want to cancel (1-5): ");
scanf("%d", &flight_num);
int i;
// Find booking to cancel
int index_to_remove = -1;
for ( i = 0; i < num_bookings; i++) {
if (strcmp(bookings[i].name, name) == 0 && bookings[i].flight_num == flight_num) {
index_to_remove = i;
break;
}
}
if (index_to_remove == -1) {
printf("No booking found for flight %d by %s.\n", flight_num, name);
return;
}
// Remove booking
for ( i = index_to_remove; i < num_bookings - 1; i++) {
bookings[i] = bookings[i+1];
}
num_bookings--;
int main() {
int choice;
while (1) {
system("cls");
printf("Menu:\n");
printf("1. Book a flight\n");
switch (choice) {
case 1:
book_flight();
break;
case 2:
view_bookings();
break;
case 3:
cancel_booking();
break;
case 4:
printf("Exiting program. Goodbye!\n");
exit(0);
default:
printf("Invalid choice. Please try again.\n");
}
getch();
}
return 0;
}
References
1) Figures are download from www.msbte.com
2) www.google.com