Can you please clean up my code? I think there is an implementation problem. Thank you. #include #include #include using namespace std; void enqQ(int&); void deqQ(int&); void clearQ(int&, int&); bool isEmpty(int, int); bool isFull(int, int); struct planes // data type plane declared via struct { stringrequest; stringflightNum; stringstartingPoint; stringdestination; stringnumberOfPassengers; }; void enqQ(int& rear) // adds data to queue { rear = (rear + 1) % 10; } void deqQ(int& front) // delets data from queue { front = (front + 1) % 10; } void clearQ(int& front, int& rear) // clears queue { front = -1; rear = -1; } bool isEmpty(int front, int rear) // tells if queue is empty or not { if (rear == front) return true; else return false; } bool isFull(int front, int rear) // tells if queue is full or not { if ((rear + 1) % 10 == front) return true; else return false; } int main() { planes normalQueue[15]; planes emergencyQueue[10]; planes plane; fstream fin; int normalFront; int normalRear; int emergencyFront; int emergencyRear; int time; string planeInfo; clearQ(normalFront, normalRear); clearQ(emergencyFront, emergencyRear); fin.open("Airport Queue Data.txt"); // makes sure that named text is there if (!fin) { cerr << "\ncould not open file"; exit(-1); } time = 1; // time is declared to 1 while (!fin.eof()) // reads data until end of file { cout << "Time Cycle = " << time << ":00" << endl; // prints time cycle getline(fin, planeInfo); // gets entire line and puts it in planeInfo which is temp variable plane.request = planeInfo.substr(0, 8); // these function reads specific characters from planeInfo and stores them into proper areas of the struct plane.flightNum = planeInfo.substr(8, 3); plane.startingPoint = planeInfo.substr(11, 8); plane.destination = planeInfo.substr(19, 8); plane.numberOfPassengers = planeInfo.substr(27, 3); if (plane.request == "NORMAL ") // if plane request is normal then it will be place into normal queue { cout << "Plane added to Normal Queue" << endl; enqQ(normalRear); // normalRear increases normalQueue[normalRear] = plane; // adds plane to normalqueue and prints out plane info cout << plane.flightNum << "\t"; cout << plane.startingPoint << "\t"; cout << plane.destination << "\t"; cout << plane.numberOfPassengers << "\n"; cout << "---------------############---------------------\n" << endl; } else { cout << "Plane added to Emergency Queue" << endl; enqQ(emergencyRear); // emergency rear increases emergencyQueue[emergencyRear] = plane; // adds plane to emergency Queue and prints out plane info cout << plane.flightNum << "\t"; cout << plane.startingPoint << "\t"; cout << plane.destination << "\t"; cout << plane.numberOfPassengers << "\n"; cout << "---------------############---------------------\n" << endl; } if (time % 2 == 0) // plane will land only if time is even { if (!isEmpty(emergencyFront, emergencyRear)) // checks if emergency queue is empty if not than it will be prioritize to land { cout << "Emergency Plane Landed" << endl; deqQ(emergencyFront); // increments emergency front and print plane info cout << emergencyQueue[emergencyFront].flightNum << "\t"; cout << emergencyQueue[emergencyFront].startingPoint << "\t"; cout << emergencyQueue[emergencyFront].destination << "\t"; cout << emergencyQueue[emergencyFront].numberOfPassengers << endl; cout << "---------------############---------------------\n" << endl; } else { cout << "Normal Plane Landed" << endl; deqQ(normalFront); // increments normal front and prints plane info cout << normalQueue[normalFront].flightNum << "\t"; cout << normalQueue[normalFront].startingPoint << "\t"; cout << normalQueue[normalFront].destination << "\t"; cout << normalQueue[normalFront].numberOfPassengers << endl; cout << "---------------############---------------------\n" << endl; } } time++; // increments time if (time > 24) // check time cycle resets to 1 when it reaches 24 { time = 1; } } fin.close(); // closes fin file cout << "\n\n\n Flights still in Queues" << endl; // prints planes still left in queues cout << "\nNormal Queue: " << endl; while (!isEmpty(normalFront, normalRear)) // prints planes that are left in normal queue { deqQ(normalFront); cout << normalQueue[normalFront].request << "\t"; cout << normalQueue[normalFront].flightNum << "\t"; cout << normalQueue[normalFront].startingPoint << "\t"; cout << normalQueue[normalFront].destination << "\t"; cout << normalQueue[normalFront].numberOfPassengers << endl; } cout << "\nEmergency Queue: " << endl; while (!isEmpty(emergencyFront, emergencyRear)) // prints planes that are left in emergency queue { deqQ(emergencyFront); cout << emergencyQueue[emergencyFront].request << "\t"; cout << emergencyQueue[emergencyFront].flightNum << "\t"; cout << emergencyQueue[emergencyFront].startingPoint << "\t"; cout << emergencyQueue[emergencyFront].destination << "\t"; cout << emergencyQueue[emergencyFront].numberOfPassengers << endl; } return 0; }
Can you please clean up my code? I think there is an implementation problem. Thank you.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void enqQ(int&);
void deqQ(int&);
void clearQ(int&, int&);
bool isEmpty(int, int);
bool isFull(int, int);
struct planes // data type plane declared via struct
{
stringrequest;
stringflightNum;
stringstartingPoint;
stringdestination;
stringnumberOfPassengers;
};
void enqQ(int& rear) // adds data to queue
{
rear = (rear + 1) % 10;
}
void deqQ(int& front) // delets data from queue
{
front = (front + 1) % 10;
}
void clearQ(int& front, int& rear) // clears queue
{
front = -1;
rear = -1;
}
bool isEmpty(int front, int rear) // tells if queue is empty or not
{
if (rear == front)
return true;
else
return false;
}
bool isFull(int front, int rear) // tells if queue is full or not
{
if ((rear + 1) % 10 == front)
return true;
else
return false;
}
int main()
{
planes normalQueue[15];
planes emergencyQueue[10];
planes plane;
fstream fin;
int normalFront;
int normalRear;
int emergencyFront;
int emergencyRear;
int time;
string planeInfo;
clearQ(normalFront, normalRear);
clearQ(emergencyFront, emergencyRear);
fin.open("Airport Queue Data.txt"); // makes sure that named text is there
if (!fin)
{
cerr << "\ncould not open file";
exit(-1);
}
time = 1; // time is declared to 1
while (!fin.eof()) // reads data until end of file
{
cout << "Time Cycle = " << time << ":00" << endl; // prints time cycle
getline(fin, planeInfo); // gets entire line and puts it in planeInfo which is temp variable
plane.request = planeInfo.substr(0, 8); // these function reads specific characters from planeInfo and stores them into proper areas of the struct
plane.flightNum = planeInfo.substr(8, 3);
plane.startingPoint = planeInfo.substr(11, 8);
plane.destination = planeInfo.substr(19, 8);
plane.numberOfPassengers = planeInfo.substr(27, 3);
if (plane.request == "NORMAL ") // if plane request is normal then it will be place into normal queue
{
cout << "Plane added to Normal Queue" << endl;
enqQ(normalRear); // normalRear increases
normalQueue[normalRear] = plane; // adds plane to normalqueue and prints out plane info
cout << plane.flightNum << "\t";
cout << plane.startingPoint << "\t";
cout << plane.destination << "\t";
cout << plane.numberOfPassengers << "\n";
cout << "---------------############---------------------\n" << endl;
}
else
{
cout << "Plane added to Emergency Queue" << endl;
enqQ(emergencyRear); // emergency rear increases
emergencyQueue[emergencyRear] = plane; // adds plane to emergency Queue and prints out plane info
cout << plane.flightNum << "\t";
cout << plane.startingPoint << "\t";
cout << plane.destination << "\t";
cout << plane.numberOfPassengers << "\n";
cout << "---------------############---------------------\n" << endl;
}
if (time % 2 == 0) // plane will land only if time is even
{
if (!isEmpty(emergencyFront, emergencyRear)) // checks if emergency queue is empty if not than it will be prioritize to land
{
cout << "Emergency Plane Landed" << endl;
deqQ(emergencyFront); // increments emergency front and print plane info
cout << emergencyQueue[emergencyFront].flightNum << "\t";
cout << emergencyQueue[emergencyFront].startingPoint << "\t";
cout << emergencyQueue[emergencyFront].destination << "\t";
cout << emergencyQueue[emergencyFront].numberOfPassengers << endl;
cout << "---------------############---------------------\n" << endl;
}
else
{
cout << "Normal Plane Landed" << endl;
deqQ(normalFront); // increments normal front and prints plane info
cout << normalQueue[normalFront].flightNum << "\t";
cout << normalQueue[normalFront].startingPoint << "\t";
cout << normalQueue[normalFront].destination << "\t";
cout << normalQueue[normalFront].numberOfPassengers << endl;
cout << "---------------############---------------------\n" << endl;
}
}
time++; // increments time
if (time > 24) // check time cycle resets to 1 when it reaches 24
{
time = 1;
}
}
fin.close(); // closes fin file
cout << "\n\n\n Flights still in Queues" << endl; // prints planes still left in queues
cout << "\nNormal Queue: " << endl;
while (!isEmpty(normalFront, normalRear)) // prints planes that are left in normal queue
{
deqQ(normalFront);
cout << normalQueue[normalFront].request << "\t";
cout << normalQueue[normalFront].flightNum << "\t";
cout << normalQueue[normalFront].startingPoint << "\t";
cout << normalQueue[normalFront].destination << "\t";
cout << normalQueue[normalFront].numberOfPassengers << endl;
}
cout << "\nEmergency Queue: " << endl;
while (!isEmpty(emergencyFront, emergencyRear)) // prints planes that are left in emergency queue
{
deqQ(emergencyFront);
cout << emergencyQueue[emergencyFront].request << "\t";
cout << emergencyQueue[emergencyFront].flightNum << "\t";
cout << emergencyQueue[emergencyFront].startingPoint << "\t";
cout << emergencyQueue[emergencyFront].destination << "\t";
cout << emergencyQueue[emergencyFront].numberOfPassengers << endl;
}
return 0;
}
![117BOSTON
621NEW YORKCOLUMBUS 82
NORMAL
COLUMBUS 46
NORMAL
NORMAL
384L.A.
COLUMBUS127
NORMAL
17CHICAGO TAMPA
PRIORITY256CHICAGO COLUMBUS 34
984ATLANTA BUFFALO
19
NORMAL
10
NORMAL
112NEW YORKL.A.
321
NORMAL
96MILWAUKECOLUMBUS 41
SANDIEG0182
PRIORITY 99BOSTON
PRIORITY217ROCHESTRCINCINAT 81
NORMAL
NORMAL
180BOSTON
CHICAGO 164
542MONTREALCOLUMBUS101
NORMAL 641SANFRANSCOLUMBUS 75
PRIORITY321BALTIMORKANSASCT109
NORMAL
94SEATTLE COLUMBUS 86
NORMAL
600ST.LOUISDETROIT 100
PRIORITY510ØPORTLANDCOLUMBUS 8
151
COLUMBUS 97
RICHMOND 40
30
PRIORITY121NEWORLEABOSTON
PRIORITY386DENVER
PRIORITY682DENVER
PRIORITY998TORONTO PHOENIX
NORMAL
82DAYTON
COLUMBUS190](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F936674a8-46b2-4872-b00b-38bd88e95e72%2F8ab94a48-8d02-47ee-aaa9-d340aecaa528%2Fva4g8p5_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 3 steps with 6 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)