Code:
#include<stdio.h>
#include<conio.h>
#include<string.h>
#define size 12
typedef struct B{
char lastname[20];
char firstname[20];
}name;
typedef struct A{
char seat_id[3];
char status;
name person;
}seat;
int number_empty_seats(seat a[]);
void list_empty_seats(seat a[]);
void list__assigned_seats(seat a[]);
void assign_seat(seat *Seats);
void delete_seat(seat *Seats);
void quit(void);
int main(void)
{
seat seats[size] = {{"A1" ,'E'},{"A2", 'E'} ,{"A3",'E'}, {"A4",'E'},{"A5", 'E'},{"A6", 'E'},{"B1", 'E'},{"B2", 'E'},{"B3", 'E'}, {"B4",'E' },{"B5", 'E'},{"B6", 'E'}};
seat *p = &seats[0];
int choice;
do
{
printf("\n******Menu******\n");
printf("1. Show total number of empty seats: \n");
printf("2.Show lists of empty seats: \n");
printf("3.List of assigned seats with name of person: \n");
printf("4.Assign the custormer to an empty seat: \n");
printf("5.Delete assigned seat: \n");
printf("6. Quit program\n");
printf("\n------Enter Selection => ");
scanf("%d", &choice);
printf("\n");
switch (choice)
{
case 1:
number_empty_seats(seats);
break;
case 2:
list_empty_seats(seats);
break;
case 3:
list__assigned_seats(seats);
break;
case 4:
assign_seat(p);
break;
case 5:
delete_seat(p);
break;
case 6:
quit();
break;
default:
printf("Invalid choice\n");
}
} while (choice != 6);
}
int number_empty_seats(seat a[])
{
int x;
int count = 0;
for (x = 0; x < size; x++)
{
if (a[x].status == 'E')
{
count = count++;
}
}
printf("Number of empty seat is => %d \n", count);
_getch();
return count;
}
void list_empty_seats(seat a[])
{
int y, j, k;
for (y = 0; y < size; y++)
{
if (a[y].status == 'E')
{
printf("%s is empty seat\n", a[y].seat_id);
}
}
_getch();
}
void list__assigned_seats(seat a[])
{
int z;
for (z = 0; z < size; z++)
{
if (a[z].status == 'F')
{
printf("Seat %s has been assigned to Custormer %s\n", a[z].seat_id, a[z].person);
}
}
printf("\nCurrently there are no seats have been assigned");
_getch();
}
void assign_seat(seat *Seats)
{
int g;
int nums;
for (g = 0; g < size; g++)
{
if (Seats[g].status == 'E')
{
printf("Enter custormer's First Name=> ");
scanf("%s", &Seats[g].person.firstname);
printf("Enter customer's Last Name=> ");
scanf("%s", &Seats[g].person.lastname);
printf("Do you want to assign seat %s to custormer %s %s\n", Seats[g].seat_id, Seats[g].person.lastname, Seats[g].person.firstname);
printf("1=Yes/ 2=No? => ");
scanf("%d", &nums);
if (nums == 1)
{
Seats[g].status == 'F';
printf("Seat %s has been assigned successfully to custormer %s %s\n\n", Seats[g].seat_id, Seats[g].person.lastname, Seats[g].person.firstname);
return;
}
else
printf("You have declined to assign the seat for custormer\n\n");
}
}
_getch();
}
void delete_seat(seat *Seats)
{
int h, k;
int nums;
int choice;
char PassengerLastName[20];
printf("Seat ID\t\tCUstormer Name\n");
for (h = 0; h < size; h++)
{
if (Seats[h].status == 'F')
{
printf("%s\t\t\t%s %s\n", Seats[h].seat_id, Seats[h].person.lastname, Seats[h].person.firstname);
}
}
printf("\n");
printf("Enter passenger Last Name you want to cancel seat => ");
scanf("%s", &PassengerLastName);
for (k = 0; k < size; k++)
{
if (Seats[k].status == 'F' && (Seats[k].person.lastname, PassengerLastName)==0)
{
printf("Are you sure you want to cancel seat of Custormer %s?\n", PassengerLastName);
printf("1-Yes / 2-No\n");
scanf("%d", &choice);
if (choice == 1)
{
printf("you are successful cancel the seat!!!\n");
return;
}
if (choice == 2)
{
printf("You have declined\n");
return;
}
}
_getch();
}
}
void quit()
{
printf("You are now QUIT the program\n");
printf("Thank you");
_getch();
}