Question

C# Question. Please do a lot of documenting of what your code did and thorough explaining...

C# Question. Please do a lot of documenting of what your code did and thorough explaining in your // comments.

A small airline has just purchased a computer for its new automated reservations system. You have been asked to develop the new system. You’re to write an app to assign seats on each flight of the airline’s only plane (capacity: 10 seats). Display the following alternatives: Please enter 1 for First Class or 2 for Economy. If the user types 1, your app should assign a seat in the first-class section (seats 1–5). If the user types 2, your app should assign a seat in the economy section (seats 6–10). Use a one-dimensional array of type bool to represent the seating chart of the plane. Initialize all the elements of the array to false to indicate that all the seats are empty. As each seat is assigned, set the corresponding element of the array to true to indicate that the seat is no longer available. Your app should never assign a seat that has already been assigned. When the economy section is full, your app should ask the person if it’s acceptable to be placed in the first-class section (and vice versa). If yes, make the appropriate seat assignment. If no, display the message "Next flight leaves in 3 hours."

0 0
Add a comment Improve this question Transcribed image text
Answer #1

I have added enough comments in the code for better understanding.

There might be few cases which I might have missed, because of the lack of more information.

Here is the code for the above problem:

using System;
using System.Collections;

                  
public class Program
{
   // boolean array that keeps track whether a seat is booked or not.
   static bool[] seat = new bool[10];
   // names of all seats are stored in tickets arraylist.
   static ArrayList tickets = new ArrayList(10);
   public static void Main()
   {
       Console.WriteLine("Welcome to Automated Reservation System!");
       // variable for while loop initialized to false.
       bool quit = false;
       // initializing all seats to false and all tickets to not booked status.
for(int i=0; i<10; i++)
{
seat[i] = false;
           tickets.Add("Not Booked");
}
       //run this loop untill quit becomes equal to true ie, till user selects 4th operation.
       while(!quit)
       {
           int choice;
           Console.WriteLine(" 1) Press 1 to book seat in First class ");
           Console.WriteLine(" 2) Press 2 to book seat in Economy class ");
           Console.WriteLine(" 3) Press 3 to display all tickets ");
           Console.WriteLine(" 4) Press 4 to quit the application ");
           //Console.readline reads input in string format. so type conversion to integer is required to assign it to choice.
           choice = Convert.ToInt32(Console.ReadLine());
           switch (choice)
           {
           case 1:
               // booking seat for people who are interested in first class
               FirstClassBooking();
               break;
           case 2:
               // booking seat for people who are interested in economy class
               EconomyClassBooking();
               break;
           case 3:
   //displaying the names and seatnumbers of all tickets, if ticket is not booked then display Not Booked for that seatnumber.
               DisplayTickets();
               break;
          case 4:
           // making quit variable to true stops the loop and finally exits form the application.
               quit = true;
               break;
           default:
               Console.WriteLine(" Please enter valid input ");
               break;
           }
          
       }
   }
   // booking seat for people who are interested in first class
   public static void FirstClassBooking()
   {
       // a variable that determines if a seat is alloted or not in that particular transaction.
       string name;
       bool assigned= false;
       Console.WriteLine("Booking Seat in First Class...");
       Console.WriteLine("Please enter your name...");
       name = Console.ReadLine();
       for(int i =0; i<5; i++)
       {
           if(!seat[i])
           {
               seat[i]=true;
               tickets[i] = name;
               assigned = true;
               break;
           }
       }
       // incase seat is not alloted among 1-5 seats, we will run the following if block and ask the user if he's interested in Economy class.
       if(!assigned)
       {
           int choice;
           Console.WriteLine("Seats in First Class are full, Is it okay to book a seat in Economy class? press 1 for yes or Press 2 for no ");
           //Console.readline reads input in string format. so type conversion to integer is required to assign it to choice.
           choice = Convert.ToInt32(Console.ReadLine());
           switch (choice)
           {
           case 1:
               // initiating economy class booking if seats are full in first class
               EconomyClassBooking();
               break;
           default:
               Console.WriteLine("Next flight leaves in 3 hours.");
               break;
           }
          
       }
      
   }
  
   public static void EconomyClassBooking()
   {
       // a variable that determines if a seat is alloted or not in that particular transaction.
       bool assigned= false;
       string name;
       Console.WriteLine("Booking Seat in Economy Class...");
       Console.WriteLine("Please enter your name...");
       name = Console.ReadLine();
       for(int i =5; i<10; i++)
       {
           if(!seat[i])
           {
               seat[i]=true;
               tickets[i] = name;
               assigned = true;
               break;
           }

       }
       // incase seat is not alloted among 6-10 seats, we will run the following if block and ask the user if he's interested in First class.
       if(!assigned)
       {
           int choice;
           Console.WriteLine("Seats in Economy Class are full, Is it okay to book a seat in First class? press 1 for yes or Press 2 for no ");
           //Console.readline reads input in string format. so type conversion to integer is required to assign it to choice.
           choice = Convert.ToInt32(Console.ReadLine());
           switch (choice)
           {
           case 1:
               // initiating first class booking if seats are full in first class
               FirstClassBooking();
               break;
           default:
               Console.WriteLine("Next flight leaves in 3 hours.");
               break;
           }
          
       }
   }
  
   //displaying the names and seatnumbers of all tickets, if ticket is not booked then display Not Booked for that seatnumber.
   public static void DisplayTickets()
   {
       Console.WriteLine("Here are the tickets booked till now : ");
       for(int i=0; i<10; i++) {
           Console.WriteLine( (i+1)+ " "+tickets[i]);
       }
   }
}

Add a comment
Know the answer?
Add Answer to:
C# Question. Please do a lot of documenting of what your code did and thorough explaining...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Programming language C++. (Airline Reservations System) A small airline has just purchased a computer for its...

    Programming language C++. (Airline Reservations System) A small airline has just purchased a computer for its new au- tomated reservations system. You have been asked to develop the new system. You’re to write an app to assign seats on each flight of the airline’s only plane (capacity: 10 seats). Display the following alternatives: Please type 1 for First Class and Please type 2 for Economy. If the user types 1, your app should assign a seat in the first-class section...

  • I could really use some help with this question! Thanks!! Must use C# and it must...

    I could really use some help with this question! Thanks!! Must use C# and it must be a console application ------------------------------------------------------------------------------------------------------------------------------ You start working on this w/o arrays just with seats: bool f1, f2,..., e1, e2,.... You can use Console application for now. A small airline has just purchased a computer for its new automated reservations system. You have been asked to develop the new system. You’re to write an app to assign seats on each flight of the airline’s...

  • (Airline Reservations System) A small airline has just purchased a computer for its new automated reservations system

    (Airline Reservations System) A small airline has just purchased a computer for its new automated reservations system. The president has asked you to program the new system. You'll write a program to assign seats on each flight of the airline's only plane (capacity: 10 scats).Your program should display the following menu of alternatives:Please type 1 for "first class"please type 2 for "economy"If the person types 1 , then your program should assign a seat in the first class section (seats...

  • For this week's assignment , create and complete a Windows application for the following question. Airline...

    For this week's assignment , create and complete a Windows application for the following question. Airline Reservation System: An airline has just bought a computer for its new reservation system. Develop a new system to assign seats on the new airplane( capacity: 10 seats) Display the following alternatives: "Please type 1 for first class, and please type 2 for Economy". If the user enters 1, your application should assign a seat in the first class( seats 1-5). If the user...

  • C# WINDOWS FORMS APPLICATION (not CONSOLE APPLICATION ) (Please screenshot window form of this program and...

    C# WINDOWS FORMS APPLICATION (not CONSOLE APPLICATION ) (Please screenshot window form of this program and write code on computer. Thank you very much !) For this week's assignment , create and complete a Windows application for the following question. Airline Reservation System: An airline has just bought a computer for its new reservation system. Develop a new system to assign seats on the new airplane( capacity: 10 seats) Display the following alternatives: "Please type 1 for first class, and...

  • I have to write a C program to assign seats on each flight of the airline’s...

    I have to write a C program to assign seats on each flight of the airline’s only plane (capacity: 40 seats, in 10 rows). For the sake of simplicity, assume that each row has 4 seats labeled A, B, C, D. Your program should display the following menu of alternatives: Please type 1 for "first class" Please type 2 for "business class" Please type 3 for “economy class”. If the person types 1, then your program should assign a seat...

  • Write a program in C to assign seats of a movie theater (capacity: 200 seats). Your...

    Write a program in C to assign seats of a movie theater (capacity: 200 seats). Your program should display the following menu of alternatives: Please type 1 for "section A, $50/ticket" type 2 for "section B, $70/ticket", and type 3 for "section C, $80/ticket".  If the user types 1, then your program should assign a seat in the A section (seats 1–50). If the user types 2, then your program should assign a seat in the B section (seats 51–100). If...

  • The Course Project can be started in Week 7 and is due by 11:59 pm CT...

    The Course Project can be started in Week 7 and is due by 11:59 pm CT Saturday of Week 8. It must follow standard code formatting and have a comment block at the top of the code file with a detailed description of what the program does. Functions must have a comment block with a detailed description of what it does. Pseudocode must be provided in the comment block at the top of the file. This program will allow the...

  • A small airline has just purchased a computer for its new automated reservations system

    OBJECTIVE:The objective of the assignment is to use object-oriented design techniques to design an application.DESCRIPTION:A small airline has just purchased a computer for its new automated reservations system. You have been hired to design an airline seating application for the FBN (Fly-By-Night) Airlines. In this portion of the assignment, the task is to do the object oriented design for the application. This system will be used only by the company and its employees. Customers will not interact with the system.Your...

  • Java // Topic 2c // Program reserves airline seats. import java.util.Scanner public class Plane {    //...

    Java // Topic 2c // Program reserves airline seats. import java.util.Scanner public class Plane {    // checks customers in and assigns them a boarding pass    // To the human user, Seats 1 to 2 are for First Class passengers and Seats 3 to 5 are for Economy Class passengers    //    public void reserveSeats()    {       int counter = 0;       int section = 0;       int choice = 0;       String eatRest = ""; //to hold junk in input buffer       String inName = "";      ...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT