% -----------------------------------------------------
% structures3.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
% -----------------------------------------------------
% 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);

% display the 2nd students information
disp(engr1234(2));
% display the lastnames
n = length(engr1234);
fprintf('The student''s last names : \n');
for k = 1 : 1 : n
    disp(engr1234(k).lastname);
end

% display the fieldnames in the structure
fldNames = fieldnames(engr1234);

fprintf('\n\nThe field names : \n');
for k = 1 : 1 : n
    disp(fldNames{k}); %  '{}' requires knowledge of cell arrays
end


