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
  • 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...

  • 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)....

  • 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...

  • 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...

  • Number of Numbers (10 pts) For this assignment you will be working with arrays. Open a...

    Number of Numbers (10 pts) For this assignment you will be working with arrays. Open a new Java project called Nums Prompt a user to enter in the length of the array (the number of numbers). Enter the number of numbers: Use this information to declare an array of the user-specified length. Next, using a for loop, prompt the user to enter that many numbers, and store each one in your array until your array is at full capacity. Using...

  • In C++ Assignment 8 - Test Scores Be sure to read through Chapter 10 before starting this assignment. Your job is to write a program to process test scores for a class. Input Data You will input a tes...

    In C++ Assignment 8 - Test Scores Be sure to read through Chapter 10 before starting this assignment. Your job is to write a program to process test scores for a class. Input Data You will input a test grade (integer value) for each student in a class. Validation Tests are graded on a 100 point scale with a 5 point bonus question. So a valid grade should be 0 through 105, inclusive. Processing Your program should work for any...

  • 2. One the last exam, you analyzed a mini-version of the board game Chutes and Ladders. For your ...

    2. One the last exam, you analyzed a mini-version of the board game Chutes and Ladders. For your reference, this information is repeated on the next page. (a) Give the one-step transition matrix P for the Markov chain {Xn,n 2 0]. (This is the same question that was on the exam) (b) What is the expected length (number of spins) of a game? (c) In which square should the player expect to spend the most time? (d) In which square...

  • C# Visual Studios HelloWorld For this assignment, you'll work with first creating an array and populating...

    C# Visual Studios HelloWorld For this assignment, you'll work with first creating an array and populating it's values. Then, we'll use the values in the array to calculate the average. Since it's common for an average to result in numbers with decimal points, the array you create should be of type double[]. This program will need to use dynamic input from the user so perform the following steps: Ask the user how many numbers need to be added. Use this...

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
ADVERTISEMENT