Description
Assignment #4
Objective
This assignment is designed to provide you with practice using functions/sub-functions to perform computations. You will also practice using repetition/loops, selections, and formatting outputs. You will develop a MATLAB program that utilizes functions/sub-functions to summarize medal standings from the 2010 Winter Olympics in Vancouver based on results from individual sports.
Marking Scheme
This assignment is worth 3% of your final mark. You will get a total of 50 points for completing the following:
TASK POINTS
Correct use and design of function and subfunctions 35
Quality of code 15
TOTAL 50
Points for Quality of Code
• Complete file header – 3 points
• Design (appropriate use and naming of variables) – 5 points
• Comments in the code – 5 points
• Layout (indentation/spacing) – 2 points
Submission
• Filename for this assignment: Assign4_<UofA_ID_Number>.m. For example, for a U of A ID Number: 1234567890, the filename for assignment #4 is Assign4_1234567890.m
• Submit only your .m file under Assignment 4 in your eClass/Moodle account.
Problem and Program Details:
As a part-time blog writer for a major sports network you are tasked with providing a readerfriendly summary of the most recent Winter Olympics. This will be an integral part of an article that will be used to discuss the next Olympic Games. Given detailed results from the 2010 Winter Olympics in Vancouver, which were provided to you by your supervisor, you are asked to summarize the medal standing for all participating countries.
Your input data, which is provided in the olympics2010.mat file that can be downloaded from the eClass/Moodle, includes the following variables:
countries, which lists countries that scored medals. The countries are coded using three letter abbreviations, e.g., CAN stands for Canada. We use country code XXX to denote a case where two countries received the same medal (silver) in the same sport, i.e., there was a tie.
gold, silver and bronze, which list the countries that received gold, silver, and bronze medals, respectively. Note that the gold, silver and bronze variables list the data in the same order. This means that the ith row in these variables gives the countries that received the corresponding three types of medals for the same sport.
Your objective is to convert the results per sport (from the olympics2010.mat file) into a table that lists medal counts and total medal tally per country where countries are sorted alphabetically. Note that countries variable already lists the countries alphabetically. You should also show the best performing country (or countries in case of a tie), when scored on the total medal tally and the number of gold medals. Moreover, you are required to list the countries that have 20 or more medals. The results should be printed to the Command Window using a specific format shown below.
Code Requirements
1. You must use three sub-functions: the first that will compute number of gold, silver, and bronze medals per country; the second that will print the table with medal standings; and the third that will compute and print the best performing countries. The third sub-function should be called three times; each time for a different criteria of performance (most medals, most gold medals, and at least 20 medals).
2. Your primary/main function assignment4 should have the following outline:
function [] = assign4_<UofA_ID_Number>()
% clear Workspace and Command Window and load olympics2010
% compute medals for each country using a sub-function that is
% called using a loop over all countries
% display medal counts for all countries using a sub-function
% display countries with most medals, most gold medals, >=20 medals % using a sub-function, the same sub-function should be used 3 times
end
3. Use switch/case statement to select between different criteria in the third sub-function.
Hints
1. In Matlab, load the olympics2010.mat and see how the data is stored.
2. Do not display results for the XXX “country”, which is included in the olympics2010.mat file.
3. Note that it is possible that there is more than one country with the highest number of all medals, or highest number of gold medals, or at least 20 medals. In that case, you code should list all of these countries.
4. You must duplicate the shown below output, including spacing and formatting, and provide the data for the remaining countries. The “…” denotes the part of the report that you have to fill in.
Country Gold Silver Bronze Total
AUS 2 1 0 3
AUT 4 6 6 16
…
Countries with the most medals: …
Countries with the most gold medals: …
Countries with at least 20 medals: CAN GER …
5. Please remember to include your header at the top of your .m file. And finally please comment the primary function and all the subfunctions.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Course: ENCMP 100
% Assignment: 4
% Lab Section: A2
% Name: Joe MacDonald
% CCID: jmac
% I received help from Jason Smith on using functions
%
% File: Assign4_1234567890.m % Description:
% This program calculates medal standings for the Vancouver Olympics
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%




Reviews
There are no reviews yet.