Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Matlab code Grades and corresponding students\' GPA are saved in two variables n

ID: 1766115 • Letter: M

Question

Matlab code

Grades and corresponding students' GPA are saved in two variables named grades and gpa grades [31, 70, 92, 5, 47, 88, 81, 73, 51, 76, 80, 90, 55, 23, 43, 98, 36, 87, 22, 61, 19, 69, 26, 82, 89, 99, 71, 59, 49, 64] gpa [2.25, 2.05, 3.58, 1.64, 3.31, 3.91, 2.87, 2.92, 3.48, 3.53, 3.12, 2.48, 3.49, 3.21, 2.36, 3.93, 2.42, 3.20, 2.65, 3.35, 2.33, 3.33, 2.79 3.03, 3.41, 3.61, 3.91, 3.08, 2.36, 3.07] Show how to use logical and relational operators in MATLAB to .calculate the average of the grades. 2. find the number of students, whose grades are within 10 points of the average (average 3. check if there is any student who got the full score (100) 4. see the gpa of students, who passed the exam (scored 60 or higher) 5. calculate the average of gpa of students, who failed the exam (scored less than 60) 10)

Explanation / Answer

matlab code:

clc;

clear all;

close all;

grades=[31,70,92,5,47,88,81,73,51,76,80, 90,55,23,43,98,36,87,22,61,19,69,26,82,89,99,71,59,49,64];

gpa=[2.25 2.05 3.58 1.64 3.31 3.91 2.87 2.92 3.48 3.53 3.12 2.48 3.49 3.21 2.36 3.93 2.42 3.20 2.65 3.35 2.33 3.33 2.79 3.03 3.41 3.61 3.91 3.08 2.36 3.07];

n=length(grades);

m=length(gpa);

avg=mean(grades);%average of the grades

fprintf('average of the grades of the students %d is %f ',n,avg);

%------number of students whose grades within 10 points of the average

count=0;

for i=1:n

if grades(i)<=(avg+10) & grades(i)>=(avg-10)

count=count+1;

else

count=count;

end

end

fprintf('The number of students whose grades are within 10 points of the average are %d ',count);

%-------------students who got full marks

count1=0;

for i=1:n

if grades(i) == 100

count1=count1+1;

else

count1=count1;

end

end

if count1==0

disp('No student got full marks')

end

%--------------gpa of students who passed the exam

for i=1:n

if grades(i) >= 60

gpa1=gpa(i);

fprintf('gpa of student %d is %f and his grade is %d ',i,gpa(i),grades(i));

end

end

%--------------average gpa of students who failed in the exam

gpa2=0;

count3=0;

for i=1:n

if grades(i) <60

count3=count3+1;

gpa2=gpa2+gpa(i);

end

end

avg2=gpa2/count3;

fprintf('average gpa of students who failed in the exam is %f ',avg2);

Result:

average of the grades of the students 30 is 61.200000

The number of students whose grades are within 10 points of the average are 7

No student got full marks

gpa of student 2 is 2.050000 and his grade is 70

gpa of student 3 is 3.580000 and his grade is 92

gpa of student 6 is 3.910000 and his grade is 88

gpa of student 7 is 2.870000 and his grade is 81

gpa of student 8 is 2.920000 and his grade is 73

gpa of student 10 is 3.530000 and his grade is 76

gpa of student 11 is 3.120000 and his grade is 80

gpa of student 12 is 2.480000 and his grade is 90

gpa of student 16 is 3.930000 and his grade is 98

gpa of student 18 is 3.200000 and his grade is 87

gpa of student 20 is 3.350000 and his grade is 61

gpa of student 22 is 3.330000 and his grade is 69

gpa of student 24 is 3.030000 and his grade is 82

gpa of student 25 is 3.410000 and his grade is 89

gpa of student 26 is 3.610000 and his grade is 99

gpa of student 27 is 3.910000 and his grade is 71

gpa of student 30 is 3.070000 and his grade is 64

average gpa of students who failed in the exam is 2.720769