The code needs to be written in C Write a reservation system
The code needs to be written in C
Write a reservation system for an airline flight. Assume the airplane has 1 row with 20 seats in the row. Use link list to maintain a seating chart. Allow the user to choose from three options. Add a passenger to the seat. Request the passenger\'s name list. If seats are available let the passenger chose a seat. Add the passenger to the seating chart. If no seats are available, display message \"no seat available\". Remove a passenger from the listSolution
using System;
public class Reservation
{
private string[,] seatsArray;
public int totalAssignedFirstClass;
public int totalAssignedSecondClass;
public void ProcessReservations()
{
seatsArray = new string[1, 20];
int selectedClass = 0;
for (int i = 0; i <= seatsArray.GetLength(0); i++)
{
for (int j = 0; j <= seatsArray.GetLength(1); j++)
{ seatsArray[i, j] = \"A\"; }
}
for (int i = 0; i <= seatsArray.GetLength(0); i++)
{
for (int j = 0; j <= seatsArray.GetLength(1); j++)
{
Console.WriteLine(\"Please type 1 for First Class, 2 for Economy Class, or 3 to view status of all seats: \");
selectedClass = Convert.ToInt32(Console.ReadLine());
while (selectedClass < 1 || selectedClass > 3)
{
Console.WriteLine(\"Please only enter 1, 2, or 3 for First or Economy Class or to view status of all seats: \");
selectedClass = Convert.ToInt32(Console.ReadLine());
}
if (selectedClass == 1)
{
if (totalAssignedFirstClass == 5 && totalAssignedFirstClass < 5)
{
Console.WriteLine(\"Sorry, first class is full. Do you want to get a ticket for the economy class? (Enter: Y or N): \");
if (Console.ReadLine().Equals(\"N\"))
{
Console.WriteLine(\"Next plane leaves in 3 hours\");
i--;
}
else
{ assignSecondClass(); }
}
else if (totalAssignedFirstClass < 5)
{ assignFirstClass(); }
}
else if (totalAssignedSecondClass == 5 && totalAssignedFirstClass < 5)
{
Console.WriteLine(\"Sorry, economy class is full. Do you want to get a ticket for the first class? (Y or N): \");
if (Console.ReadLine().Equals(\"N\"))
{
Console.WriteLine(\"Next plane leaves in 3 hours\");
i--;
}
else { assignFirstClass(); }
}
else { assignSecondClass(); }
}
else
{
if (selectedClass == 3)
{
Console.Write(seatsArray[i, j]);
}
}
}
Console.WriteLine();
Console.WriteLine(\"Sorry, the plane is full. Next one leaves in 3 hours.\");
Console.ReadLine();
}
public void assignFirstClass()
{
string noDuplicate = \"X\";
Random rn = new Random();
int i = 0;
while (noDuplicate = \"A\")
{
noDuplicate = \"A\";
i = rn.Next(1, 6);
if (seatsArray[i] == \"A\")
noDuplicate = \"X\";
}
seatsArray[i] = \"A\";
totalAssignedFirstClass++;
Console.WriteLine(\"Assigned seat {0:N0}\", i);
}
public void assignSecondClass()
{
string noDuplicate = \"X\";
Random rn = new Random();
int i = 0;
while (noDuplicate = \"A\")
{
noDuplicate = \"A\";
i = rn.Next(6, 11);
if (seatsArray[i] == \"A\")
noDuplicate = \"X\";
}
seatsArray[i] = \"A\";
totalAssignedSecondClass++;
Console.WriteLine(\"Assigned seat {0:N0}\", i);
}
}



