Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask C/C++ Expert


Home >> C/C++

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

C/C++, Programming

  • Category:- C/C++
  • Reference No.:- M9454106

Have any Question?


Related Questions in C/C++

1 implement the binary search tree bst in c using the node

1. Implement the Binary Search Tree (BST) in C++, using the Node class template provided below. Please read the provided helper methods in class BST, especially for deleteValue(), make sure you get a fully understanding ...

Why do researcher drop the ewaste and where does it end

Why do researcher drop the ewaste and where does it end up?

Assign ment - genetic algorithmin this assignment you will

ASSIGN MENT - GENETIC ALGORITHM In this assignment, you will use your C programming skills to build a simple Genetic Algorithm. DESCRIPTION OF THE PROGRAM - CORE REQUIREMENTS - REQ1: Command-line arguments The user of yo ...

Software development fundamentals assignment 1 -details amp

Software Development Fundamentals Assignment 1 - Details & Problems - In this assignment, you are required to answer the short questions, identify error in the code, give output of the code and develop three C# Console P ...

Assignment word matchingwhats a six-letter word that has an

Assignment: Word Matching What's a six-letter word that has an e as its first, third, and fifth letter? Can you find an anagram of pine grave. Or how about a word that starts and ends with ant (other than ant itself, of ...

What are the legal requirements with which websites must

What are the legal requirements with which websites must comply in order to meet the needs of persons with disabilities? Why is maximizing accessibility important to everyone?

Question 1find the minimum and maximum of a list of numbers

Question: 1. Find the Minimum and Maximum of a List of Numbers: 10 points File: find_min_max.cpp Write a program that reads some number of integers from the user and finds the minimum and maximum numbers in this list. Th ...

There are several ways to calculate the pulse width of a

There are several ways to calculate the pulse width of a digital input signal. One method is to directly read the input pin and another method (more efficient) is to use a timer and pin change interrupt. Function startTi ...

Project - space race part a console Project - Space Race Part A: Console Implementation

Project - Space Race Part A: Console Implementation INTRODUCTION This assignment aims to give you a real problem-solving experience, similar to what you might encounter in the workplace. You have been hired to complete a ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As