Question

In: Computer Science

Write a function that takes a number as input, and returns the character A if the...

Write a function that takes a number as input, and returns the character A if the input is 90 and above, B if it’s 80 and above but less than 90, C if it’s at least 70 but less than 80, D if it’s at least 60 but less than 70, and F if it’s less than 60. If the input is not a number or is negative, the function should exit 1 with an error (by calling the Matlab function error).

function letter = grade (percent)

% Inputs: percent -- percentage grade
%
% Output: letter -- letter grade
%
% For example,
% l = grade (85) should return B
% l = grade (90) should return A
% l = grade (35) should return Z

Need to submit Matlab function online to check if if successful. Please help!

Solutions

Expert Solution

SOURCE CODE:

percent=0
function letter=grade(percent) %function grade() for calculating grade
if percent>=90 %if percent is greater than equal to 90
letter='A'
return
%if percent is greater than equal to 80 and less than 90   
elseif percent>=80 && percent<90
letter='B'
return
%if percent is greater than equal to 70 and less than 80   
elseif percent>=70 && percent<80
letter='C'
return
%if percent is greater than equal to 60 and less than 70   
elseif percent>=60 && percent<70
letter='D'
return
%if percent is less than 60 and greater than 0   
elseif percent<60 && percent>=0
letter='F'
return
%if percent is not numberic or less than 0(i.e negative number)   
elseif isnumeric(percent)==0 || percent<0
error('Number is not accepted') %calling error function
end
endfunction
percent=input("Enter a number: ") %reading input from user
letter=grade(percent) %calling grade() function
fprintf('The final grade is: %s',letter) %printing final grade

CODE SCREENSHOT:

OUTPUT:


Related Solutions

Write a PYTHON function CommonLetters(mystring) that takes mystring as input and returns the number of letters...
Write a PYTHON function CommonLetters(mystring) that takes mystring as input and returns the number of letters in mystring that also occur in the string ‘Python’. Using above function, write a program that repeatedly prompts the user for a string and then prints the number of letters in the string that are also in string ‘Python’. The program terminates when the user types an empty string.
write a function that takes as input the root of a general tree and returns a...
write a function that takes as input the root of a general tree and returns a binary tree generated by the conversion process illustrated in java
Write a function that takes a list of integers as input and returns a list with...
Write a function that takes a list of integers as input and returns a list with only the even numbers in descending order (Largest to smallest) Example: Input list: [1,6,3,8,2,5] List returned: [8, 6, 2] Do not use any special or built in functions like append, reverse etc.
USING PYTHON, write a function that takes a list of integers as input and returns a...
USING PYTHON, write a function that takes a list of integers as input and returns a list with only the even numbers in descending order (Largest to smallest) Example: Input list: [1,6,3,8,2,5] List returned: [8, 6, 2]. DO NOT use any special or built in functions like append, reverse etc.
Write a function bracket_by_len that takes a word as an input argument and returns the word...
Write a function bracket_by_len that takes a word as an input argument and returns the word bracketed to indicate its length. Words less than five characters long are bracketed with << >>, words five to ten letters long are bracketed with (* *), and words over ten characters long are bracketed with /+ +/. Your function should require the calling function to provide as the first argument, space for the result, and as the third argument, the amount of space...
Write a C function called weighted_digit_sum that takes a single integer as input, and returns a...
Write a C function called weighted_digit_sum that takes a single integer as input, and returns a weighted sum of that numbers digits. The last digit of the number (the ones digit) has a weight of 1, so should be added to the sum "as is". The second from last digit (the tens digit) has a weight of 2, and so should be multiplied by 2 then added to the sum. The third from last digit should be multiplied by 1...
Write a function in Matlab that takes as input the number n and a symmetric tridiagonal...
Write a function in Matlab that takes as input the number n and a symmetric tridiagonal matrix given as two vectors: n×1 vector v representing the main diagonal and (n−1)×1 vector w representing the upper diagonal. Have this function output the Cholesky factor of the matrix as a vector for the main diagonal and a vector for the upper diagonal and output the number of flops and, separately, the number of square roots used as well. Use only basic programming....
write a python function that takes a number as input argument, and that tries to determine...
write a python function that takes a number as input argument, and that tries to determine two other integers, root and pwr, such that root**pwr is equal to the integer passed as an argument to the function. Consider that pwr > 1. The function should return the values of root and pwr, as a string in the form root**pwr. For example, when the passed argument is 8, the function should return the string ‘2**3’. When the passed input argument does...
Write a function named "characters" that takes a string as a parameter and returns the number...
Write a function named "characters" that takes a string as a parameter and returns the number of characters in the input string
C++ write a function called divideBy that takes two integers as its input and returns the...
C++ write a function called divideBy that takes two integers as its input and returns the remainder. If the divisor is 0, the function should return -1, else it should return the remainder to the calling function.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT