Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have found the answer for Question 2,but can\'t find the solution for Question

ID: 3672556 • Letter: I

Question

I have found the answer for Question 2,but can't find the solution for Question 3.Please help.I would really appreciate.

Q2: The Colossus Airlines fleet consists of one plane with a seating capacity of 12. It makes one flight daily. Write a seating reservation program with the following features:
a. The program uses an array of 12 structures. Each structure should hold 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.
b. The program displays the following menu:
To choose a function, enter its letter label:
a) Show number of empty seats
b) Show list of empty seats
c) Show alphabetical list of seats
d) Assign a customer to a seat assignment
e) Delete a seat assignment
f) Quit
c. The program successfully executes the promises of its menu. Choices d) and e) require additional input, and each should enable the user to abort an entry.
d. After executing a particular function, the program shows the menu again, except for choice f).
e. Data is saved in a file between runs. When the program is restarted, it first loads in the data, if any, from the file.


Q3: Colossus Airlines (from Q2) acquires a second plane (same capacity) and expands its service to four flights daily (Flights 102, 311, 444, and 519). Expand the program to handle four flights. Have a top-level menu that offers a choice of flights and the option to quit. Selecting a particular flight should then bring up a menu similar to that of Q2. However, one new item should be added: confirming a seat assignment. Also, the quit choice should be replaced with the choice of exiting to the top-level menu. Each display should indicate which flight is currently being handled. Also, the seat assignment display should indicate the confirmation status.

Explanation / Answer

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SEAT 12
#define MAX 30
#define DATAFILE "data.bat"
struct seat
{
int identi;
char marker;
char lname [MAX];
char fname [MAX];
};
struct seat airline [SEAT] = {
{1, 'N', "null", "null"},
{2, 'N', "null", "null"},
{3, 'N', "null", "null"},
{4, 'N', "null", "null"},
{5, 'N', "null", "null"},
{6, 'N', "null", "null"},
{7, 'N', "null", "null"},
{8, 'N', "null", "null"},
{9, 'N', "null", "null"},
{10, 'N', "null", "null"},
{11, 'N', "null", "null"},
{12, 'N', "null", "null"},
};
void menu (void);
void flush (void);
void initial (void);
void deal_choice (char);
void show_number_empty (void);
void show_list_empty (void);
void order_seat (void);
void unorder_seat (void);
void show_list_alph (void);
int main (void)
{
char choice;
while (menu (), scanf ( "% c", & choice) == 1 && choice! = 'f')
{
flush ();
initial ();
deal_choice (choice);
}
}
void menu (void)
{
puts ( "=============") ;
puts ( "To choose a function, enter its letter label:");
puts ( "a) Show number of empty seats");
puts ( "b) Show list of empty seats");
puts ( "c) Show alphabetical list of seats");
puts ( "d) Assign a customer to a seat assignment");
puts ( "e) Delete a seat assignment");
puts ( "f) Quit");
puts ( "==============") ;
}
void flush (void)
{
while (getchar ()! = ' n')
continue;
}
void deal_choice (char ch)
{
switch (ch)
{
case 'a': show_number_empty ();
break;
case 'b': show_list_empty ();
break;
case 'c': show_list_alph ();
break;
case 'd': order_seat ();
break;
case 'e': unorder_seat ();
break;
case 'f': exit (1);
break;
default: break;
}
}
void initial (void)
{
FILE * fp;
struct seat temp;
int i;
if ((fp = fopen (DATAFILE, "ab +")) == NULL)
{
fprintf (stderr, ". Can not open file% s n", DATAFILE);
exit (2);
}
rewind (fp);
if (fread (& temp, sizeof (struct seat), 1, fp)! = 1)
fwrite (airline, sizeof (struct seat), SEAT, fp);
fclose (fp);
}
void show_number_empty (void)
{
int i;
int ct;
FILE * fp;
struct seat temp;
if ((fp = fopen (DATAFILE, "rb")) == NULL)
{
fprintf (stderr, ". Can not open file% s n", DATAFILE);
exit (2);
}
rewind (fp);
for (ct = 0, i = 0; i <SEAT; i ++)
{
fread (& temp, sizeof (struct seat), 1, fp);
if (temp.marker == 'N')
ct ++;
}
puts ( " n ********** ");
if (ct> 0)
printf ( " nNow have% d seats have not ordered n n.", ct);
else
printf ( ". nI'm so sorry, all seats has been ordered n n");
puts ( "************* n ");
fclose (fp);
}
void show_list_empty (void)
{
int i, j;
FILE * fp;
struct seat temp;
if ((fp = fopen (DATAFILE, "r + b")) == NULL)
{
fprintf (stderr, ". Can not open file% s n", DATAFILE);
exit (3);
}
rewind (fp);
puts ( " n **************** n ");
for (j = 0, i = 0; i <SEAT; i ++)
{
fread (& temp, sizeof (struct seat), 1, fp);
if (temp.marker == 'N')
{
printf ( "SEAT% -5d ======> tN n", temp.identi);
j ++;
}
}
if (j == 0)
{
printf ( "I'm so sorry, there is not seat n");
}
puts ( " n ************* n ");
fclose (fp);
}
void order_seat (void)
{
int i;
int ticket;
char ch;
FILE * fp;
struct seat temp;
if ((fp = fopen (DATAFILE, "rw + b")) == NULL)
{
fprintf (stderr, ". Can not open file% s n", DATAFILE);
exit (4);
}
rewind (fp);
printf ( "Input the seat number you want to order (1 to% d) n", SEAT);
while (scanf ( "% d", & ticket) == 1)
{
if (ticket <1 || ticket> 12)
{
printf ( "Invalid input (1-% d)", SEAT);
continue;
}
for (i = 0; i <SEAT; i ++)
{
fread (& temp, sizeof (struct seat), 1, fp);
if (ticket == temp.identi && temp.marker == 'N')
{
printf ( "? SEAT% d have not been ordered, are you sure (y / n) n", temp.identi);
flush ();
scanf ( "% c", & ch);
flush ();
if (strchr ( "Yy", ch))
{
temp.marker = 'Y';
puts ( "Enter your first name.");
gets (temp.fname);
puts ( "Enter your last name.");
gets (temp.lname);
fseek (fp, -sizeof (struct seat), SEEK_CUR);
fwrite (& temp, sizeof (struct seat), 1, fp);
printf ( " nSEAT% d order successfull% s% s n n", ticket, temp.fname, temp.lname);
fclose (fp);
return;
}
else
{
fclose (fp);
flush ();
return;
}
}

}
rewind (fp);
printf ( "SEAT% d has already been ordered, choice others n.", ticket);
}

}
void unorder_seat (void)
{
int i;
char ch;
FILE * fp;
struct seat temp;
char fname [14];
char lname [14];
if ((fp = fopen (DATAFILE, "rw + b")) == NULL)
{
fprintf (stderr, ". Can not open file% s n", DATAFILE);
exit (5);
}
rewind (fp);
puts ( "Input your firstname.");
gets (fname);
puts ( "Input your last name.");
gets (lname);
for (i = 0; i <SEAT; i ++)
{
fread (& temp, sizeof (struct seat), 1, fp);
if (strcmp (temp.fname, fname) == 0 && strcmp (temp.lname, lname) == 0)
{
printf ( "% s% s you have ordered seat% d, are you sure unordered (y / n)?", fname, lname, temp.identi);
scanf ( "% c", & ch);
if (strchr ( "Yy", ch))
{
temp.marker = 'N';
strcpy (temp.fname, "null");
strcpy (temp.lname, "null");
fseek (fp, -sizeof (struct seat), SEEK_CUR);
fwrite (& temp, sizeof (struct seat), 1, fp);
printf ( " nSEAT% d unorder successfully% s% s n n", temp.identi, fname, lname);
fclose (fp);
flush ();
return;
}
else
{
flush ();
fclose (fp);
return;
}
}
}
printf ( " n% s% s you have not ordered any seat n n.", fname, lname);
}
void show_list_alph (void)
{
int i, j, k;
FILE * fp;
char fullname [2 * MAX];
struct seat temp;
struct seat passenger [SEAT];
if ((fp = fopen (DATAFILE, "rb")) == NULL)
{
fprintf (stderr, ". Can not open file% s n", DATAFILE);
exit (6);
}
for (j = 0, i = 0; i <SEAT; i ++)
{
fread (& temp, sizeof (struct seat), 1, fp);
if (strcmp (temp.fname, "null")! = 0 && strcmp (temp.lname, "null")! = 0)
passenger [j ++] = temp;
}
fclose (fp);
puts ( " n ************ n ");
if (j == 0)
{
printf ( " nThere has nobody ordered any seat n n.");
puts ( " n ********* n ");
return;
}
for (i = 0; i <j; i ++)
for (k = i; k <j; k ++)
{
if (strcmp (passenger [i] .fname, passenger [k] .fname)> 0)
{
temp = passenger [i];
passenger [i] = passenger [k];
passenger [k] = temp;
}
if (strcmp (passenger [i] .fname, passenger [k] .fname) == 0)
if (strcmp (passenger [i] .lname, passenger [k] .lname)> 0)
{
temp = passenger [i];
passenger [i] = passenger [k];
passenger [k] = temp;
}
}
for (i = 0; i <j; i ++)
{
strcpy (fullname, passenger [i] .fname);
strcat (fullname, passenger [i] .lname);
printf ( "% - 30s ordered SEAT% d n", fullname, passenger [i] .identi);
}
puts ( " n ********** n ");
}