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

Using MATLAB write a code for the following: Create a vector of structs to repre

ID: 3793936 • Letter: U

Question

Using MATLAB write a code for the following:

Create a vector of structs to represent a database in which a professor might store information pertaining to his/her students. Every element in the vector represents information about one particular student. For every student, the professor wants to store: - Name (a string) - University ID (Number) - Quiz scores (a vector of five quiz scores) The vector variable, which you should call student, might look like the following: Each element in the vector is a struct with three fields (name, id_no, quiz scores). For example, the third element of the above data structure could be defined as follows: >> student(3) = structfName', 'Tony, Romo', 'ld_No', 332, 'Quiz_Scores', [75 60 85 90 72)); Create a structure with at least 5 students (add two or more students to the above list of students). The professor would like to print the quiz average for each student. To accomplish this, create a function printAverage() that would take as input the student structure, calculate the averages, and print the results as follows: >> printAverage(student) Name Average Bob, Myers 76.4 Dez, Bryant 97.6 Tony, Romo 80.8 Submit the codes and the resulting output. Your function could make use of for loop, mean, fprintf.

Explanation / Answer

Matlab printAverage.m function

function printAverage(student)
N = length(student);% number of students
fprintf('Name Average ');% printing the table title
for k= 1:N
      % printing information of each student
      fprintf('%s %2.1f ',student(k).Name,mean(student(k).Quiz_Scores));
end
end

Matlab code to create data base of five student and calling printAverage.m function

student(1) = struct('Name','Eden, Hazard','Id_No',111 ,'Quiz_Scores',[100 95 0 87 100]);% Student 1
student(2) = struct('Name','Dez, Bryant','Id_No',123 ,'Quiz_Scores',[100 100 90 100 98]);% Student 2
student(3) = struct('Name','Tony, Romo','Id_No',332 ,'Quiz_Scores',[75 82 85 90 72]);% Student 3
student(4) = struct('Name','Sup, Hone','Id_No',143 ,'Quiz_Scores',[30 45 89 90 100]);% Student 4
student(5) = struct('Name','Zid, Lepz','Id_No',160 ,'Quiz_Scores',[100 80 90 70 50]);% Student 5
printAverage(student);% Calling function printAverage

Output

Name                Average
Eden, Hazard    76.4
Dez, Bryant         97.6
Tony, Romo       80.8
Sup, Hone           70.8
Zid, Lepz             78.0

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote