Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. // elevator.cpp
  2. //
  3.  
  4. #include "pch.h"
  5. #include <iostream>
  6. #include <cstdlib>
  7. #include <time.h>
  8.  
  9. using namespace std;
  10.  
  11. int main()
  12.  
  13. {
  14. //variable declaration
  15. int arr[25];
  16. int n, f, r, i;
  17.  
  18. //accepting the input from user
  19. do
  20. {
  21. cout << "Enter the number of hour" << endl;
  22. cin >> n;
  23.  
  24. if (n > 10)
  25. cout << "Hour cannot be greater than 10" << endl;
  26. }
  27.  
  28. //hour should be within 10
  29. while (n > 10);
  30. for (i = 0; i < 25; i++)
  31. arr[i] = 0;
  32.  
  33. r = n * 60 / 5; //calculatng max change in floor
  34.  
  35. int tp[r];
  36. int k = 0;
  37.  
  38. srand(time(NULL));
  39.  
  40. //generating randoom floor numbers
  41. for (i = 0; i < r; i++)
  42. {
  43. f = rand() % 25 + 1;
  44. tp[k++] = f;
  45. }
  46.  
  47. int temp, temp1;
  48. temp = tp[0]; //storing the first floor
  49. arr[temp - 1] = arr[temp - 1] + 1;
  50.  
  51. //checking for immediate up and down floor
  52. for (i = 1; i <= r; i++)
  53. {
  54. temp1 = tp[i];
  55. if (temp1 == temp + 1)
  56. {
  57. arr[temp1 + 1] = arr[temp1 + 1] + 1;
  58. temp = temp1;
  59. }
  60.  
  61. if (temp1 == temp - 1)
  62. {
  63. arr[temp1 - 1] = arr[temp1 - 1] + 1;
  64. temp = temp1;
  65. }
  66.  
  67. }
  68.  
  69. cout << endl;
  70.  
  71. //display bar chart
  72. for (i = 1; i <= 25; i++)
  73. {
  74. cout << i << " ";
  75. temp = arr[i - 1];
  76.  
  77. while (temp != 0)
  78. {
  79. cout << "*";
  80. temp = temp - 1;
  81. }
  82. cout << endl;
  83. }
  84. return 0;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement