wheelsmanx

CPS 272 QUEUE2

Dec 1st, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. #include <vector>
  2. #include <string>
  3. #include <iostream>
  4. #include <stdlib.h>
  5. #include <queue>
  6.  
  7. using namespace std;
  8.  
  9. class personInLine {
  10. public:
  11. int waitTime;
  12. int timeToGo;
  13. int id;
  14. personInLine(int a, int c) {
  15. this->waitTime = a;
  16. this->timeToGo = a;
  17. this->id = c;
  18. }
  19. };
  20.  
  21. class env {
  22. public:
  23. int currentTime = 0;
  24. int maxTime = 120;
  25. int numberOfPeople = 0;
  26. };
  27.  
  28. queue<personInLine> createQueue(int input) {
  29. queue<personInLine> returnObject;
  30. for (int i = 0; i < input; i++) {
  31. int tempInt = rand() % 4 + 1;
  32. personInLine ptr(tempInt, i);
  33. returnObject.push(ptr);
  34. }
  35. return returnObject;
  36. }
  37.  
  38. env createEnv(queue<personInLine> userInput) {
  39. env returnObject;
  40. for (int i = 0; i < userInput.size(); i++) {
  41. if (returnObject.currentTime < returnObject.maxTime && returnObject.currentTime + userInput.front().waitTime < returnObject.maxTime) {
  42. returnObject.currentTime = returnObject.currentTime + userInput.front().waitTime;
  43. returnObject.numberOfPeople++;
  44. cout << "current time: "
  45. }
  46. else {
  47. break;
  48. }
  49. }
  50. return returnObject;
  51. }
  52.  
  53. void main() {
  54. env myEnv;
  55. myEnv = createEnv(createQueue(1000));
  56. cout << "total time used for customers: " << myEnv.currentTime << endl << endl << "number of people servered: " << myEnv.numberOfPeople << endl << endl;
  57.  
  58.  
  59.  
  60. system("pause");
  61. }
Advertisement
Add Comment
Please, Sign In to add comment