Emulates the behavior of a bus

Assignment Help C/C++ Programming
Reference no: EM13163987

Write a program that emulates the behavior of a bus. The bus must have a schedule ( a finite number of times for it to stop) and a certain capacity (number of passengers). In this program the bus has two states: stopped and going. Over time, events take place, such as stopping the bus ( for which the bus must already be going ), loading passengers, unloading passengers, or starting the bus. For each event, the current state of the bus must change accordingly. Each time the bus stops, it must load and unload passengers. The number of passengers that will be unloaded at every bus stop must be generated randomly. The number of passengers waiting for the bus at each stop is also generated randomly. The bus should load as many waiting passengers as possible without exceeding the bus capacity. Write a program that implements this model, with the following operation:

void stop_bus();   /* Stop the bus   */

void start_bus();   /* Start the bus   */

void load_pass(); /* Load passengers */

void unload_pass(); /* Unload passengers */

Note: These function prototypes lack parameters; add whatever parameters you feel are necessary so that the program works without global variables. The program's output should reflect the bus's actions by reporting each change in state, along with the number of passengers loaded and unloaded.

Hints:

Bus status transition diagram: ( Diagram in the link: https://www.dropbox.com/s/qwe455521mm9hex/BUS%20C%2B%2B.jpg )

Bus travel from the first station to the last station. In each station, bus needs to stop, unload passengers, load passengers, and start. However, based on the station, bus's status , and the number of passengers, those actions may do different things.

In the computation (or simulation), bus will repeat actions in each station. In such a iteration, siulation codes call functions stop_bus, unload_pass, load_pass, and start_bus. In a specific function, we need to handle all cases.

For example,

Load_passengers

Case 1: If bus status is "running", do noting (direct return)

Case 2: If bus is full, do nothing

Case 3: If bus is in the last station, do nothing

Case 4: If the number of passengers plus the number of wating people is more than the max capacity, only a part of waiting customers can get loaded (to change the number of passengers)

Case 5 : Or else, all waiting people get loaded (to change the number of passengers)

Inputs: station_id, max_station_id, bus_status, &passengers

Output: the number of people who get loaded

Unload_passengers

Case 1: If bus is "running", do nothing

Case 2: If bus is empty, do noting

Case 3: If bus is in the last station, all passengers get unloaded (to change the number of passengers to be 0)

Case 4: Or else, our program generates a random number which represents the unloaded passengers (to change the number of passengers)

Inputs: station_id, max_station_id, bus_status, &passengers,

Outputs: the number of people who get unloaded

Stop_bus

Case 1: if bus is in the first station, display "Welcome!"

Case 2: Or else display "We are in the station X."

Inputs: station id, &bus_status

Start_bus

Case1: If bus is in the last station, do nothing

Case 2: Or else display "We leave for our next station X"

Inputs: station_id, max_station_id, &bus_status

Reference no: EM13163987

Questions Cloud

How much h2o is needed : Acetylene gas (C2H2) is produced as a result of the reaction CaC2(s)+2H2O(l)-> C2H2(g)+Ca(HO)2(aq) if 13g of CaC2 are consumed in this reaction, how much H2O is needed?
How many moles of sodium phospahte were present : A student mixed 5.00 mL of a nickel(2) chloride solution with 5.00 mL of .100M sodium phosphate and a precipitate formed. How many moles of sodium phospahte were present in 5.00 mL of the solution?
How many moles of cn- ions will be contained : A 270 mL stock solution contains 0.9 M Ca(CN)2. When 103 mL of the stock solution is diluted to 130 mL, how many moles of CN- ions will be contained in the dilute solution?
Calculate the de broglie wavelength : Calculate the de Broglie wavelength for each of the following.a 57 g ball with a velocity of 35. m/s b an electron with a velocity 12% the speed of light.
Emulates the behavior of a bus : Write a program that emulates the behavior of a bus. The bus must have a schedule ( a finite number of times for it to stop) and a certain capacity (number of passengers). In this program the bus has two states: stopped and going.
What objectives and political philosophies did he advocate : Who was Eugene V. Debs and what objectives and political philosophies did he advocate? What did he accomplish in 1912?
Method that receives an array and returns with no duplicate : Write a program that contrains a method that receives an array and returns a new array with no duplicates.
The knight''s tour problem : The knight's tour problem is as follows: given an initial position for a single knight on an otherwise empty chessboard, find a sequence of 64 moves that will make the knight visit every square on the board exactly once
Three dimensional array representing parking spaces : start with code in the file lab.cpp. This program works with a three dimensional array representing parking spaces in a parking garage on several floors. The code is incomplete. The functions "main", "display" and "showSpace" are complete. Your job i..

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Write a function to compute the magnitude f

write a function to compute the magnitude F and direction angle of a two-dimensional force F by using two components of the force fx,fy as its parameters,returning F and using the reference to pass theta value .

  Problems on oops

Problems on OOPS

  Array of integers declared-initialized to number of tickets

Array of integers named parkingTickets has been declared and initialized to number of parking tickets given out by city police each day as beginning of current year.

  Create a class called point3d

Create a class called Point3D to represent 3D point in space, a class called Sphere and a class called Cylinder. The sphere is characterized by its center point and the radius while the Cylinder can be characterized by its center point, radius and he..

  Create a program that maintains the required book catalog

Create a program that maintains the required book catalog for the circulation desk of a library.

  Program to produce ten random permutations of numbers

In C++(must be able to compile in Visual Studio ): Write a program to produce ten random permutations of numbers 1 to 10.

  Wrtie a function called gen_rand_double_array

Wrtie a function called gen_rand_double_array that generates 900 samples of size 22500 random numbers from U(10, 12). For each of these 900 samples, write a main funciton that calculates the mean and finds the simulated probability that the mean is b..

  Write a program to read only one integer number

Write a program to read ONLY one integer number (your input must be one 3 digit number from 100 to 999), and to think of a number as being ABC (where A, B, and C are the 3 digits of a number)

  Design and write a c++11/fltk game program

The project is to design and write a C++11/FLTK game program with a graphical user interface. The game is based on "pancake sorting," which actually has some mathematical significance.

  Write a program that converts between app and ppm values

Write a simple program that converts between APP and PPM values

  Write the code required to analyse and display the data

Calculate and store the average for each row and column. Determine and store the values for the Average Map.

  How nested if-statements replace with one if-statement

Describe how following nested If-statements could be replaced with one if-statement using logical operator (And/Or/Not). Write down the C++ code example.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd