Write a MATLAB script to process student grades. Example execution: Enter studen
ID: 3695445 • Letter: W
Question
Write a MATLAB script to process student grades. Example execution:
Enter student lab average (negative to end):70
Enter student program average:80
Enter student lab average (negative to end):70
Enter student program average:90
Enter student lab average (negative to end):85
Enter student program average:75
Enter student lab average (negative to end):70
Enter student program average:75
Enter student lab average (negative to end):-1
Number of students: 4
Average for all students: 76.875000
Student averages above the class average:
student: 2 average: 80.000000
student: 3 average: 80.000000
Requirements:
1. Insert one comment at the top of the file with your name and the name and date of the assignment (for example, "Jane Doe: Lab Exam 2: April 30 2015"). You may include additional comments in the code if you wish, but this is not required for the exam.
2. You must match the output shown above
3. Have a clear statement at the start your script to clear previous variables.
4. After grades are put into the array, process the matrix with a loop to display students with an average above the class average. The student number displayed is the index of that student in the array
5. Read the grades into a two dimensional array. Each row contains:
Column 1: student lab average
Column 2: student program average
Column 3: student class average. Labs and programs averages each count 50% towards the class average.
Explanation / Answer
% initializing an array with zeros for maximum of 10 students
m=[0 0 0; 0 0 0; 0 0 0; 0 0 0; 0 0 0; 0 0 0; 0 0 0; 0 0 0; 0 0 0; 0 0 0];
% variable to check the negativity of lab averagae of the student
n=1;
% for loop to read the values from user
for a=1:20
% prompting user to enter the lab average
m(a,1)=input('Enter student lab average (negative to end):');
% storing lab average into variable n
n=m(a,1);
% checking if value n is negative or not
if n<0
%if negative breaking the loop
break;
end
% reading student program average into second coloumn
m(a,2)=input('Enter student program average:');
% calculating average
m(a,3)=(n+m(a,2))/2;
end
% printing number of students
fprintf('number of students is:%d ',c-1);
avg=0;
% for loop to calculate all students average
for n=1:20
% summing to calculate avg for all students
avg=avg+m(n,3)+m(n,1)+m(n,2);
end
% formula to calculate average for all students
avg=avg/3;
fprintf('average for all students %d',avg);
fprintf('students above the class average:')
% for loop for checking class avg is above of students average
for k=1:20
if avg>m(k,3)
fprintf('student%d : average %d',k,m(k,3));
end
end
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.