Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Function Name: divingScore % Inputs (2): - (double) A vector of judge\'s scores

ID: 3648427 • Letter: F

Question

Function Name: divingScore
% Inputs (2): - (double) A vector of judge's scores for a single dive
% - (double) the degree of difficulty of the dive performed
% Outputs (1): - (double) The final diving score
%
% Function Description:
% Write a function called "divingScore" that takes in a vector of scores
% for an single Olympic dive and the degree of difficulty and computes
% the overall score for the dive. In Olympic dive events, the highest and
% lowest score for each dive is dropped. The rest of the scores are then
% summed, and the result is multiplied by the degree of difficulty to
% produce the overall score for each dive.
%
% Test Cases:
% dive1 = [4.5 6.7 8.9 7.6 5.5 6.8];
% dive2 = [5.6 7.3 8.6 8.4 7.4 6.6];
%
% overall1 = divingScore(dive1, 2.5);
% overall1 => 66.5
%
% overall2 = divingScore(dive2, 1.6);
% overall2 => 47.52

Explanation / Answer

function overall=divingScore(score,degree) n=length(score); high=max(score); low=min(score); sum=-(high+low);%sets to negative of high and low score (will be added back later to =0 in for loop) for i=1:n sum=sum+score(i); end overall=sum*degree;