Your Perfect Assignment is Just a Click Away
We Write Custom Academic Papers

100% Original, Plagiarism Free, Customized to your instructions!

glass
pen
clip
papers
heaphones

Introduction to Computer Programming

Introduction to Computer Programming

Introduction to Computer Programming with MATLAB CEE/MAE M20

EXTRA CREDIT 1 Due: Friday, August 13th 2021, 11:59 PM

Formatting Reminder: The submitted work MUST follow the naming convention listed below.

• “LastName UID EC code.zip”

• “LastName UID EC main.m”

Submit one file to the CCLE course website a .zip file containing all of the MATLAB files written for the assignment. Remember to use good coding practices by keeping your code organized, choosing suitable variable names, and commenting where applicable. Any of your MATLAB .m files should contain a few comment lines at the top to provide the name of the script, a brief description of the function of the script, and your name and UID. Any submission that does not follow the above-mentioned format will receive severe point deductions!

1. The Ranked-Choice Vote. In class, we talked about an alternative voting system in which voters rank all the candidates in order of preference instead of supporting only a single candidate. During each round of voting, only a voter’s highest-ranked eligible candidate is con- sidered. If no candidate wins a majority, the lowest performer is eliminated from all ballots and the totals are recalculated. This process continues until cone candidate achieves a majority, i.e. > 50% of the votes. Consider the following election with 9 voters deciding between 4 candidates.

1

where voter 1’s favorite candidate is 3 and least favorite candidate is 4. After the first round of voting, candidate 2 leads with 4 votes but does not secure > 50% of the total vote. Thus, the least-popular option, candidate 1, is eliminated from all ballots and the votes are recounted. Write a script that performs this vote counting process on a large set of election data until a winner has been found.

(a) Begin by writing a function to remove a specified candidate from all ballots. This function must use exactly the specification shown below, where the function name, inputs, and outputs must be followed exactly. function votes = removeCandidate(votes,losingCandidate)

This function takes the total votes array, searches for all instances of losingCandidate (losingCandidate = 1 in the above example), and removes them from the array. Since we are assuming voters will list every candidate only once, the dimension of the votes array is updated from [N × c] to [N × c ? 1].

(b) Using your removeCandidate function, write a script to determine each win- ning candidate given the mock election results posted to CCLE (we will use the load function to access the raw data.) Your code only needs to process one set of votes per run, simply swapping the load filename between runs to generate both results. Print your results to the command window using exactly the format shown below:

1 2 3 4

Round 1 Totals: 1 4 2 2

Round 2 Totals: 0 4 3 2

Round 3 Totals: 0 4 5 0

Winning Candidate: 3

Where the candidates’ round-by-ro

Order Solution Now