function  struct_demo()
%---------------------------------------------------------------
%       USAGE: Struct_demo()
%
%      AUTHOR: Col David S. Gibson       DATE: 13 Oct 04
%    MODIFIED: Dr. Wayne Brown           DATE: 30 Sep 05
%
% DESCRIPTION: This program demonstrates creation and use of a
%              structure array to hold student information.
%
%      INPUTS: None
%
%     OUTPUTS: None
%
%  REFERENCES: None
%---------------------------------------------------------------

% Clear screen and display intro

clc()

fprintf('CS211 - Structure array demo\n\n')
fprintf('You will be asked to enter the following data for students:\n')
fprintf('  - first name\n')
fprintf('  - last name\n')
fprintf('  - test score\n\n');

% Get the number of students

Num_students = input('How many students are there (keep it small!): ');

% Allocate a structure array large enough to hold all the data

Student(Num_students) = struct('First', [], 'Last', [], 'Score', []);

% get info for each student and place it in the student struct array

for count = 1 : Num_students
    fprintf('Please enter info for student %d:\n', count)
    Student(count).first = input('Enter first name: ', 's');
    Student(count).last  = input(' Enter last name: ', 's');
    Student(count).score = input('Enter test score: ');
end

% display the values of all elements of the student struct array

fprintf('\n')
for count = 1 : length(Student)
    fprintf('%s %s earned a score of %d\n', Student(count).first, ...
            Student(count).last, Student(count).score)
end

% display the average score of all students

fprintf('\nThe average score is %.2f.\n', mean([Student.score]))

