a)
function [grade]= num2grade(points) if round(points) ~= points error('points is not an integer.') elseif points > 100 || points < 0 error('points is not within closed the intervall [0,100].') elseif points > 88 grade = 'A'; elseif points > 76 grade = 'B'; elseif points > 64 grade = 'C'; elseif points > 52 grade = 'D'; elseif points > 40 grade = 'E'; else grade = 'F'; end end
b)
function grade = evaluateGrade(points,hand_W) grade = num2grade(points); if strcmp(hand_W,'fin') && grade ~= 'A' grade = grade-1; elseif strcmp(hand_W , 'stygg') && grade ~= 'F' grade = grade + 1; end end
c)
function points = randomGrade() points = randi([0,100],1,1); end
d)
function hand_W = randomHandW () temp = randi([0,1],1,1); if temp == 1 hand_W = 'fin'; else hand_W = 'stygg'; end end
e)
function [] = untitledFunction7() points = randomGrade(); hand_W = randomHandW (); grade = evaluateGrade(points,hand_W); fprintf('Du fikk %d poeng på eksamen, en %s. Fordi du skrev %st ble dette en %s\n',points,num2grade(points), hand_W, grade) end