package Student;  # Definition of an Object of type Student

@student_data = qw(Name ID GPA ); # Name the fields

### The subroutines "new" and "initialize" for the Constructor

sub new   
{
	print "new: @_ \n";
        my $class_name = shift;		# Gets class name from parmlist

        my $recref = {};		# Creates reference to object

        bless $recref, $class_name;     # Associates reference with class

        $recref -> initialize(@_);      # Call local initialize subroutine
					#   passing rest of parmlist

        return $recref;                 # Explicit return of value of $recref
}

sub initialize
{
	print "initialize: @_ \n";
        my $stu_ref = shift;    # Receive an object reference as 1st param
        my %parms = @_;         # Get passed parameters from the call to "new"

        # Change hash reference for key with supplied value, or assign default
        $stu_ref -> {'Name'}        = $parms{'Name'}    ||   "NOBODY";
        $stu_ref -> {'ID'}          = $parms{'ID'}      ||   "NO_ID";
        $stu_ref -> {'GPA'}         = $parms{'GPA'}     ||    0;
}


sub PrintRec  # Print a student record
{
      
	print "PrintRec: @_ \n";
        my $instance = shift;  # Figure out who I am

        for(@student_data)     # Go through all fields
        {
                print "$_: ", $instance -> {$_}, "\n"; # Print key and value
        }
}


sub Modify  #  Modify student Record
{
	print "Modify: @_ \n";
        my $instance = shift; # Figure out who I am
        my %parms = @_;       # Make hash out of rest of parm list

	# Step through all keys in parm list
        for(keys %parms)  
        {
                $instance -> {$_} = $parms{$_}; # Replace with new value 
        }
}



1;		# Return 1 to say package loaded correctly

