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

  Randominrange() function that accepts two integer

Write a randomInRange() function that accepts two integer parameters. The parameters will represent the low number and the high number (both inclusive) in the random range. For example, when the function receives 3 and 8.

  During the execution of the above code, how many instru

(a) During the execution of the above code, how many instructions are executed? (b) Assuming a standard unicycle machine (CPI = 1) running at 100 KHz, how long will the above code take to complete?

  Takes a string containing a full name

Write a program that takes a string containing a full name and outputs each part of the name separately with its length. The name should be in the form of first, middle, and last name, separated from each other by a single space. For example, if the ..

  Implement circular linked list in c program

implement circular linked list in c program in the best possible easiest way.

  By a minimal interpretation that makes a formula

By a minimal interpretation that makes a formula true, we mean that if one atom is removed from the interpretation then the resulting interpretation does no longer make the formula true.

  Program that asks the user to enter the number of miles

Write a C - program that asks the user to enter the number of miles traveled and the number of gallons of gasoline consumed. It should then calculate and display the miles-per-gallon value. Confine your output to 1 decimal place.

  Draws a pyramid consisting of bricks

Write a C program that draws a pyramid consisting of bricks arranged in horizontal rows, so that the number of bricks in each row decreases by one as you move up the pyramid.

  Write a program that computes the cost of long distance call

Write a program that computes the cost of a long distance call. The cost of the call is determined according to the following rate schedules.

  Write program in c to calculate diameter-compression load

Write a program in C to calculate diameter in centimeters of steel rod, an aluminum rod, and a copper rod, which can withstand a particular compression load.

  A palindrome is a number

A palindrome is a number or text phrase that reads the same backward as forward. For example, each of the following five-digit integers is a palindrome: 12321, 55555, 34543 and 11611. Write a program that reads in a five-digit integer and determines ..

  Program that displays the ball at a random

Write a C++ program that displays the ball at a random location and then makes the ball move down to the bottom of the screen. When the ball reaches the bottom of the screen, it should start these actions over again, appear-ing at another random l..

  We wish to process survey results

Suppose we wish to process survey results that are stored in a file. This exercise requires twoseparate programs. First, create a program that prompts the user for survey responses and outputseach response to a file

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