Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <queue>
- #include <vector>
- #include <string>
- #include <stdlib.h>
- #include <iostream>
- #include <iomanip>
- /* I was confused about the order in which the people are to arrive and how they are to arrive */
- using namespace std;
- class person {
- public:
- int arivailTime = 1;
- int waitTime = 9;
- int timeLeft = 0;
- int realWaitTime = 0;
- int id;
- };
- void header() {
- cout << setw(5) << "time";
- cout << setw(5) << "line";
- }
- class Gline {
- public:
- int currentTime = 0;
- int maxTime = 120;
- queue<person> theLine;
- void run() {
- for (currentTime = 0; currentTime <= maxTime; currentTime++) {
- cout << setw(5) << "[" << setw(3) << currentTime << "]";
- cout << setw(2) << "[" << setw(3) << lengthLine() << "]";
- cout << setw(2) << "[" << setw(1) << arrive() << "]";
- cout << setw(2) << "[" << setw(1) << departure() << "]";
- cout << setw(3) << "[" << setw(3) << theLine.front().realWaitTime << "]";
- cout << setw(3) << "[" << setw(3) << theLine.front().waitTime + currentTime << "]";
- cout << endl;
- addWaitTime();
- }
- }
- void addWaitTime() {
- queue<person> tempQueue;
- queue<person> nextQueue;
- tempQueue = theLine;
- for (int i = 0; i < theLine.size(); i++) {
- // the person at the begining of line A add to their total wait time.
- tempQueue.front().realWaitTime = tempQueue.front().realWaitTime + 1;
- // add that first person in line A to the line B.
- nextQueue.push(tempQueue.front());
- // remove the first person in line A
- tempQueue.pop();
- }
- this->theLine = nextQueue;
- }
- bool departure() {
- bool returnObject = false;
- if (theLine.front().waitTime == 0) {
- returnObject = true;
- theLine.pop();
- theLine.front().waitTime = theLine.front().waitTime - 1;
- cout << "depart" << endl;
- }
- return returnObject;
- }
- bool arrive() {
- bool returnObject = false;
- if (theLine.front().arivailTime == 0) {
- person tempPerson;
- tempPerson.arivailTime = rand() % 4 + 1;
- tempPerson.waitTime = rand() % 4 + 1;
- tempPerson.realWaitTime = tempPerson.waitTime;
- theLine.push(tempPerson);
- theLine.front().arivailTime = theLine.front().arivailTime - 1;
- cout << "arrival" << endl;
- }
- return returnObject;
- }
- int lengthLine() {
- return theLine.size();
- }
- person nextPerson() {
- person returnObject;
- queue<person> tempQueue;
- tempQueue = theLine;
- tempQueue.pop();
- returnObject = tempQueue.front();
- cout << "nextPerson" << endl;
- return returnObject;
- }
- Gline() {
- for (int i = 0; i < maxTime + 20; i++) {
- person tempPerson;
- tempPerson.id = i;
- tempPerson.waitTime = rand() % 4 + 1;
- tempPerson.arivailTime = rand() % 4 + 1;
- tempPerson.realWaitTime = tempPerson.waitTime;
- theLine.push(tempPerson);
- }
- }
- void showPeople() {
- for (int i = 0; i < theLine.size(); i++) {
- cout << theLine.front().id << " " << theLine.front().waitTime << " " << endl;
- theLine.pop();
- }
- }
- };
- void main() {
- Gline main;
- main.run();
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment