Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1.  
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <sys\time.h>
  5. #include <math.h>
  6. #include <queue.h>
  7. typedef struct customer
  8. {
  9. unsigned int transactionTime;
  10. unsigned int startTimeInLine;
  11. unsigned int endTimeInLine;
  12. };
  13.  
  14. void initTimeClock(void);
  15. struct timeval t1, t2;
  16. static double elapsedTime;
  17. static int time = 0;
  18. static int customerWait = 0;
  19. static int customerNumber = 0;
  20.  
  21. int main(int argc, char *argv[]) {
  22.  
  23. printf("Bank Opened");
  24. printf("\n");
  25. initTimeClock();
  26.  
  27. while ((int) elapsedTime < 12000) {
  28. printf("Hours, %f \n", elapsedTime);
  29. updateTimeClock();
  30. generateCustomer();
  31.  
  32. }
  33. printf("Customers Served Today: %f \n", customerLine.size());
  34. printf("Bank Closed");
  35. printf("\n");
  36.  
  37. }
  38.  
  39. void initTimeClock(void) {
  40. // start timer
  41. gettimeofday(&t1, NULL);
  42. //create queue
  43. queue<int> customerLine;
  44. }
  45.  
  46. void updateTimeClock(void) {
  47. // stop timer
  48. gettimeofday(&t2, NULL);
  49. // compute and print the elapsed time in millisec
  50. elapsedTime = (t2.tv_sec - t1.tv_sec) * 1000.0; // sec to ms
  51. elapsedTime += (t2.tv_usec - t1.tv_usec) / 1000.0; // us to ms
  52. }
  53. double rand_normal(double mean, double stddev) { //Box muller method
  54. static double n2 = 0.0;
  55. static int n2_cached = 0;
  56. if (!n2_cached) {
  57. double x, y, r;
  58. do {
  59. x = 2.0 * rand() / RAND_MAX - 1;
  60. y = 2.0 * rand() / RAND_MAX - 1;
  61.  
  62. r = x * x + y * y;
  63. } while (r == 0.0 || r > 1.0);
  64. {
  65. double d = sqrt(-2.0 * log(r) / r);
  66. double n1 = x * d;
  67. n2 = y * d;
  68. double result = n1 * stddev + mean;
  69. n2_cached = 1;
  70. return result;
  71. }
  72. } else {
  73. n2_cached = 0;
  74. return n2 * stddev + mean;
  75. }
  76. }
  77.  
  78. void generateCustomer(void) {
  79. customerNumber++;
  80. //customerWait = rand() % 400 + 100;
  81. customerWait = rand_normal(250, 50);
  82. delay(customerWait);
  83. printf("Customer Number: , %d "
  84. "\n", customerNumber);
  85. printf("Customer created, %d "
  86. "\n", customerWait);
  87. //customer newCustomer = {0, elapsedTime, 0};
  88. customerLine.push(elapsedTime);
  89. updateTimeClock();
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement