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 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
|
using namespace std;
Passenger::Passenger() {
}
Passenger::Passenger(string &newLname, char &newType, int &newSeat, int &newKey){
setLname(newLname);
setType(newType);
setSeat(newSeat);
setKey(newKey);
}
Passenger::Passenger(string &newLname, char &newType, int &newSeat) {
setLname(newLname);
setType(newType);
setSeat(newSeat);
}
Passenger::Passenger(const Passenger &obj) {
lName = obj.lName;
type = obj.type;
seat = obj.seat;
key = obj.key;
//cout << "copied passenger object" << endl;
}
string Passenger::getLname(){
return lName;
}
char Passenger::getType() {
return type;
};
int Passenger::getSeat(){
return seat;
}
void Passenger::setLname(string name) {
lName = name;
}
void Passenger::setType(char aType) {
if ((aType == 'E') || (aType == 'G') || (aType == 'H')){
type = aType;
}
else{
cout << "Invalid Passenger type" << endl;
}
}
void Passenger::setSeat(int aSeat) {
if((aSeat > 0) && (aSeat < 27)){
seat = aSeat;
}
else{
cout << "Seat number out of range" << endl;
}
}
void Passenger::setKey(int aKey) {
key = aKey;
}
int Passenger::getKey() {
return key;
}
void Passenger::display() {
cout << key << endl;
cout << lName << endl;
cout << type << endl;
cout << seat << endl;
}
bool Passenger::operator<(const Passenger &queue) {
//cout << key <<endl;
bool queueReturn = (key < queue.key);
//cout << queueReturn << endl;
return queueReturn;
}
bool Passenger::operator>(const Passenger &queue) {
//cout << key <<endl;
bool queueReturn = (key > queue.key);
//cout << queueReturn << endl;
return queueReturn;
}
Passenger Passenger::operator=(const Passenger &queue) {
//cout << key <<endl;
Passenger returnPassenger = queue;
returnPassenger.display();
return returnPassenger;
}
using namespace std;
const int NOT_BLOCKED = 1, BLOCKED = 25;
Airworthy::Airworthy() {
boardingTime = 0;
rdmBoardingTime = 0;
}
void Airworthy::readInData(ifstream& inFile) {
while (!inFile.eof()) {
string tempLName;
string tempSeat;
string strType;
char tempType;
int tempIntRow;
int tempKey = 0;
int tempKey2 = 0;
//Reads in the last name of the passenger
getline(inFile, tempLName, ' ');
//Reads in the passenger type and converts it to a char
getline(inFile, strType, ' ');
tempType = strType[0];
//Reads in the row and converts it to an int
getline(inFile, tempSeat);
tempIntRow = atoi(tempSeat.c_str());
//constructs the passenger objects
Passenger priPassenger(tempLName, tempType, tempIntRow);
Passenger rdmPassenger(tempLName, tempType, tempIntRow);
//determines the key and preboarding conditions
if (preboardConditions(priPassenger) > 0) {
tempKey = preboardConditions(priPassenger);
} else if (previousBoarding(priPassenger) > 0) {
tempKey = previousBoarding(priPassenger);
}
priPassenger.setKey(tempKey);
//adds passenger to the heap Queue
heapQueue.add(priPassenger);
//determines key and preboarding conditions
if (preboardConditions(rdmPassenger) > 0) {
tempKey2 = previousBoarding(rdmPassenger);
} else if (randomBoarding(rdmPassenger) > 0) {
tempKey2 = randomBoarding(rdmPassenger);
}
rdmPassenger.setKey(tempKey2);
//adds passenger to the random heap queue
rdmHeapQueue.add(rdmPassenger);
heapQueue.peek().display(); //these are the lines where I get null
rdmHeapQueue.peek().display();
}
int Airworthy::preboardConditions(Passenger myPassenger)
{
int key= 0;
//Comparisons for special boarding conditions
if (myPassenger.getType() == 'H')
{
key = 7;
}
else if (myPassenger.getSeat() >= 1 && myPassenger.getSeat() <=4)
{
key = 6;
}
else if (myPassenger.getType() == 'E' || myPassenger.getSeat() >= 10 && myPassenger.getSeat() <=11)
{
key = 5;
}
return key;
}
int Airworthy::previousBoarding(Passenger myPassenger)
{
int key = 0;
//Comparisons for previous general boarding conditions
if (myPassenger.getType() == 'G' && myPassenger.getSeat() >= 23 && myPassenger.getSeat() <= 26)
{
key = 4;
}
else if (myPassenger.getType() == 'G' && myPassenger.getSeat() >= 17 && myPassenger.getSeat() <= 22)
{
key = 3;
}
else if (myPassenger.getType() == 'G' && myPassenger.getSeat() >= 12 && myPassenger.getSeat() <= 16)
{
key = 2;
}
else if (myPassenger.getType() == 'G' && myPassenger.getSeat() >= 5 && myPassenger.getSeat() <=9)
{
key = 1;
}
return key;
}
int Airworthy::randomBoarding(Passenger myPassenger)
{
int key = 0;
//Comparison for the random general boarding conditions
if (myPassenger.getType() == 'G' && myPassenger.getSeat() > 4 && myPassenger.getSeat() < 27) {
key = 4;
}
return key;
}
void Airworthy::runSimulation()
{
int passengerOne = 0;
int rdmPassengerOne = 0;
passengerOne = heapQueue.peek().getSeat();
boardingTime += NOT_BLOCKED;
heapQueue.peek().display();
heapQueue.remove();
while(!heapQueue.isEmpty())
{
if(passengerOne >= heapQueue.peek().getSeat())
{
cout << "Passenger is blocked" << endl;
cout << passengerOne << endl;
boardingTime += BLOCKED;
heapQueue.peek().display();
heapQueue.remove();
}
else {
boardingTime += NOT_BLOCKED;
cout << "Passenger is not blocked" << endl;
heapQueue.peek().display();
heapQueue.remove();
}
passengerOne = heapQueue.peek().getSeat();
}//end while
//Calculations for the final boarding times in minutes
cout << "RANDOM CONDITIONS BOARDING" << endl;
rdmPassengerOne = rdmHeapQueue.peek().getSeat();
rdmBoardingTime += NOT_BLOCKED;
rdmHeapQueue.peek().display();
rdmHeapQueue.remove();
while(!rdmHeapQueue.isEmpty())
{
if(rdmPassengerOne >= rdmHeapQueue.peek().getSeat()) {
rdmBoardingTime += BLOCKED;
rdmHeapQueue.peek().display();
rdmHeapQueue.remove();
}
else {
rdmBoardingTime += NOT_BLOCKED;
rdmHeapQueue.peek().display();
rdmHeapQueue.remove();
}
rdmPassengerOne = rdmHeapQueue.peek().getSeat();
}//end while
double finalBoardingTime = boardingTime/60;
cout << fixed;
cout << setprecision(2) << "Boarding Time = " << finalBoardingTime << " minutes" <<endl;
double finalRdmBoardingTime = rdmBoardingTime/60;
cout << fixed;
cout << setprecision(2) << "Random Boarding Time = " << finalRdmBoardingTime << " minutes" <<endl;
}
|