CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Threaded View

  1. #1
    Join Date
    Dec 2011
    Posts
    2

    Tired. Need Help. Please. :(

    I'm dumb. Theres probably a much more efficient way of doing this, but I'm a few weeks behind in this class and I don't know of one, so I'm using what I know. This is the Airline Seating Programming that I'm sure lots of people here have encountered at some point.

    ( Airline Reservations System ) A small airline has just purchased a computer for its new automated reservations system. You have been asked to develop the new system. You are to write an application to assign seats on each flight of the airline's only plane (capacity: 10 seats).

    Your application should display the following alternatives: Please type 1 for First Class and Please type 2 for Economy . If the user types 1 , your application should assign a seat in the first-class section (seats 1-5). If the user types 2 , your application should assign a seat in the economy section (seats 6-10).

    Use a one-dimensional array of simple 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 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."

    This is what I've got.
    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
        class Airline2
        {
            string classChoice;
    
             const int ARRAY_LENGTH = 10;
             bool[] seatList = new bool[ARRAY_LENGTH];
    
            public void PromptForSeat()
            {
                Console.WriteLine("Please Choose Class: Type '1' for First Class or '2' for Economy Class: ");
            }
    
            public void AssignSeat() 
            {
                classChoice = Console.ReadLine();
                string answer;
    
                if (classChoice == "1") 
                {
                    if (seatList[0] == false)
                    {
                    seatList[0] = true;
                    AssignSeat();
                    }
                    else if (seatList[1] == false)
                    {
                        seatList[1] = true;
                        AssignSeat();
                    }
                    else if (seatList[2] == false)
                    {
                        seatList[2] = true;
                        AssignSeat();
                    }
                    else if (seatList[3] == false)
                    {
                        seatList[3] = true;
                        AssignSeat();
                    }
                    else if (seatList[4] == false)
                    {
                        seatList[4] = true;
                        AssignSeat();
                    }
                    else if (seatList[4] == true)
                    {
                        Console.WriteLine("No more seats available. Downgrade to Economy? Y/N?");
                        answer = Console.ReadLine();
    
                        if (answer == "y")
                        {
                            classChoice = "2";
                        }
                        else
                            Console.WriteLine("Sorry, the next flight is in 3 hours.");
                    } 
    
    
                } else
                    if (classChoice == "2")
                    {
                        if (seatList[5] == false)
                        {
                            seatList[5] = true;
                            AssignSeat();
                        }
                        else if (seatList[6] == false)
                        {
                            seatList[6] = true;
                            AssignSeat();
                        }
                        else if (seatList[7] == false)
                        {
                            seatList[7] = true;
                            AssignSeat();
                        }
                        else if (seatList[8] == false)
                        {
                            seatList[8] = true;
                            AssignSeat();
                        }
                        else if (seatList[9] == false)
                        {
                            seatList[9] = true;
                            AssignSeat();
                        }
                        else if (seatList[9] == true)
                        {
                            Console.WriteLine("No more seats available. Upgrade to First? Y/N?");
                            answer = Console.ReadLine();
    
                            if (answer == "y")
                            {
                                classChoice = "1";
                            }
                            else
                                Console.WriteLine("Sorry, the next flight is in 3 hours.");
                        }
                    }
            }
        }
    It breaks down after all the seats in a given class have been taken and it prompts the user to see if they'd like to upgrade/downgrade. I've been playing catch up for this class all night and I'm dog tired, so this could be blaringly obvious and I'm just not seeing it. Thanks in advance to anyone that can help.
    Last edited by elbumpy; December 3rd, 2011 at 03:21 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured