Grade Roster (condition looping through vector elements)
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Code has already been provided to create a function named assignGrade that defines a vector of integer exam scores to the input variable scores. Add code to the function that uses the values in scores to create a character array (string) named grade with the same number of rows as scores. Each element of the grade should contain a score from the input vector. The elements of grade should have strings that give the corresponding letter grade according to the following grading scale:
- Score values ranging from 90 to 100 receive an A.
- Score values ranging from 80 to 89 receive a B.
- Score values ranging from 70 to 79 receive a C.
- Score values ranging from 60 to 69 receive a D.
- Score values ranging from 0 to 59 receive an F.
Note the values in scores are defined as an input to the function. Do not overwrite these values in your code. Be sure to assign values to each element of the function output variable.
0 Kommentare
Antworten (1)
Parth Trehan
am 6 Apr. 2021
I have assumed that the expected output of the provided function is a character array. I hope the snippet provided below helps in this case.
function grade = assignGrade(scores)
grade(scores>=0) = 'F';
grade(scores>=60) = 'D';
grade(scores>=70) = 'C';
grade(scores>=80) = 'B';
grade(scores>=90) = 'A';
end
0 Kommentare
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!