Lab 11
Version 1

 

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.

  1. 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.

  2. 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.

  3. 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.

  4. 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.

  5. 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.

  6. 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.)

Last modified August 28 for Fall 99 cs5 by fleck@cs.hmc.edu


This page copyright ©1998 by Joshua S. Hodas. It was built with Frontier on a Macintosh . Last rebuilt on Sat, Nov 14, 1998 at 11:40:00 AM.
http://www.cs.hmc.edu/~hodas/courses/cs5/week_11/lab.html