Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Your employer has determined a market for a simple airline ticketing system for

ID: 657619 • Letter: Y

Question

Your employer has determined a market for a simple airline ticketing system for a very simple airline (Tree Top Airways - TTA). The airline only has two aircraft, named ALFA and BRAVO. Initially, the ticket system will determine the number of seats on each plane and in the lounge. The ticketing system is to be installed at the airport ticket booth for the airline and will operate under the following rules:

1) If a party arrives and there is enough room on the plane requested, they are allowed to board and a message to that effect is printed.

2) If a party arrives and there is not enough room on the plane requested due to people already being on the plane, the party is directed to wait in the lounge and a message to that effect is printed.

3) If a party arrives and there is not enough room on the plane requested because the plane is just too small, the party is turned away and a message to that effect is printed.

4) If a party is directed to the lounge and there is not enough room in the lounge, the party is turned away.

5) Parties are never split.

6) A plane will fly whenever it becomes full and a list of all parties on board will be printed.

7) A plane may fly upon a command from the ticket clerk. Again a list of all parties on board will be printed

. 8) The ticket clerk will enter when a plane flys and upon the return of the plane the system will move people from the lounge to the plane in the order in which the parties arrived, but will skip parties that cannot fit and search for those which can fit. A list of those parties boarding the plane will be printed.

9) When the airline shuts down for the night, the airplanes will continue to fly and return (without the ticket clerk performing any action) until all parties in the lounge have flown with appropriate messages being printed.

10) Party names do not have a maximum size.

The commands the system will accept are the following: ALFA <size> BRAVO <size> LOUNGE <size> FLY <airplane> ARRIVE <airplane> <party> <size> SHUTDOWN where: is either ALFA or BRAVO. is a name of unlimited length. is an integer number Fields in the input will be separated by some amount of whitespace. The ticket clerk is a terrible typist

Explanation / Answer

REFERENCE: CPLUS FORUM

plane.h

#ifndef PLANE_H
#define PLANE_H

#include "Party.h"

struct Plane
   {
   long   NumSeats;
   long   NumEmptySeats;
   long   NumParties;
   Party *   pParty;
   char   PlaneAbbrev;
   };

#endif

ReadFunctions.ccp

#include <iostream>

using namespace std;

#include <conio.h>
#include <ctype.h>  
#include <math.h>  

#include "ReadFunctions.h"

static void BackSpace ()  
   {
   _putch ('');
   _putch (' ');
   }

double ReadDouble ()
   {
   char   c;
   bool   Digits       (false);
   int       Fraction   (0);
   double   Num           (0.0);
   int       Sign       (0);

   while (!isspace (c = static_cast <char> (_getch ())))
       {
       switch (c)
           {
           case '+':
           case '-':
               if ((Sign == 0) && !Digits)
                       if (c == '+')
                               Sign = 1;
                           else // c == '-'
                               Sign = -1;
                   else
                       c = '';
               break;
           case '.':
               if (Fraction == 0)
                       Fraction = 1;
                   else
                       c = '';
               break;
           case '':
               if (Fraction > 0)
                       {
                       BackSpace ();
                       Fraction /= 10;
                       if (Fraction > 0)
                               {
                               Num = static_cast <int> (Num * Fraction);
                               Num /= Fraction;
                               }
                           else;
                       }
                   else
                       if (Digits)
                               {
                               BackSpace ();
                               Num = static_cast <int> (Num) / 10;
                               if (Num == 0.0)
                                       Digits = false;
                                   else;
                               }
                           else
                               if (Sign != 0)
                                       {
                                       BackSpace ();
                                       Sign = 0;
                                       }
                                   else
                                       c = '';
               break;
           case '0':
               if (!Digits && (Fraction == 0))   // doesn't do leading zeros
                       {
                       c = '';
                       break;
                       }
                   else;
           case '1':
           case '2':
           case '3':
           case '4':
           case '5':
           case '6':
           case '7':
           case '8':
           case '9':
               Digits = true;
               if (Fraction > 0)
                       {
                       Fraction *= 10;
                       Num = Num + ((c - '0') / static_cast <double> (Fraction));
                       }
                   else
                       Num = (Num * 10.0) + (c - '0');
               break;
           default:
               c = '';
           }
       _putch (c);
       }
   if (c == ' ')
           c = ' ';
       else;
   _putch (c);
   if (Sign < 0)
           Num = -Num;
       else;
   return Num;
   }


int ReadInteger ()
   {
   char   c;
   bool   Digits   (false);
   int       Num       (0);
   int       Sign   (0);


   while (!isspace (c = static_cast <char> (cin.get ())))
       {
       switch (c)
           {
           case '+':
           case '-':
               if ((Sign == 0) && !Digits)
                       if (c == '+')
                               Sign = 1;
                           else // c == '-'
                               Sign = -1;
                   else
                       c = '';
               break;
           case '':
               if (Digits)
                       {
                       BackSpace ();
                       Num /= 10;
                       if (Num == 0)
                               Digits = false;
                           else;
                       }
                   else
                       if (Sign != 0)
                               {
                               BackSpace ();
                               Sign = 0;
                               }
                           else
                               c = '';
               break;
           case '0':
               if (!Digits)
                       {
                       c = '';
                       break;
                       }
                   else;
           case '1':
           case '2':
           case '3':
           case '4':
           case '5':
           case '6':
           case '7':
           case '8':
           case '9':
               Digits = true;
               Num = (Num * 10) + (c - '0');
               break;
           default:
               c = '';
           }

       }
   if (c == ' ')
           c = ' ';
       else;

   if (Sign < 0)
           Num = -Num;
       else;
   return Num;
   }

UINT ReadHex ()
   {
   char   c;
   bool   Digits   (false);
   UINT   Num       (0);

   while (!isspace (c = static_cast <char> (_getch ())))
       {
       switch (c)
           {
           case '':
               if (Digits)
                       {
                       BackSpace ();
                       Num /= 16;
                       if (Num == 0)
                               Digits = false;
                           else;
                       }
                   else
                       c = '';
               break;
           case '0':
               if (!Digits)
                       {
                       c = '';
                       break;
                       }
                   else;
           case '1':
           case '2':
           case '3':
           case '4':
           case '5':
           case '6':
           case '7':
           case '8':
           case '9':
               Digits = true;
               Num = (Num * 16) + (c - '0');
               break;
           case 'a':
           case 'b':
           case 'c':
           case 'd':
           case 'e':
           case 'f':
               Digits = true;
               Num = (Num * 16) + (c - 'a') + 10;
               break;
           case 'A':
           case 'B':
           case 'C':
           case 'D':
           case 'E':
           case 'F':
               Digits = true;
               Num = (Num * 16) + (c - 'A') + 10;
               break;
           default:
               c = '';
           }
       _putch (c);
       }
   if (c == ' ')
           c = ' ';
       else;
   _putch (c);
   return Num;
   }

ReadString.cpp

#include <iostream>

using namespace std;

#include <ctype.h>
#include <memory.h>

#include "ReadString.h"

char * ReadString ()
   {
   const   long   StartingSize (50);
           long   CurrentNumChars;
           long   CurrentSize;
           char *   pStr;
           char   c;

   CurrentSize       = StartingSize;
   pStr           = new char [CurrentSize + 1];
   CurrentNumChars   = 0;

   while (!isspace (c = cin.get ()))
       {
       pStr [CurrentNumChars++] = c;
       if (CurrentNumChars >= CurrentSize)
               {
               char * pChar;
               CurrentSize += StartingSize;
               pChar       = new char [CurrentSize + 1];
               memcpy (pChar, pStr, CurrentNumChars);
               delete [] pStr;
               pStr = pChar;
               }
           else;
       }
   pStr [CurrentNumChars] = '';
   return pStr;
   }

ReadString.h

#ifndef READ_STRING_H
#define READ_STRING_H

char * ReadString ();

#endif

ReadFunctions.h

#ifndef READ_FUNCTIONS_H
#define READ_FUNCTIONS_H

typedef unsigned int   UINT;

double   ReadDouble   ();
UINT   ReadHex       ();
int       ReadInteger   ();

Party.h

#ifndef PARTY_H
#define PARTY_H

struct Party
   {
   char *   pName;
   long   Size;
   char    Plane;
   };

#endif

main.cpp

#include <iostream>

using namespace std;

#include <stdlib.h>

#include <iostream>

using namespace std;

#include "Party.h"
#include "Plane.h"
#include "ReadFunctions.h"
#include "ReadString.h"

enum CommandList {ALFA, BRAVO, LOUNGE, ARRIVE, FLY, SHUTDOWN, INVALID};

void       Move       (Plane &, Plane &);
CommandList   ReadCommand   ();

void main ()
   {
   int       i;
   long   j;
   Plane       Alfa;
   Plane       Bravo;
   Plane       Lounge;
   Party       Parties;

   bool       Done;
   bool       AlfaInitialized;
   bool       BravoInitialized;
   bool       LoungeInitialized;
   CommandList   Command;

   AlfaInitialized       = false;
   BravoInitialized   = false;
   LoungeInitialized   = false;

   do   {
       if (!AlfaInitialized)
                           {
                           Alfa.PlaneAbbrev   = 'A';
                           cout << "Enter number of ALFA seats: ";
                           Alfa.NumSeats       = ReadInteger ();
                           Alfa.NumEmptySeats   = Alfa.NumSeats;
                           Alfa.NumParties       = 0;
                           Alfa.pParty           = new Party [Alfa.NumSeats];
                           AlfaInitialized       = true;
                           cout << "ALFA initialized." << endl;
                           }
                       else
                           cout << "ALFA is already initialized" << endl;
       if (!BravoInitialized)
                           {
                           Bravo.PlaneAbbrev   = 'B';
                           cout << "Enter number of BRAVO seats: ";
                           Bravo.NumSeats       = ReadInteger ();
                           Bravo.NumEmptySeats   = Bravo.NumSeats;
                           Bravo.NumParties       = 0;
                           Bravo.pParty           = new Party [Bravo.NumSeats];
                           BravoInitialized       = true;
                           cout << "BRAVO initialized." << endl;
                           }
                       else
                           cout << "BRAVO is already initialized" << endl;
      
      
       if (!LoungeInitialized)
                           {
                           Lounge.PlaneAbbrev   = 'L';
                           cout << "Enter number of Lounge seats: ";
                           Lounge.NumSeats       = ReadInteger ();
                           Lounge.NumEmptySeats   = Lounge.NumSeats;
                           Lounge.NumParties       = 0;
                           Lounge.pParty           = new Party [Lounge.NumSeats];
                           LoungeInitialized       = true;
                           cout << "Lounge initialized." << endl;
                           }
                       else
                           cout << "Lounge is already initialized" << endl;                  
          
       } while (!AlfaInitialized || !BravoInitialized || !LoungeInitialized);
   Done = false;
   do   {
       cout << "Enter a command (ARRIVE, FLY, SHUTDOWN): ";
       Command = ReadCommand ();
       switch (Command)
           {
           case ARRIVE:
                   cout << "Enter number of members in party: ";
                   Parties.Size = ReadInteger ();  
                   cout << "Party size entered is " << Parties.Size << endl;
                   cout << "Enter which plane the party will be on: ";
                   Parties.Plane = ReadCommand ();
                   switch (Parties.Plane)
                       {
                       case ALFA:
                           Parties.pName = new char [Parties.Size];
                           Parties.Plane = 'A';
                           for (i = 0; i < Parties.Size; i++)
                               {
                               cout << "Enter name [" << i + 1 << "] or press Enter to continue: ";
                               Parties.pName [i] = *ReadString ();
                               }
                           break;
                       case BRAVO:
                           Parties.pName = new char [Parties.Size];
                           Parties.Plane = 'B';
                           for (i = 0; i < Parties.Size; i++)
                               {
                               cout << "Enter name [" << i + 1 << "] or press Enter to continue: ";
                               Parties.pName [i] = *ReadString ();
                               }              
                           break;
                       default:
                           cout << "Invalid Command." << endl;
                       }
          
          
           case FLY:
               // if plane is Alfa
                       // print the names of all parties on the plane
                       // take everybody off the plane
                       Move (Alfa, Lounge);
                   //else   // plane is Bravo
                       // print the names of all parties on the plane
                       // take everybody off the plane
                       Move (Bravo, Lounge);
               break;
           case SHUTDOWN:
               Done = true;
               break;
           default:
               cout << "Invalid Command" << endl;
           }
       } while (!Done);
   }
CommandList ReadCommand ()
   {
   char *       CommandString;
   CommandList   Command;

   CommandString = ReadString ();
   if (_strcmpi (CommandString, "ALFA") == 0)
           Command = ALFA;
       else
           if (_strcmpi (CommandString, "BRAVO") == 0)
                   Command = BRAVO;
               else
                   if (_strcmpi (CommandString, "LOUNGE") == 0)
                           Command = LOUNGE;
                       else
                           if (_strcmpi (CommandString, "ARRIVE") == 0)
                                   Command = ARRIVE;
                               else
                                   if (_strcmpi (CommandString, "FLY") == 0)
                                           Command = FLY;
                                       else
                                           if (_strcmpi (CommandString, "SHUTDOWN") == 0)
                                                   Command = SHUTDOWN;
                                               else
                                                   Command = INVALID;
   delete [] CommandString;
   return Command;
   }

void Move (Plane & To, Plane & From)
   {
   long   i;
   long   j;

   for (i = 0; i < From.NumParties; i++)
       if ((From.pParty [i].Plane == To.PlaneAbbrev) && (From.pParty [i].Size <= To.NumEmptySeats))
               {
               To.pParty [To.NumParties] = From.pParty [i];
               To.NumParties++;
               To.NumEmptySeats           -= From.pParty [i].Size;
               From.NumEmptySeats           += From.pParty [i].Size;
               for (j = i + 1; j < From.NumParties; j++)
                   From.pParty [j - 1] = From.pParty [j];
               From.NumParties--;
           }
   }


#endif

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote