Use relational and logical operators. Do NOT use the find function. Amy and John
ID: 3799123 • Letter: U
Question
Use relational and logical operators. Do NOT use the find function. Amy and John took the following courses: Math, Hist, Physics, Eng, Chem, Bio Amy's grades in the courses are: 190 45 80 72 64 53]. John's grades in the courses are: [40 45 85 70 53 77]. Write a script file to do the following: (a) Create arrays for the grades and courses (use the built-in char function). Display Amy's grades that are above or equal to 80 and the courses she got them. Display the courses where Amy and John got the same grades. In how many and in which courses did Amy get better grades than John? Display both their grades. Write a script file to repeat Problem l(b)R(d) using the find function. Consider the same courses and grades as in Problem 1. Use relational operators and logical operators/functions where applicable. Write a script file to do the following (a) Find and display Amy's grade that are neither below 45 nor above 72. Display Amy's grades that are between 65 and 80 excluding 65 and 80. Find and display Amy's grades that are NOT between 65 and 80 (d) Find and display the courses where John's and Amy's grades are above 70 (e) Find and display the courses where either ONLY John's or ONLY Amy's grades are above 70 (D Display the courses where neither John's nor Amy's grades are aboveExplanation / Answer
1.b)
course = {'Math','History','Physics','Eng','Chem','Bio'};
amygrades = [90 45 80 72 64 53];
johngrades = [40 45 85 70 53 77];
for i=1:length(amygrades)
elm = amygrades(i);
if elm >= 80
disp(elm);
disp(course(i));
end;
end;
90
Math
80 Physics
1.c
course = {'Math','History','Physics','Eng','Chem','Bio'};
amygrades = [90 45 80 72 64 53];
johngrades = [40 45 85 70 53 77];
for i=1:length(amygrades)
for j=1:length(johngrades)
elm = amygrades(i);
elm1 = johngrades(j);
if elm==elm1 & i==j
disp(course(i));
end;
end
end;
History
1.d
course = {'Math','History','Physics','Eng','Chem','Bio'};
amygrades = [90 45 80 72 64 53];
johngrades = [40 45 85 70 53 77];
count=0;
for i=1:length(amygrades)
for j=1:length(johngrades)
elm = amygrades(i);
elm1 = johngrades(j);
if elm>elm1 && i==j
count=count+1;
disp(elm);
disp(elm1);
disp(course(i));
end;
end
end;
disp(count);
90
40
Math
72
70
Eng
64
53
Chem
Problem 3:
3.a
course = {'Math','History','Physics','Eng','Chem','Bio'};
amygrades = [90 45 80 72 64 53];
johngrades = [40 45 85 70 53 77];
count=0;
for i=1:length(amygrades)
elm = amygrades(i);
if elm>45 && elm<72
disp(elm);
end;
end;
64
53
3.b
course = {'Math','History','Physics','Eng','Chem','Bio'};
amygrades = [90 45 80 72 64 53];
johngrades = [40 45 85 70 53 77];
count=0;
for i=1:length(amygrades)
elm = amygrades(i);
if elm>65 && elm<80
disp(elm);
end;
end;
72
3.c)
course = {'Math','History','Physics','Eng','Chem','Bio'};
amygrades = [90 45 80 72 64 53];
johngrades = [40 45 85 70 53 77];
count=0;
for i=1:length(amygrades)
elm = amygrades(i);
if !(elm>65 && elm<80)
disp(elm);
end;
end;
90
45
80
64
53
3.d)
course = {'Math','History','Physics','Eng','Chem','Bio'};
amygrades = [90 45 80 72 64 53];
johngrades = [40 45 85 70 53 77];
count=0;
disp("Amy's course greater than 70");
for i=1:length(amygrades)
elm = amygrades(i);
if elm>70
disp(course(i));
end;
end;
disp("John's course greater than 70");
for i=1:length(johngrades)
elm = johngrades(i);
if elm>70
disp(course(i));
end;
end;
}
Amy's course greater than 70
Math
Physics
Eng
John's course greater than 70
Physics
Bio
3.e)
course = {'Math','History','Physics','Eng','Chem','Bio'};
amygrades = [90 45 80 72 64 53];
johngrades = [40 45 85 70 53 77];
for i=1:length(amygrades)
for j=1:length(johngrades)
elm = amygrades(i);
elm1 = johngrades(j);
if (elm>70 && elm1<70 && i==j) || (elm<70 && elm1>70 && i==j)
disp(course(i));
end;
end
end;
Math
Bio
3.f)
course = {'Math','History','Physics','Eng','Chem','Bio'};
amygrades = [90 45 80 72 64 53];
johngrades = [40 45 85 70 53 77];
for i=1:length(amygrades)
for j=1:length(johngrades)
elm = amygrades(i);
elm1 = johngrades(j);
if (elm<70 && elm1<70 && i==j)
disp(course(i));
end;
end
end;
History
chem
Problem 2, i am not able to use find function.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.