Write a C++ computer program that simulates the action of an elevator that is out of order. After simulating the motion of the elevator, your program will display a bar chart that shows the number of times the elevator stays on each floor of a twenty-five-story building.
When you arrive on the scene to begin studying the elevator, it is on the twelfth floor of the twenty-five-story building. Every five minutes the elevator either moves up one floor or down one floor. There is the same chance that the elevator will move up as move down, it is totally random. Keep track of the number of times the elevator stays at each of the twenty-five floors and display that information as a bar chart using a character like an asterisk to represent each time the elevator stays on a particular floor.
For example, our elevator starts on the twelfth floor and moves up to the thirteenth floor, five minutes later it moves up to the fourteenth floor and after another five minutes it moves back down to the thirteenth floor. A portion of a bar chart showing the number of visits the elevator made to each floor might look like this:
Floor Number of Visits
----- -----------------------
17
16
15
14 *
13 **
12 *
11
10
This is only a portion of the output your program will produce. Your Bar Chart will include all 25 floors from 25 through 1. Your output will display the top floor (25) at the top and the bottom floor (1) at the bottom to properly represent the floors in the building.
Observe the elevator’s behavior for a number of hours that is entered by your user. Do not forget to validate your user’s input. Your bar chart will show how many times the elevator visited each floor.
NOTES:
This assignment allows you to use an array, generate random numbers, interact with your user, validate input, control processing with repetition structures, and format output.
In order to receive full credit for this assignment:
Suggested Grading Criteria:
Example output:
Floor Number of Visits
----- ---------------------------
25
24
23
22
21
20
19
18 ****
17 ******
16 *********
15 ***************
14 *********************
13 ***********************
12 **********************
11 ****************
10 *****
9
8
7
6
5
4
3
2
1
Cpp code:
// Header files
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <string>
#include <ctime>
using namespace std;
int main()
{
/*constants variable declarations*/
const int MAX_FLOORS = 25;
const int MAX_OBSERVE_HOURS = 10;
const int MINUTES_PER_HOUR = 60;
const int MINUTES_TO_STAY_ON_FLOOR = 5;
/*setting seed to generate random numbers*/
srand(time(NULL));
/*create an array for floors*/
int floors[MAX_FLOORS + 1];
/*initializing floors with 0*/
for (int i = 0; i < MAX_FLOORS; i++)
{
floors[i] = 0;
}
/*variable declarations*/
int hours;
int minutes;
int Move;
int currFloor;
/*prompting the user to enter the number of hours to observe the
elevator's behavior.*/
cout << "Enter the number of hours to observe the elevator’s
behaviour: ";
cin >> hours;
/*validate the user input*/
while (hours < 0 || hours > MAX_OBSERVE_HOURS)
{
/*again taking the user input*/
cout << "Range of hours to observe is [1-" <<
MAX_OBSERVE_HOURS << "]. Try again!" << endl;
cout << "Enter the number of hours to observe the elevator’s
behaviour: ";
cin >> hours;
}
currFloor = 12; // starting from 12th floor
floors[currFloor]++;
minutes = 0;
while(minutes < hours * MINUTES_PER_HOUR)
{
//generate a random number either 0 or 1
Move = rand() % 2;
if (Move == 0 && currFloor > 1)
{
// move to the down floor if current floor is greater than the 1st
floor
currFloor--;
// increment the number of visits
floors[currFloor]++;
// stay 5 minutes at the current floor
minutes += MINUTES_TO_STAY_ON_FLOOR;
}
else if (Move == 1 && currFloor < 25)
{
// Move to the up floor if current floor is less than the 25th
floor
currFloor++;
// increment the number of visits
floors[currFloor]++;
// stay 5 minutes at the current floor
minutes += MINUTES_TO_STAY_ON_FLOOR;
}
}
// display a bar chart showing the number of visits to all 25
floors of the building
cout << endl;
cout << "Floor Number of Visits" << endl;
cout << "----- ---------------------------" <<
endl;
for (currFloor = MAX_FLOORS; currFloor > 0; currFloor--)
{
cout << right << setw(5) << currFloor << "
" << left;
for (int i = 0; i < floors[currFloor-1]; i++)
{
cout << "*";
}
cout << endl;
}
return 0;
}
Images of code:




Output:

Write a C++ computer program that simulates the action of an elevator that is out of...
In C++ Write a program that calculates the occupancy rate for a hotel. The program should start by asking the user how many floors the hotel has. A loop should then iterate once for each floor. In each iteration, the loop should ask the user for the number of rooms on the floor and how many of them are occupied. After all iterations, the program should display how many room the hotel has, how many of them are occupied, how...
Question 2. There are only two buttons inside an elevator in a building with 50 floors. The elevator goes 11 floors up if the first button is pressed and 6 floors down if the second button is pressed. Using dynamic programming methods to answer the following questions. Is it possible to get from floor 27 to floor 29? (5 points) What is the minimum number of buttons one has to press to do so? (10 points) What is the shortest...
Homework #5 - Elevator Simulation - Doubly Linked List The program needs to use a doubly linked list. Homework #5 - Extra Credit Elevator Simulation Algorithm We are going to develop an algorithm and implement in C++ to simulate a single elevator in a 10-story building. There will be some simplifying assumptions that will make this a bit less complex than a real-world implementation. The number of floors is not important, nor is the number of people getting on or...
Write a complete Java program with methods that prompt user for the number of floors, rooms, occupied rooms in a hotel. You must validate floors, rooms, occupied rooms. Compute vacant rooms, occupancy rate on each floor and display rooms, occupied rooms, vacant rooms and occupancy rate for each floor. Use the given method names. See validation rules below: 1. getFloors(). This method prompts user for number of floors in a hotel and returns floors to the caller. 2. testFloors(floors). Do...
Design a Mealy FSM that will model an elevator that can be at any of 4 floors of EPIC (Ground, First, Second, and Third). There are 2 input buttons that are active High – U to move UP and D to move DOWN. The input buttons are mutually exclusive, that is, only one of them can be active at any point in time (U = 0 and D = 1 makes it go DOWN, and U = 1 and D...
Using C++ create a lotto program Lottery Design a program that simulates a lottery. Requirements: The program should have an array of 5 integers named lottery and should generate a random number in the range of 1 through 99 for each element of the array. The user should enter five digits, which should be stored in an integer array named user. The program is to compare the corresponding elements in the two arrays and keep a count of the digits that...
Write a C++ program that simulates a lottery game. Your program should use functions and arrays. Define two global constants: - ARRAY_SIZE that stores the number of drawn numbers (for example 5) -MAX_RANGE that stores the highest value of the numbers ( for example 9 ) The program will use an array of five integers named lottery, and should generate a random number in the range of 0 through 9 for each element of the array. The user should enter...
Using Microsoft Visual Studio 2017 C++, write a C++ program to calculate to analyze the data from the number of visitors to Sleeping Bear Dunes in Michigan in 2015. Requirements Read the data from the Months.txt and Visitors.txt files. The text files are provided for you to download. The data was obtained from the National Park Service website. Design the program so the user enters a menu item and the following is displayed Display the chart below Totals and display...
Please make a JAVA program for the following using switch structures Write a program that simulates a simple Calculator program. The program will display menu choices to the user to Add, Subtract, Multiply and Divide. The program will prompt the user to make a selection from the choices and get their choice into the program. The program will use a nested if….else (selection control structure) to determine the user’s menu choice. Prompt the user to enter two numbers, perform the...
This is a repost of my question from before. I am having trouble writting the code for this project. Below is the project description with various methods and classes the code in C++ should implement. Project Description The goal of this project is to design and develop C++ code and algorithms to control a bank of elevators, which services many floors and transports people “efficiently ", that is, as per the given specifications. A second goal is to effectively employ...