1. (4 pts.) The following algorithm is designed to determine a grade for a cours
ID: 3880255 • Letter: 1
Question
1. (4 pts.) The following algorithm is designed to determine a grade for a course that consists of quizzes, homework, and a final exam: Step 1: Input course number and name Step 2: Input weighting factors for quizzes (WQ), homework (WH), and the final exam (WF) Step 3: Input quiz grades and determine an average quiz grade (AQ) Step 4: Input homework grades and determine an average homework grade (AH) Step 5: If this course has a final grade, continue to step 6. If not, go to step 9. Step 6: Input final exam grade (FE) Step 7: Determine average grade AG according to 100% Step 8: Go to step 10 Step 9: Determine average grade AG according to AG = 100% Step 10: Print out course number, name, and average grade. Step 11: Terminate computation a. Write and document a structured MATLAB user-defined function (m file) based on this algorithm. Include COMMENTS in your script that clearly describe each block of your code. Test your code using the following input data: WQ-35, WH-35, WF = 30 quizzes-98, 85, 90, 65, 99, homeworks = 95, 90, 87, 100, 92, 77, and final 92Explanation / Answer
Matlab Script:--
function stu_gade = struct_grade()
clear;
clc;
%define structure
stu_gade = struct('C_num',0,'C_name',"null",'quizzes',0,'homework',0,'final_exam',0,'Quizgrade',0,'avg_homework',0,'final_examgrade',0,'avg_grade',0);
stu_gade %display empty structure
num='enter exam number: ';
name='enter exam name: ';
num=input(num); %ask user to enter exam number
name=input(name); %ask user to enter exam name
stu_gade.C_num=num; %assign number to struct num field
stu_gade.C_name=name; %assign name to struct name field
WQ_WH_WF='enter weighting factors for WQ,WH and WF: ';
[WQ_WH_WF]=input(WQ_WH_WF); %askuser to read WQ,WH and WF
WQ=WQ_WH_WF(1);
WH=WQ_WH_WF(2);
WF=WQ_WH_WF(3);
%assign WQ,WH and WF to corsponding struct fields
stu_gade.quizzes=WQ;
stu_gade.homework=WH;
stu_gade.final_exam=WF;
prompt1='Input Quizz grades: ';
Qgrade=input(prompt1); %ask enter quiz marks
AQ=mean(Qgrade); %average
stu_gade.Quizgrade=AQ; %assign to corsponding struct fields
prompt2='Input Homework grades: ';
Hgrade=input(prompt2); %ask enter home work marks
AH=mean(Hgrade); %average
stu_gade.avg_homework=AH; %assign to corsponding struct fields
AG=0;
choice='Course has final grade? Y/N: ';
c=input(choice); %ask user to has EF or not
if c=='Y' %if has
prompt3='Enter final exam grade: ';
FE=input(prompt3); %ask to enter EF
stu_gade.final_examgrade=FE;
AG=(WQ.*AQ+WH.*AH+WF.*FE)./(WQ+WH+WF).*100; %calculate AG
else
AG=(WQ.*AQ+WH.*AH)/(WQ+WH).*100; %calculate AGwith out EF
end
stu_gade.avg_grade=AG;
%print results
fprintf('Course number %d, course name %s and average grade is %f',stu_gade.C_num,stu_gade.C_name,stu_gade.avg_grade)
end
Output:--
stu_gade =
struct with fields:
C_num: 0
C_name: "null"
quizzes: 0
homework: 0
final_exam: 0
Quizgrade: 0
avg_homework: 0
final_examgrade: 0
avg_grade: 0
enter exam number: 12
enter exam name: 'mat'
enter weighting factors for WQ,WH and WF: [35 35 30]
Input Quizz grades: [98 85 90 65 99]
Input Homework grades: [95 90 87 100 92 77]
Course has final grade? Y/N: 'Y'
Enter final exam grade: 92
Course number 12, course name mat and average grade is 8974.833333
ans =
struct with fields:
C_num: 12
C_name: 'mat'
quizzes: 35
homework: 35
final_exam: 30
Quizgrade: 87.4000
avg_homework: 90.1667
final_examgrade: 92
avg_grade: 8.9748e+03
>>
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.