Tip of the day
News
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:
- Display ALL seat assignments (including Empty).
- Show ONLY a list of empty seats and show total of empty seats
- Show ONLY the assigned seats with name of person and total assigned.
- Assign the customer to an empty seat.
- Delete ONE seat assignment.
- Delete ALL seat assignments.
- 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;}elsesystem("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.
C++
Word Count
6780 Words
Writer Name:Alexander Gough
Total Orders:2435
Satisfaction rate:
C++
Word Count
6185 Words
Writer Name:Neven Bell
Total Orders:2376
Satisfaction rate:
C++
Word Count
5749 Words
Writer Name:Professor Kevin Tan
Total Orders:569
Satisfaction rate:
C++
Word Count
4786 Words
Writer Name:Dr. Isabelle Taylor
Total Orders:580
Satisfaction rate:
C++
Word Count
3997 Words
Writer Name:Professor Oliver Bennett
Total Orders:304
Satisfaction rate:
C++
Word Count
6830 Words
Writer Name:Dr. Maddison Todd
Total Orders:865
Satisfaction rate:
C++
Word Count
4424 Words
Writer Name:Dr. Alexandra Mitchell
Total Orders:589
Satisfaction rate:
C++
Word Count
7250 Words
Writer Name:Mr. Harrison Yu
Total Orders:311
Satisfaction rate:
C++
Word Count
4894 Words
Writer Name:James Miller
Total Orders:824
Satisfaction rate:
C++
Word Count
5544 Words
Writer Name:Callum Chambers
Total Orders:932
Satisfaction rate:
C++
Word Count
3533 Words
Writer Name:Aaliyah Armstrong
Total Orders:658
Satisfaction rate:
C++
Word Count
3645 Words
Writer Name:Len E. Villasenor
Total Orders:489
Satisfaction rate:
C++
Word Count
4033 Words
Writer Name:Daniel M. Harrison
Total Orders:700
Satisfaction rate:
C++
Word Count
3576 Words
Writer Name:Dr. Isabella Wong
Total Orders:652
Satisfaction rate:
C++
Word Count
3600 Words
Writer Name:Prof. Liam Wilson
Total Orders:554
Satisfaction rate:
C++
Word Count
1035 Words
Writer Name:Professor Marcus Tan
Total Orders:544
Satisfaction rate:
C++
Word Count
6288 Words
Writer Name:Dr. Stephanie Kim
Total Orders:812
Satisfaction rate:
C++
Word Count
1586 Words
Writer Name:Ethan Patel
Total Orders:556
Satisfaction rate:
C++
Word Count
3852 Words
Writer Name:Sarah Rodriguez
Total Orders:689
Satisfaction rate:
C++
Word Count
4701 Words
Writer Name:Harry F. Grimmett
Total Orders:342
Satisfaction rate: