Question: Modify main() to allow the user to enter command 'd', followed by the user entering a seat number. Call SeatMakeEmpty() to delete the seat. #include

Modify main() to allow the user to enter command 'd', followed by the user entering a seat number. Call SeatMakeEmpty() to delete the seat.

#include #include #include

typedef struct Seat_struct { char firstName[50]; char lastName[50]; int amountPaid; } Seat;

/*** Functions for Seat ***/

void SeatMakeEmpty(Seat* seat) { strcpy((*seat).firstName, "empty"); strcpy((*seat).lastName, "empty"); (*seat).amountPaid = 0; return; }

bool SeatIsEmpty(Seat seat) { return (strcmp(seat.firstName, "empty") == 0); }

void SeatPrint(Seat seat) { printf("%s ", seat.firstName); printf("%s, ", seat.lastName); printf("Paid: %d ", seat.amountPaid); return; } /*** End functions for Seat ***/

/*** Functions for array of Seat ***/ void SeatsMakeEmpty(Seat seats[], int numSeats) { int i = 0; for (i = 0; i < numSeats; ++i) { SeatMakeEmpty(&seats[i]); } return; }

void SeatsPrint(Seat seats[], int numSeats) { int i = 0; for (i = 0; i < numSeats; ++i) { printf("%d: ", i); SeatPrint(seats[i]); } return; } /*** End functions for array of Seat ***/

int main(void) { const int NUM_SEATS = 5; char userKey = '-'; int seatNum = 0; Seat allSeats[NUM_SEATS]; Seat currSeat; SeatsMakeEmpty(allSeats, NUM_SEATS); while (userKey != 'q') { printf("Enter command (p/r/q): "); scanf(" %c", &userKey); if (userKey == 'p') { // Print seats SeatsPrint(allSeats, NUM_SEATS); printf(" "); } else if (userKey == 'r') { // Reserve seat printf("Enter seat num: "); scanf("%d", &seatNum); if (!SeatIsEmpty(allSeats[seatNum])) { printf("Seat not empty. "); } else { printf("Enter first name: "); scanf("%s", currSeat.firstName); printf("Enter last name: "); scanf("%s", currSeat.lastName); printf("Enter amount paid: "); scanf("%d", &currSeat.amountPaid); allSeats[seatNum] = currSeat; printf("Completed. "); } } // FIXME: Add option to delete reservations else if (userKey == 'q') { // Quit printf("Quitting. "); } else { printf("Invalid command. "); } } return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!