You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 8 Next »

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, handWriting)
    grade = num2grade(points);
    if handWriting && grade ~= 'A' 
        grade = grade - '1';
    else if ~handWriting && 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 grades()
    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

 

 

  • No labels