Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

using c# visual studio (Duplicate Elimination) Use a one-dimensional array to solve the following problem: Write an app that inputs five numbers, each between 10

using c# visual studio

(Duplicate Elimination) Use a one-dimensional array to solve the following problem: Write an app that inputs five numbers, each between 10 and 100, inclusive. As each number is read, display it only if its not a duplicate of a number already read. Provide for the worst case, in which all five numbers are different. Use the smallest possible array to solve this problem. Display the complete set of unique values input after the user inputs each new value.

I have this code for the above question but the problem I have with this code is after the program tells you to the seat is full and press Y for yes and N no if you put and number or a or a letter other than what it asks you for the code will take that number and assign a seat to which ever seat is available. I want the code not to do that or tell the user the entry is invalid. thanks, for the help.

p.s can you pls tell me also what to add on change history(line 6 ) it is a requirement for my assignment but I don't know what is supposed to go in there.

//********************************************************************************* //TINFO 200B, winter 2019 //UWTacoma SET, Chuck Costarella // Cs3 assignment // Chage History // date Developer Description // 2019-01-28 Amha Aygoda This program is an automated reservation system for an airline. the program will assign seat for passengers. this app is designed for 10 seat airpalne. // Users press one for first class and 2 for economy class. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;

namespace DuplicateElimination { class DupEliminator { static bool[] totalNumberOfSeats; // initalizing total seats static int assignedFirstClassSeats; static int assignedEconomyClassSeats;

static void Main(string[] args) { // console output Console.WriteLine(@" This is a program is an automated airline reservation system. passengers select their seat by pressing 1 for business class and 2 for economy class. if the first class is full you will be asked if you want to book in economy class if there are an available seat and vice versa. if no seats are available the application will let you know when the next flight is. make sure you enter capital letter 'Y' for yes and a capital letter 'N' for No.

"); totalNumberOfSeats = new bool[11]; // array int selectedClass = 0; // initalizing assigned seats

for (int i = 0; i <= 10; i++) // assigning initial seats to false totalNumberOfSeats[i] = false;

// assigning seats for (int i = 1; i <= 10; i++) { // console output Console.WriteLine("Enter 1 for First class or 2 for Economy class."); selectedClass = Convert.ToInt32(Console.ReadLine());

// discarding any inputs other than 1 and 2 form the user while (selectedClass < 1 || selectedClass > 2) { // console output Console.WriteLine("Please enter 1 for first class or 2 for Economy class."); selectedClass = Convert.ToInt32(Console.ReadLine()); } // when user assign first class seat if (selectedClass == 1) { // when first class is full and their are available seats in economy class if (assignedFirstClassSeats == 5 && assignedEconomyClassSeats < 5) { Console.WriteLine("First class seat is full. would you like a seat in Economy class? press uppercase 'Y' for yes and uppercase 'N' for no "); if (Console.ReadLine().Equals("N")) // if the passanger declines Economy class seats {

Console.WriteLine("Next plane leaves in 3 hours"); // console output i--; // decrement of one

} else { assignEconomyClass(); } } else if (assignedFirstClassSeats < 5) { assignFirstClass(); } } else { // when Economy class is full and their are available seats in first class if (assignedEconomyClassSeats == 5 && assignedFirstClassSeats < 5) { // console output Console.WriteLine("Economy class seat is full. would you like a seat in first class? press uppercase 'Y' for yes and uppercase 'N' for no "); if (Console.ReadLine().Equals("N")) { // console output Console.WriteLine("Next plane leaves in 3 hours"); i--; // decrement by one } else { assignFirstClass(); } } else { assignEconomyClass(); } } } // console output Console.WriteLine(); Console.WriteLine("Sorry, The plane is full. Next one leaves in 3 hours."); Console.ReadLine(); }

// new method for assigning first class seats static void assignFirstClass() { bool noDuplicate = false; Random rand = new Random(); int index = 0;

// generates seat number until their are no available seat while (!noDuplicate) { noDuplicate = true; index = rand.Next(1, 6); // holds the random generated seats if (totalNumberOfSeats[index] == true) noDuplicate = false; } totalNumberOfSeats[index] = true; // taken seats assignedFirstClassSeats++; // increase assigned class by one Console.WriteLine("assigned seat {0:N0}", index); // console output

} // new method for assigning second class seats static void assignEconomyClass() { bool noDuplicate = false; Random rand = new Random(); int index = 0;

// generates seat number until their are no available seat while (!noDuplicate) { noDuplicate = true; index = rand.Next(6, 11); if (totalNumberOfSeats[index] == true) noDuplicate = false; } totalNumberOfSeats[index] = true;// taken seats

assignedEconomyClassSeats++; // increase assigned class by one Console.WriteLine("assined seat {0:N0}", index); } } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design And Implementation

Authors: Edward Sciore

2nd Edition

3030338355, 978-3030338350

More Books

Students also viewed these Databases questions

Question

What is the relationship between humans?

Answered: 1 week ago

Question

What is the orientation toward time?

Answered: 1 week ago