Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The code below is for a flight reservation system. It is written in the C language. Can you add a password for admin option? There

The code below is for a flight reservation system. It is written in the C language.

Can you add a password for admin option? There should also be an option to change the password in the Admin menu. It should ask once for the old password, ask for the new password twice, and change the password if it is correct.

Can you add the reserved flight list for the user option?

Can you add code to write these flights in the file?

File Name: reservation.c

#include  #include  /*Global variable holding flight index*/ int p = 0; /*structure defining flight*/ struct { char flightn[10]; char pilot[20]; char arrival[10]; char depart[10]; char from[20]; char to[20]; char seat[20][4][20]; }flight[20]; /*function prototype declarations*/ /* function to add a flight Input: flight details Output: None Return: None Side Effects: flight details will be updated in the flight structure */ void add_flight(); /* function to delete a flight Input: flight number Output: None Return: None Side Effects: flight details will be deleted in the flight structure */ void delete_flight(); /* function to reserve seats Input: seat details Output: None Return: None Side Effects: Seat reserved will be updated in the flight structure */ void allotment(); /* function to show the reservation details Input: flight details Output: Reservation Details Return: None Side Effects: None */ void show(); /* function to show the details of the available flights Input: Nil Output: Available flight Details Return: None Side Effects: None */ void avail(); /* function to display seat positions Input: Nil Output: Display seat positions Return: None Side Effects: None */ void position(int i); /* function to display a line Input: character to draw and number of characters Output: The line Return: None Side Effects: None */ void vline(char ch, int size); /* function to delete reservation Input: seat details Output: None Return: None Side Effects: Seat reserved will be marked "empty" in the flight structure */ void delete_reservation(); void admin_menu() { // displays admin menu int w, c; while(1) { vline('-',100); printf(" ***FLIGHT RESERVATION SYSTEM - ADMIN OPTIONS***"); vline('-',100); printf(" 1.Add flight"); printf(" 2.Delete Filght"); printf(" 3.Show a Flight Status"); printf(" 4.Show available flights"); printf(" 5.Return to main menu"); vline('-',100); printf(" Enter your choice:- "); scanf("%d", &w); switch(w) { case 1: add_flight(); break; case 2: delete_flight(); break; case 3: show(); break; case 4: avail(); break; case 5: return; default: printf(" Invalid Choice "); } } } void user_menu() { // displays user menu int w, c; while(1) { vline('-',100); printf(" ***FLIGHT RESERVATION SYSTEM - USER OPTIONS***"); vline('-',100); printf(" 1.Reservation"); printf(" 2.Cancel Reservation"); printf(" 3.Flights Available "); printf(" 4.Return to main menu"); vline('-',100); printf(" Enter your choice:- "); scanf("%d", &w); switch(w) { case 1: allotment(); break; case 2: delete_reservation(); break; case 3: avail(); break; case 4: return; default: printf(" Invalid Choice "); } } } int main() { int w, choice, c; while(1) { vline('-',100); printf(" ***ENTER AS***"); vline('-',100); printf(" 1.Admin"); printf(" 2.User"); printf(" 3.Quit"); vline('-',100); printf(" Enter your choice:- "); scanf("%d", &choice); switch (choice) { case 1: admin_menu(); break; case 2: user_menu(); break; case 3: return 0; default: printf(" Invalid choice "); } while ( (c = getchar()) != ' ' && c != EOF ); } return 0; } /* function to display a line Input: character to draw and number of characters Output: The line Return: None Side Effects: None */ void vline(char ch, int size) { printf(" "); for(int i=size;i>0;i--) printf("%c",ch); } /* function to add_flight flights Input: flight details Output: None Return: None Side Effects: flight details will be updates in the flight structure */ void add_flight() { int c; while ( (c = getchar()) != ' ' && c != EOF ); printf("Enter flight no: "); fgets(flight[p].flightn, 10, stdin); flight[p].flightn[strcspn(flight[p].flightn," ")] = 0; printf("Enter pilot's name: "); fgets(flight[p].pilot, 20, stdin); flight[p].pilot[strcspn(flight[p].pilot," ")] = 0; printf("Arrival time: "); fgets(flight[p].arrival, 10, stdin); flight[p].arrival[strcspn(flight[p].arrival," ")] = 0; printf("Departure: "); fgets(flight[p].depart, 10, stdin); flight[p].depart[strcspn(flight[p].depart," ")] = 0; printf("From: "); fgets(flight[p].from, 20, stdin); flight[p].from[strcspn(flight[p].from," ")] = 0; printf("To: "); fgets(flight[p].to, 20, stdin); flight[p].to[strcspn(flight[p].to," ")] = 0; for(int i=0; i<20;i++) for(int j=0;j<4;j++) strcpy(flight[p].seat[i][j], "Empty"); p++; } /* function to delete a flight Input: flight number Output: None Return: None Side Effects: flight details will be deleted in the flight structure */ void delete_flight() { int c; while ( (c = getchar()) != ' ' && c != EOF ); char flightno[10]; int found = 0; printf("Enter flight no: "); fgets(flightno, 10, stdin); flightno[strcspn(flightno," ")] = 0; for(int n=0; n80) printf(" There are only 80 seats available in this flight."); else { if (strcmp(flight[n].seat[seat/4][(seat%4)-1], "Empty")==0) { printf(" Enter passenger's name: "); fgets( flight[n].seat[seat/4][(seat%4)-1], 20, stdin); flight[n].seat[seat/4][(seat%4)-1][strcspn(flight[n].seat[seat/4][(seat%4)-1]," ")] = 0; break; } else printf(" The seat no. is already reserved. "); } } if(n>=p) { printf(" Enter correct flight no. "); goto top; } } /* function to show the reservation details Input: flight details Output: Reservation Details Return: None Side Effects: None */ void show() { int c; while ( (c = getchar()) != ' ' && c != EOF ); int n; char number[10]; printf("Enter flight no: "); fgets(number, 10, stdin); number[strcspn(number," ")] = 0; for(n=0;n=p) printf(" Flight not found."); } /* function to display seat positions Input: Nil Output: Display seat positions Return: None Side Effects: None */ void position(int l) { int s=0;p=0; for (int i =0; i<20;i++) { printf(" "); for (int j = 0;j<4; j++) { s++; if(strcmp(flight[l].seat[i][j], "Empty")==0) { printf("%10d. %-10s",s,flight[l].seat[i][j]); p++; } else { printf("%10d. %-10s",s,flight[l].seat[i][j]); } } } printf(" There are %d seats empty in flight No: %s",p,flight[l].flightn); } /* function to show the details of the available flights Input: Nil Output: Available flight Details Return: None Side Effects: None */ void avail() { if(p == 0) { printf(" No flights available"); return; } for(int n=0;n80) printf(" There are only 80 seats available in this flight."); else { printf(" Passenger Name: "); fgets( passenger, 20, stdin); passenger[strcspn(passenger," ")] = 0; if (strcmp(flight[n].seat[seat/4][(seat%4)-1], passenger)==0) { strcpy(flight[n].seat[seat/4][(seat%4)-1], "Empty"); printf(" Reservation cancelled successfully. "); break; } else { printf(" The seat no. is not reserved for %s ", passenger); break; } } } if(n>=p) { printf(" Enter correct flight no. "); goto top; } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

What are payroll disbursement fraud schemes?

Answered: 1 week ago