| |
Note, problems 2 through 5 build on one another. It is best to make a copy of the solution to the
previous problem to use as the working file for the following problem.
- Define a class named
Student that stores information about a
student (suprise, suprise!). In particular, store their first and last name,
their year of graduation, and their GPA.
- Write a program (i.e. in another class) with a
method called
displayStudent which takes a Student as a parameter, and
displays its contents in the following manner:
Name: Smith, John
Year: 1996
GPA : 3.76
Test this method by calling it from a main method which defines a
student whose data is as shown above.
- Add a method called
smarter
to the program above which compares two students and returns the
one with the higher GPA. Test it with an appropriate addition to the main method.
- Add a method called
valedictorian which takes an array of student records and a graduation year
and returns the location of the student with that graduation year with the highest GPA.
(Note, it should not make use of smarter from above.)
Modify main to declare, allocate, and initialize
the contents of an array of 5 student records (you make up the data in them). Have it print out
(using code("displayStudent")}) the information on the valedictorian for 1999.
- Write a method called
ITR
which takes an array of student records and a cutoff GPA and prints (using displayStudent)
the records of those students whose GPAs are below the cutoff.
Note that the method ITR does not return a value.
Call ITR from main after the call to valedictorian.
- Write a method called
ITRArray
which takes an array of student records and a cutoff GPA and
returns an array of
the records of those students whose GPAs are below the cutoff.
Note that this method does not display anything.
(This problem is a bit tricky. You will need to make one pass through the
given array to identify how many ITR'ing students there are, then allocate
an array that large, then make a second pass to copy the objects from the given array
to the returned array. Also note that you should not create new student records
to store in the returned array. Rather it should just contain references to the
same objects as contained in the given array.)
|