PLEASE ONLY ATTEMPT IF YOU ARE SURE! Write a script M-file hw04-4 . Ti that prom
ID: 3755329 • Letter: P
Question
PLEASE ONLY ATTEMPT IF YOU ARE SURE!
Write a script M-file hw04-4 . Ti that prompts for a user key-board input of a numeric grade and outputs the corresponding letter grade on the terminal. The script uses a user defined function M- file that is passed a numeric grade from 0 to 100 and returns a letter grade according to the scheme A (90-100), B (80 to less than 90), C (70 to less than 80), D ( 60 to less than 70), F(less than 60). Write codes for both M-files. You are allowed to use Matlab built-in functions input and disp INPUT SCREEN Enter a Numeric Grade78 OUTPUT SCREEN: Letter arade Corresponding to Numeric Grade 78 is : CExplanation / Answer
Note: Be very careful while copying/re-writing the script text. Function name must be the same as the file it is contained in.
A check for the grade values out of [0 100] bound has also been included.
The required MATLAB script:
%================================
clear all
clc
num_grade = input('Enter a Numeric Grade : ');
while(num_grade<0 && num_grade>100)
num_grade = input('Invalid grade value, enter again : ');
end
letter_grade = grader(num_grade);
disp(['Letter Grade Corresponding to Numeric Grade ',num2str(num_grade), ' is : ',letter_grade]);
%======================================
The corresponding function script:
%======================================
function [letter_grade] = grader(num_grade)
if (num_grade>=90 && num_grade<=100)
letter_grade = 'A';
elseif (num_grade>=80 && num_grade<90)
letter_grade = 'B';
elseif (num_grade>=70 && num_grade<80)
letter_grade = 'C';
elseif (num_grade>=60 && num_grade<70)
letter_grade = 'D';
else
letter_grade = 'F';
end
end
%========================================
Sample output:
Enter a Numeric Grade : 78
Letter Grade Corresponding to Numeric Grade 78 is : C
Hope this helps! PLEASE THUMBS UP!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.