Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // elevator.cpp
- //
- #include "pch.h"
- #include <iostream>
- #include <cstdlib>
- #include <time.h>
- using namespace std;
- int main()
- {
- //variable declaration
- int arr[25];
- int n, f, r, i;
- //accepting the input from user
- do
- {
- cout << "Enter the number of hour" << endl;
- cin >> n;
- if (n > 10)
- cout << "Hour cannot be greater than 10" << endl;
- }
- //hour should be within 10
- while (n > 10);
- for (i = 0; i < 25; i++)
- arr[i] = 0;
- r = n * 60 / 5; //calculatng max change in floor
- int tp[r];
- int k = 0;
- srand(time(NULL));
- //generating randoom floor numbers
- for (i = 0; i < r; i++)
- {
- f = rand() % 25 + 1;
- tp[k++] = f;
- }
- int temp, temp1;
- temp = tp[0]; //storing the first floor
- arr[temp - 1] = arr[temp - 1] + 1;
- //checking for immediate up and down floor
- for (i = 1; i <= r; i++)
- {
- temp1 = tp[i];
- if (temp1 == temp + 1)
- {
- arr[temp1 + 1] = arr[temp1 + 1] + 1;
- temp = temp1;
- }
- if (temp1 == temp - 1)
- {
- arr[temp1 - 1] = arr[temp1 - 1] + 1;
- temp = temp1;
- }
- }
- cout << endl;
- //display bar chart
- for (i = 1; i <= 25; i++)
- {
- cout << i << " ";
- temp = arr[i - 1];
- while (temp != 0)
- {
- cout << "*";
- temp = temp - 1;
- }
- cout << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement