In: Computer Science
Please use c# and write a console application
Part 1) A small airline has just purchased a computer for its
newly automated reservations system. You have been asked to develop
a new system. You are to write an application to assign seats on
each flight of the airline’s only plane. The plane has ten rows and
each row has 2 seats (total capacity: 20 seats). The first five
rows are for first class passengers, while the remaining rows are
for economy passengers. The application is used by an airline
employee who is given the task of assigning all seats to passengers
(one passenger at a time). Your application should display the
following alternatives: Please type 1 for First Class and Please
type 2 for Economy or type 3 to see the status of all seats. If the
user types 1, your application should assign a seat in the
first-class section (rows 1–5). If the user types 2, your
application should assign a seat in the economy section (rows
6–10).
If the user types 3, the application will display the status of all
seats (“A” for available and “X” for booked) as shown below. The
application will continue to ask for the user’s input until the
flight is full or the user suggests that they do not want to assign
anymore seats.
Availability Status:
X X
X X
X A
A A
A A
X X
X X
X X
X X
A A
Your application should never assign a seat that has already been assigned. When the economy section is full, your application should ask the person if it is 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." You will need to use a multi-dimensional array to solve this problem.
Part 2) Use a one-dimensional array to solve the following
problem: A company pays its salespeople on a commission basis. The
salespeople receive $200 per week plus 9% of their gross sales for
that week. For example, a salesperson who grosses $5000 in sales in
a week receives $200 plus 9% of $5000, or a total of $650. Write an
application (using an array of counters) that determines how many
of the salespeople earned salaries in each of the following ranges
(assume that each salesperson’s salary is truncated to an integer
amount):
a) $200–299
b) $300–399
c) $400–499
d) $500–599
e) $600–699
f) $700–799
g) $800–899
h) $900–999
i) $1000 and over
The application will accept sales amount until the user enters -1
to end (as shown in figure 2.1 below). At this point, the
application calculates the salary and updates the appropriate
counter of the array. For instance, if the salesperson gets a total
salary of $565, you will update the counter that is counting totals
between the $500-$599 range.
Figure 2.1. Receiving input from user
Note that you do NOT need to store the individual salary of the salesperson. Summarize the results in tabular format Use only a for loop to display the output.
Final output showing all ranges and the number of agents that
received commission in that range
Part 1)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Automated_reservations_system
{
class Program
{
static void Main(string[] args)
{
char[,] Seats = new Char[10, 2];
for(int i=0;i<10;i++)
{
Seats[i, 0] = 'X';
Seats[i, 1] = 'X';
}
int choice;
while (true)
{
menu();
choice = Convert.ToInt16(Console.ReadLine());
switch (choice)
{
case 1:
bookFirstClassTicket(Seats);
break;
case 2:
bookEconomyClassTicket(Seats);
break;
case 3:
printSeates(Seats);
break;
default:
Console.WriteLine("Invalid Option! Please try again....");
break;
}
}
}
private static void printSeates(char[,] Seats)
{
Console.WriteLine("\nAvailability Status:");
for (int i = 0; i < 10; i++)
Console.WriteLine(Seats[i, 0] + "\t" + Seats[i, 1]);
}
public static void menu()
{
Console.WriteLine("\nPlease type 1 for First Class\nPlease type 2
for Economy\nPlease Type 3 to see the status of all seats.");
Console.Write("Emter your choice: ");
}
public static void bookFirstClassTicket(char [,]seats)
{
if (checkSeatAvaibility(seats, 'F'))
{
for (int i = 4; i >= 0; i--)
{
if (seats[i, 0] == 'X')
{
seats[i, 0] = 'A';
break;
}
else if (seats[i, 1] == 'X')
{
seats[i, 1] = 'A';
break;
}
}
Console.WriteLine("You ticket has been booked. Enjoy your
journey.");
}
else
{
if (!checkSeatAvaibility(seats, 'E'))
{
Console.WriteLine("\nSorry! No tickets are available. Next flight
leaves in 3 hours");
}
else
{
string c;
Console.Write("\nNo ticekts is available in First class do you want
to book Economy class ticket?(y/n):");
c = Console.ReadLine();
if (c == "y" || c == "Y")
bookEconomyClassTicket(seats);
else
Console.WriteLine("\nNext flight leaves in 3 hours.");
}
}
}
public static void bookEconomyClassTicket(char[,] seats)
{
if (checkSeatAvaibility(seats, 'E'))
{
for (int i = 9; i >= 5; i--)
{
if (seats[i, 0] == 'X')
{
seats[i, 0] = 'A';
break;
}
else if (seats[i, 1] == 'X')
{
seats[i, 1] = 'A';
break;
}
}
Console.WriteLine("\nYou ticket has been booked. Enjoy your
journey.");
}
else
{
if (!checkSeatAvaibility(seats, 'F'))
{
Console.WriteLine("\nSorry! No tickets are available. Next flight
leaves in 3 hours");
}
else
{
string c;
Console.Write("\nNo ticekts in Economy class do you want to book
first class ticket?(y/n):");
c = Console.ReadLine();
if (c == "y" || c == "Y")
bookFirstClassTicket(seats);
else
Console.WriteLine("\nNext flight leaves in 3 hours.");
}
}
}
public static bool checkSeatAvaibility(char[,] seats, char
type)
{
bool isAvailable = false;
if (type == 'F')
{
for (int i = 4; i >= 0; i--)
{
if (seats[i, 0] == 'X' || seats[i, 1] == 'X')
{
isAvailable = true;
break;
}
}
}
else
{
for (int i = 9; i >= 5; i--)
{
if (seats[i, 0] == 'X' || seats[i, 1] == 'X')
{
isAvailable = true;
break;
}
}
}
return isAvailable;
}
}
}
outputs





Part 2)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EmployeeSalary
{
class Program
{
static void Main(string[] args)
{
int[] salariesArray = new int[9];
Array.Clear(salariesArray, 0, salariesArray.Length);
int salesAmount;
int salary;
while (true)
{
Console.Write("Enter your salars amont or -1 to stop: ");
salesAmount = Convert.ToInt32(Console.ReadLine());
if (salesAmount == -1)
break;
salary = (int)(200 +0.09 * salesAmount);
if (salary <= 299)
salariesArray[0]++;
else if (salary >= 300 && salary <= 399)
salariesArray[1]++;
else if (salary >= 400 && salary <= 499)
salariesArray[2]++;
else if (salary >= 500 && salary <= 599)
salariesArray[3]++;
else if (salary >= 600 && salary <= 699)
salariesArray[4]++;
else if (salary >= 700 && salary <= 799)
salariesArray[5]++;
else if (salary >= 800 && salary <= 899)
salariesArray[6]++;
else if (salary > 900 && salary <= 999)
salariesArray[7]++;
else
salariesArray[8]++;
}
int s=200;
Console.WriteLine("\n\nSalary Range\tCount");
for (int i = 0; i < 9; i++)
{
Console.WriteLine("$" + s + " - " + (s +
99)+"\t"+salariesArray[i]);
s += 100;
}
}
}
}
output
If you have any query regarding the code please ask me in the
comment i am here for help you. Please do not direct thumbs down
just ask if you have any query. And if you like my work then please
appreciates with up vote. Thank You.