% -----------------------------------------------------
% structures4.m
% -----------------------------------------------------
% Create a structure - engr1234 with the following fields
% lastname - last name of a student
% firstname - first name of a student
% attendance - a boolean variable (1 or 0) indicating 
%           if student is still coming to class or not
% grade - student's grade as a percentage 
% -----------------------------------------------------
% Notes: create a structure array using a function
% Calculate the class average.
% -----------------------------------------------------
% Copyright and license details available at matlabmarina.com
%------------------------------------------------------
clear;
clc;

% building a structure array of students
engr1234(1)=makeengr1234('Jones','David',1,90);
engr1234(2)=makeengr1234('Gommes','Daniel',0,50);
engr1234(3)=makeengr1234('Louise','Mary',1,70);

% number of students in class
n = length(engr1234);

% calculate the class average
classGrds = zeros(1, n);
for k = 1 : 1 : n
    classGrds(k)=engr1234(k).grade;             
end

classAvg = mean(classGrds);

fprintf('The class average is %0.2f\n', classAvg);