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
b)
grade = evaluateGrade(points,h_Wrt) grade = num2grade(poits); if h_Wrt == 'fin' && grade ~= 'A' grade = grade+1; elseif h_Wrt == 'stygg' && grade ~= 'F' grade = grade - 1; 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 [] = grade() points = randomGrade(); hand_W = randomHandW (); grade = evaluateGrade(points,hand_W); fprintf('Du fikk %d poeng på eksamen, en %s. Fordi du skrev %s ble dette en %s',points,num2grade(points), hand_W, grade) end