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

This is using C program. We are specifically using eclipse to write this program

ID: 3804893 • Letter: T

Question

This is using C program. We are specifically using eclipse to write this program usinmg C code.

Programming Exercise:

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 list of seats reserved (alphabetical by last name)

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).

Explanation / Answer

Please refer below code

# include<stdio.h>
# include<stdlib.h>
# include <stdbool.h>

typedef struct airline
{
int seat_identification_number;
bool seat_assigned;
char lastName[100];
char firstName[100];

}airline;

void show_empty(airline *ptr)
{
int count = 0,i;

for(i = 0; i < 12; i++)
if(!ptr[i].seat_assigned)
count++;

printf("Number Of Empty seats : %d ",count);
}
void show_list_empty(airline *ptr)
{
int i=0;
printf(" Below are empty Seats ");

for(i = 0; i < 12; i++)
{
if(!ptr[i].seat_assigned)
printf("%d ", ptr[i].seat_identification_number);
}
}
void show_list_reserved(airline *ptr)
{
int i,j = 0;
airline t;

airline *ptr1;

for(i = 0; i < 12; i++)
{
strcpy(ptr1[i].firstName, ptr[i].firstName);
strcpy(ptr1[i].lastName, ptr[i].lastName);
ptr1[i].seat_assigned = ptr[i].seat_assigned;
ptr1[i].seat_identification_number = ptr[i].seat_assigned;
}
for (i = 1; i < 12; i++)
{
for (j = 1; j < 12; j++)
{
if (strcmp(ptr1[j - 1].lastName, ptr1[j].lastName) > 0)
{
strcpy(t.lastName, ptr1[j - 1].lastName);
strcpy(t.firstName, ptr1[j-1].firstName);
t.seat_assigned = ptr1[j-1].seat_assigned;
t.seat_identification_number = ptr1[j-1].seat_identification_number;

strcpy(ptr1[j - 1].lastName, ptr1[j].lastName);
strcpy(ptr1[j - 1].firstName, ptr1[j].firstName);
ptr1[j - 1].seat_assigned = ptr1[j].seat_assigned;
ptr1[j - 1].seat_identification_number = ptr1[j].seat_identification_number;

strcpy(ptr1[j].lastName, t.lastName);
strcpy(ptr1[j].firstName, t.firstName);
ptr1[j].seat_assigned = t.seat_assigned;
ptr1[j].seat_identification_number = t.seat_identification_number;

}
}
}
for(i = 0; i < 12; i++)
{
if(ptr1[i].firstName != "")
printf("%s ", ptr1[i].lastName);
}
}
void assign_seat(char *FN, char *LN,int SIN,airline *ptr)
{
ptr[SIN].seat_identification_number = SIN;
strcpy(ptr[SIN].firstName,FN);
strcpy(ptr[SIN].lastName,LN);
ptr[SIN].seat_assigned = 1;
}
void delete_seat(int SIN, airline *ptr)
{
strcpy(ptr[SIN].firstName, "");
strcpy(ptr[SIN].lastName, "");
ptr[SIN].seat_assigned = 0;
}

int main()
{
airline *ptr;
char ch;
char FN[100];
char LN[100];
int SIN,i;
ptr = (airline *)malloc(12 * sizeof(airline));

for(i = 0; i < 12; i++)
{
strcpy(ptr[i].firstName, " ");
strcpy(ptr[i].lastName, " ");
ptr[i].seat_assigned = 0;
ptr[i].seat_identification_number = i + 1;
}

do
{
printf("Choose an Option from below ");

printf("a. Show Number of Empty Seats b. Show list of Empty seats c. Show list of seats Reserved d. Assign a customer to a seat assignment e. Delete a seat assignment f. Quit ");
scanf("%c", &ch);

switch (ch)
{
case 'a':
show_empty(ptr);
break;

case 'b':
show_list_empty(ptr);
break;

case 'c':
show_list_reserved(ptr);
break;

case 'd':
printf(" Enter First Name : ");
scanf("%s", FN);

printf(" Enter Last Name : ");
scanf("%s", LN);

printf(" Enter Seat Identification Number : ");
scanf("%d", &SIN);
assign_seat(FN,LN,SIN,ptr);
break;

case 'e' :
printf(" Enter Seat Identification Number for deleting : ");
scanf("%d", &SIN);
delete_seat(SIN,ptr);
break;

default :
break;
}

}while(ch != 'f');
return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote