×
Samples Blogs Make Payment About Us Reviews 4.9/5 Order Now

Create a Program to Implement Airline Reservation in C++ Assignment Solution

July 01, 2024
Aisha Kaur
Aisha Kaur
🇨🇦 Canada
C++
Aisha Kaur has a Bachelor’s degree in Computer Engineering from the University of Toronto and a rich background in C++ programming and software engineering. She has completed over 600 assignments, specializing in data structures, algorithms, and multi-threaded applications in Visual Studio. Aisha is known for her clear, concise coding style and her dedication to helping students achieve academic success.
Key Topics
  • Instructions
  • Requirements and Specifications
Tip of the day
Focus on understanding TensorFlow's computational graph and its eager execution mode. Use pre-built functions like tf.data for efficient data pipelines.
News
The latest version of Google's machine learning library, offering improved performance, streamlined APIs, and expanded support for reinforcement learning, making it a powerful tool for AI development.

Instructions

Objective
Write a C++ homework program to implement airline reservation.

Requirements and Specifications

PRG255 - Assignment
Title: Econo-Flight Airline Reservation Program
Write the Econo-Flight Airline Reservation Program with the following features:
Description :The Econo-Airlines fleet consists of one plane with a seating capacity of 12.
It makes one flight daily.
The aircraft seating is arranged in 6 rows with 2 seats per row. The program uses an array of 12 structures. Each structure holds a seat identification number, a marker that indicates whether the seat is assigned, the last name of the seat holder, and the first name of the seat holder.
The program is to displays the following menu. Use a do while loop and a switch to make the selection. The selection must NOT be case sensitive. Each selection should call a different function.
To choose a function, enter its letter label:
  1. Display ALL seat assignments (including Empty).
  2. Show ONLY a list of empty seats and show total of empty seats
  3. Show ONLY the assigned seats with name of person and total assigned.
  4. Assign the customer to an empty seat.
  5. Delete ONE seat assignment.
  6. Delete ALL seat assignments.
  7. Quit program.
Note all data must be saved to a file.
  • The program must successfully execute the premise of the menu.
  • Data is to be saved to a file between runs. When the program is restarted,
it must first load the last status.
Do not use global variables. (except for the structure definition).
Submission requirements:
The first page is the cover page. (Word or PDF document)
  • Name of the Project
  • Name of your Professor
  • Your name and student number.
Marks:
Format (2) _____
User interface (2) _____
Program Compiles (1) _____
Functionality (7) _____
Data I/O to disk (3) _____
Total _____
Source Code
#include
#include <stdlib.h>
#include <string.h>
struct seats {
int seat_Number;
char seat_avail;
char first_name[40];
char last_name[40];
};
void startMenu();
void ecoMenu();
void seatArrange();
void save_to_file(struct seats seating_data[]);
void read_from_file(struct seats seating_data[]);
int main() {
struct seats s[12];
char choice = 'z';
char deleteInpt;
int emptySeats = 12;
int full = 0;
int num = 0;
int seatNum;
int selectSeat;
char firstName[20];
char lastName[20];
char backupFilePath[100];
int file_flag = 0;
for (seatNum = 0; seatNum < 12; seatNum++) {
s[seatNum].seat_avail = 'y';
s[seatNum].first_name[0] = '\0';
s[seatNum].last_name[0] = '\0';
s[seatNum].seat_Number = seatNum + 1;
}
do {
if (file_flag == 1) {
read_from_file(s);
}
Menu();
scanf("%c", &choice);
system("cls");
switch (choice) {
case 'a':
case 'A':
seatArrange();
for (seatNum = 0; seatNum < 12; seatNum++) {
printf("\n\t%d", s[seatNum].seat_Number);
if (s[seatNum].seat_avail == 'y' || s[seatNum].seat_avail == 'Y')
printf("\t\tEmpty");
else {
printf("\t\tOccupied");
printf("\t %s", s[seatNum].last_name);
printf("\t%s", s[seatNum].first_name);
}
}
printf("\n");
system("pause");
system("cls");
break;
case 'b':
case 'B':
seatArrange();
emptySeats = 0;
for (seatNum = 0; seatNum < 12; seatNum++) {
if (s[seatNum].seat_avail == 'y' || s[seatNum].seat_avail == 'Y') {
printf("\n\tseat %d", s[seatNum].seat_Number);
emptySeats++;
}
}
printf("\n\n\nThere are %d Empty Seats\n", emptySeats);
system("\npause");
break;
case 'c':
case 'C':
seatArrange();
full = 0;
for (seatNum = 0; seatNum < 12; seatNum++) {
if (s[seatNum].seat_avail == 'n' || s[seatNum].seat_avail == 'N') {
printf("\n\tseat %d", s[seatNum].seat_Number);
printf("\t\t%s", s[seatNum].first_name);
printf("\t\t%s", s[seatNum].last_name);
full += 1;
}
}
printf("\n\nThere are %d ASSIGNED Seats\n", full);
system("pause");
break;
case 'd':
case 'D':
printf("\tThe following seats are available -\n\n");
printf("There are %d Filled Seats\n", full);
printf("Which Seat would you like (0 to exit)?\n");
scanf("%d", &selectSeat);
printf("Seat selected: %d", selectSeat);
if (selectSeat == 0) {
break;
}
else {
selectSeat--;
printf("\nInput Last Name:\n");
scanf("%s", &lastName);
printf("\nInput First Name:\n");
scanf("%s", &firstName);
system("\npause");
}
if (s[selectSeat].seat_avail == 'y' || s[selectSeat].seat_avail == 'Y') {
printf("\nAssigned seat number: %d", s[selectSeat].seat_Number);
strcpy(s[selectSeat].first_name, firstName);
strcpy(s[selectSeat].last_name, lastName);
s[selectSeat].seat_avail = 'n';
}
else {
printf("\nAssigned seat number: %d is not available, select another!", s[selectSeat].seat_Number);
}
save_to_file(s);
file_flag = 1;
printf("\n");
system("\npause");
break;
case 'e':
case 'E':
printf("\tHere are the seats you can delete\n");
emptySeats = 0;
for (seatNum = 0; seatNum < 12; seatNum++) {
if (s[seatNum].seat_avail == 'n' || s[seatNum].seat_avail == 'N') {
printf("\n\tseat %d", s[seatNum].seat_Number);
emptySeats++;
}
}
printf("\nWhich Seat would you like to delete (0 to exit)?\n");
scanf("%d", &selectSeat);
selectSeat--;
if (s[selectSeat].seat_avail == 'n' || s[selectSeat].seat_avail == 'N') {
printf("\n assigned seat number: %d", s[selectSeat].seat_Number);
strcpy(s[selectSeat].first_name, "\0");
strcpy(s[selectSeat].last_name, "\0");
s[selectSeat].seat_avail = 'y';
printf("Deleted entry on seat: %d", selectSeat);
}
else {
printf("\n selected seat number: %d is already empty, select another!", s[selectSeat].seat_Number);
}
save_to_file(s);
file_flag = 1;
printf("\n");
system("\npause");
break;
case 'f':
case 'F':
printf("Are you sure you want to RESET the DATA (y/n)\n");
scanf("%s", &deleteInpt);
if (deleteInpt == 'y' || deleteInpt == 'Y') {
for (seatNum = 0; seatNum < 12; seatNum++) {
s[seatNum].seat_avail = 'y';
s[seatNum].first_name[0] = '\0';
s[seatNum].last_name[0] = '\0';
s[seatNum].seat_Number = seatNum + 1;
}
save_to_file(s);
file_flag = 1;
}
else
system("pause");
break;
case 'g':
case 'G':
goto exit_loop;
break;
case 'h':
case 'H':
printf("Loading data from previous save");
read_from_file(s);
file_flag = 1;
break;
};
} while (choice != 'g' || choice != 'G');
exit_loop:;
}
void Menu() {
printf("\na. Display all seat assignments (including empty) \n");
printf("b. Show only the empty seat and total empty seat \n");
printf("c. Show only the assigned seats with name of person and total assigned \n");
printf("d. Assign the customer to an empty seat \n");
printf("e. Delete ONE seat assignment \n");
printf("f. Delete ALL seat assignment \n");
printf("q. Quit \n");
printf("Enter your option: \n");
}
void seatArrange() {
printf("\t\t\tSeating Arragement\n\n");
printf("\tSeat#:\t\tStatus:\t\tClient Name:\n");
}
void save_to_file(struct seats seating_data[]) {
FILE* fptr;
fopen("airlineSeating.txt", "w");
if ((fptr = fopen("airlineSeating.txt", "w")) == NULL) {
printf("Error opening file!\n\n");
exit(1);
}
for (int seatNum = 0; seatNum < 12; seatNum++) {
if (seating_data[seatNum].seat_avail == 'n' || seating_data[seatNum].seat_avail == 'N') {
fwrite(&seating_data[seatNum], sizeof(struct seats), 1, fptr);
}
}
fclose(fptr);
}
void read_from_file(struct seats seating_data[]) {
FILE* fptr;
struct seats input_data;
int seat_no;
fopen("airlineSeating.txt", "r");
if ((fptr = fopen("airlineSeating.txt", "r")) == NULL) {
printf("Error Reading File...");
}
while (fread(&input_data, sizeof(struct seats), 1, fptr)) {
seat_no = input_data.seat_Number;
seat_no--;
seating_data[seat_no].seat_avail = 'n';
strcpy(seating_data[seat_no].first_name, input_data.first_name);
strcpy(seating_data[seat_no].last_name, input_data.last_name);
}
printf("File Loadded...\n\n");
}

Related Samples

Discover our C++ Assignment samples, designed to support students from basics to advanced topics. Explore solutions covering object-oriented programming, data structures, algorithms, and more. Each example includes well-commented code and explanations, ensuring clarity and comprehension. Elevate your C++ proficiency with our comprehensive resources tailored for academic success.