Write a user-defined MATLAB function that calculates a student’s final grade in
ID: 3761695 • Letter: W
Question
Write a user-defined MATLAB function that calculates a student’s final grade in a course using the scores from three midterm exams, a final exam, and six homework assignments. The midterms are graded on a scale from 0 to 100 and each accounts for 15% of the course grade. The final exam is graded on a scale from 0 to 100 and accounts for 40% of the course grade. The six homework assignments are each graded on a scale from 0 to 10. The homework assignment with the lowest grade is dropped, and the average of the remaining assignments accounts for 15% of the course grade. In addition, the following adjustment is made when the grade is calculated. If the average grade for the three midterms is higher than the grade for the final exam, then the grade of the final exam is not used and the average grade of the three midterms accounts for 85% of the course grade. The program calculates a course grade that is a number between 0 and 100. For the function name and arguments use g = fgrade(R). The input argument R is a matrix in which the elements in each row are the grades of one student. The first six columns are the homework grades (numbers between 0 and 10), the next three columns are the midterm grades (numbers between 0 and 100), and the last column is the final exam grade (a number between 0 and 100). The output from the function, g, is a column vector with the student grades for the course. Each row has the course grade of the student with the grades in the corresponding row of the matrix R. The function can be used to calculate the grades of any number of students. For one student the matrix R has one row. Use the function for the following cases: (a) Use the Command Window to calculate the course grade of one student with the following grades: 8, 9, 6, 10, 9, 7, 76, 86, 91, 80. (b) Write a program in a script file. The program asks the user to enter the students’ grades in an array (one student per row). The program then calculates the course grades by using the function fgrade. Run the script file in the Command Window to calculate the grades of the following four students: Student A: 7, 10, 6, 9, 10, 9, 91, 71, 81, 88. Student B: 5, 5, 6, 1, 8, 6, 59, 72, 66, 59. Student C: 6, 8, 10, 4, 5, 9, 72, 78, 84 78. Student D: 7, 7, 8, 8, 9, 8, 83, 82, 81 84.
Explanation / Answer
function g = fgrade(R)
[x,y] = size(R);
g = zeros(1,x);
for i=1:x
quiz = sort(R(i,1:6,:));
g(i,1) = 0.15*(sum(quiz) - quiz(1,1));
avg = sum(R(i,7:9,:))/3;
if (avg > R(i,10))
g(i,1) = g(i,1) + 0.85*avg;
else
g(i,1) = g(i,1) + 0.85*R(i,10);
end
end
end
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.