Question

Before reading this assignment, remember that the Guide to Mini Projects is ALWAYS part of the...

Before reading this assignment, remember that the Guide to Mini Projects is ALWAYS part of the instructions for EVERY Mini Project Assignment. Please go back and read it before beginning.

Mini Project #2 – Bus Routes

Introduction

You are working for a city, and want to set up a system for better understanding the needs of the busses running on certain routes. Using demographic data and technical specifications of busses, the city has created data structures for each city bus with the following properties that do not change:

bus.mass – The mass of the buss

bus.passMass – The average mass of a passenger on a route

bus.engine – The amount of force the bus’s engine puts out per unit mass

In addition, you have added the following property to the structure for simulation purposes. This property

can change:

bus.numPass – The number of passengers on the bus.

Procedure

The city wants you to do some calculations on the amount of work buses have to do on bus routes, given the number of passengers entering and leaving busses. You will write a function called busSim that will take the following inputs:

bus – A structure with the format defined above. You can assume that it will start with a certain number of passengers on board.

passOn – An array that contains only integers. This is the number of passengers that get on at each stop.passOff – An array that contains only integers and is the same length as passOn. This is the number

of passengers that get off at each stop.

distance – An array that contains real numbers that is the same length as passOn containing the distance the bus has to travel after each bus stop to get to the next stop.

It should return the following ouputs:

bus – An updated version of the input structure with the final number of passengers.

passRecord – An array with the same length ad passOn with the number of passengers after each bus stop.

totalWork – A real number that is the total amount of work the bus’s engine has had to put out on the entire trip. You can assume that passengers will board and leave the bus at the first stop beforeyou have to make the first work calculation. You should therefore make as many work calculations as there are elements in each of the input arrays.

Additional Code – Data Entry Errors

Your function should work with any inputs that are of the correct input data types, even if they contain errors. You should handle those errors in the following ways:

  • - If your input arrays are not all the same length you should only do calculations up to the index of the shortest array.

  • - If the number of passengers would ever go below 0, it should instead be set to 0.

  • - If the number of passengers would ever be a non-integer value, it should instead be rounded up

    to the nearest integer.

  • - If a distance is listed as negative, treat it as positive

    You can assume the following and do not have to check for them:

  • - Masses will always be positive

  • - Engines will always put out positive force

  • - The numbers in passOn or passOff will always be non-negative

Code for MatLab

0 0
Add a comment Improve this question Transcribed image text
Answer #1

function [bus,passRecord,totalWork] = busSim(bus,passOn,passOff,distance)


passOn = ceil(passOn);
passOff = ceil(passOff);
distance = abs(distance);

array_length = min(numel(passOn),numel(passOff));
passRecord = zeros(1,array_length);

aboard = bus.numpass+ passOn(1)-passOff(1);
passRecord(1) = aboard*(aboard>=0);

for i=2:array_length
aboard = passRecord(i-1) + passOn(i) - passOff(i);
passRecord(i) = aboard*(aboard>=0);
end

totalWork = sum(distance(1:array_length) .* bus.engine.*(bus.mass + bus.passMass.*passRecord)); % w = dxf
bus.numpass = passRecord(end);
end

-------------------------------------------------------------------

%command

clc
clear

%constants
bus.mass = 1000; %kg
bus.passMass = 50; %kg
bus.engine = 2; %N per unit mass

%some random variables
bus.numpass = randi(10);
passOn = randi(5,1,10);
passOff = randi(5,1,10);
distance = randi(30,1,10);

disp('INPUTS:')
disp('bus:');disp(bus)
disp('numpass:');disp(bus.numpass)
disp('passOn:');disp(passOn)
disp('passOff:');disp(passOff)

[bus,passRecord,totalWork] = busSim(bus,passOn,passOff,distance);

disp('OUTPUTS:')
disp('bus:');disp(bus)
disp('passRecord:');disp(passRecord)
disp('totalWork:');disp(totalWork)

Add a comment
Know the answer?
Add Answer to:
Before reading this assignment, remember that the Guide to Mini Projects is ALWAYS part of the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • PLEASE ANSWER USING MATLAB SYNTAX AND LANGUAGE. You are working for a city, and want to...

    PLEASE ANSWER USING MATLAB SYNTAX AND LANGUAGE. You are working for a city, and want to set up a system for better understanding the needs of the busses running on certain routes. Using demographic data and technical specifications of busses, the city has created data structures for each city bus with the following properties that do not change: bus.mass – The mass of the buss bus.passMass – The average mass of a passenger on a route bus.engine – The amount...

  • C. In Regular Bus City, there is a shuttle bus that goes between Stop A and Stop B, with no stops...

    Question D C. In Regular Bus City, there is a shuttle bus that goes between Stop A and Stop B, with no stops in between. The bus is perfectly punctual and arrives at Stop A at precise five minute intervals (6:00, 6:05, 6:10, 6:15, etc.) day and night, at which point it immediately picks up all passengers waiting. Citizens of Regular Bus City arrive at Stop A at Poisson random times, with an average of 5 passengers arriving every minute,...

  • In a series of numbers, a "mini peak" is a set of 3 numbers where the...

    In a series of numbers, a "mini peak" is a set of 3 numbers where the middle number is strictly greater than its adjacent left and right neighbors. For example, the array: [ 4, 6, 2, 1 ] contains 1 mini peak, with 6 in the middle ([ 4, 6, 2]). Write full and complete C++ program to open a text file named numbers.txt in the working folder, which contains groups of numbers, one per line, with each group starting...

  • Implement a C program unique.c that recreates the functionality of the uniq tool by reading the...

    Implement a C program unique.c that recreates the functionality of the uniq tool by reading the input line by line and dropping each l ine that is identical to the line immediately before it. On the input abc abc abc your program should output abc abc the same output that uniq would produce. While not strictly necessary for this step, it is important as a basis for subsequent steps that you read the entire input and store it as a...

  • Description An array in C++ is a collection of items stored at contiguous memory locations and...

    Description An array in C++ is a collection of items stored at contiguous memory locations and elements can be accessed randomly using indices of an array. They are used to store similar type of elements as in the data type must be the same for all elements. One advantage of arrays is easy data manipulation and accessibility of elements stored in consecutive locations. The Problem: One teaching assistant of a computer science department in Engineering University got a simple question...

  • C++ code The assignment has two input files: • LSStandard.txt • LSTest.txt The LSStandard.txt file contains...

    C++ code The assignment has two input files: • LSStandard.txt • LSTest.txt The LSStandard.txt file contains integer values against which we are searching. There will be no more than 100 of these. The LSTest.txt file contains a set of numbers that we are trying to locate within the standard data set. There will be no more than 50 of these. Read both files into two separate arrays. Your program should then close both input files. All subsequent processing will be...

  • Matrix Multiplication with Threads - C/C++ **Please read entire question before answering** In this assignment you...

    Matrix Multiplication with Threads - C/C++ **Please read entire question before answering** In this assignment you will use the Pthreads library to write a program that multiplies two square arrays and compare the difference between the imperative and parallel implementations of this algorithm. Use the matrix mulltiplication algorithm. Write a program that contains three functions: (1) A function that has an integer as a parameter and returns a pointer to square array of integers (i.e. both dimensions should be equal)....

  • CISC 1115 Assignment 6 Write a complete program, including javadoc comments, to process voter statistics Input...

    CISC 1115 Assignment 6 Write a complete program, including javadoc comments, to process voter statistics Input to Program: A file containing lines of data, such that each line has 2 integers on it The first integer represents a zip code (in Brooklyn or the Bronx), and the second represents the number of voters in that zip code. Output: All output may be displayed to the screen. In main: 1. Your program will read in all of the data in the...

  • Python: Arrays and Lists (do code on repl.it) Part C (4 points) - more advanced lists...

    Python: Arrays and Lists (do code on repl.it) Part C (4 points) - more advanced lists You will need a Python repl to solve part C. In Python, define a function named secondHighest which accepts a list of numbers, and returns the second highest number from the list. If the highest value occurs more than once, then it is also the second highest (see example). Assume the input list will always have length at least two (so there is always...

  • Assignment 6, Merge Arrays (java) Instructions In this assignment, you will write a program which merges...

    Assignment 6, Merge Arrays (java) Instructions In this assignment, you will write a program which merges two arrays of positive integers and removes any duplicate entries. Your program will first ask for a valid length which must be an integer which is 10 or greater. The program should continue to ask until a valid length is entered. The program will then create two arrays of the length entered, fill these with random integers between 1 and 100 inclusive, and print...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT