1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
|
#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--;
}
}
|