% -----------------------------------------------------
% structures2.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: structure array with information for 3 students
% -----------------------------------------------------
% Copyright and license details available at matlabmarina.com
%------------------------------------------------------

clear;
clc;

% building a structure array of students one at a time
engr1234(1).lastname = 'Jones';
engr1234(1).firstname = 'David';
engr1234(1).attendance = 1;
engr1234(1).grade = 90;

engr1234(2).lastname = 'Gommes';
engr1234(2).firstname = 'Daniel';
engr1234(2).attendance = 0;
engr1234(2).grade = 50;

engr1234(3).lastname = 'Louise';
engr1234(3).firstname = 'Mary';
engr1234(3).attendance = 1;
engr1234(3).grade = 70;

% display the 2nd students information
disp(engr1234(2));

% display the lastnames of the students
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 of students
fldNames = fieldnames(engr1234);

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


