Computer Science 161
Exercise set #10
Due: Various
I. search.cpp
The best way to start this project is to copy class.cpp to
search.cpp, and simply add some code to the back of search.cpp.
Extend class.cpp by adding code so that, after the class list has
been printed, the program asks the user for the name of a student to
search for, and then uses a binary search to search for that student
in the class. If the student is found in the class, the details of
that student should be printed. If the student is not found in the
class, an error message should be printed.
Important note: Please do not add features to assigned
problems. Asking the user if they want to do this again, for
example, will cause problems with my grading program and may result
in delay in getting your program back to you (or its return with a
request to correct and resubmit).
Due: Thursday, April 29 (Poincare's birthday!)
II. object.cpp
Using the code in search.cpp, create a new program called
object.cpp with the following:
- Create an object for student with elements and methods
as follows
- Public
- Print all of the information about a student
- Get the student's name
- Get the student's class average
- Get the student's grade
- Constructors
- Default constructor: initialize everything
- Other constructor (which you will actually use) with
arguments containing the student's name, quiz and exam
scores, and which will calculate the student's class
average and letter grade
- Private
- Student's name, quiz scores, exam scores, class average
and grade
- Using the student class, create a ClassRec object with
elements and methods as follows
- Public
- Class report (same as the printed report in search.cpp)
- Search (given a student name, find and print (using the
print method of the student class) information
about the student, and print an error message otherwise).
- Constructors
- Default constructor (simply set the class size to
zero)
- Other constructor (which you will actually use):
Accept the name of a file (a string) as input, and load
the array of student records (see below). In testing,
this will be the file "class.dat", but the constructor
should accept this as a parameter.
- Private
- All implementation variables: class size (an integer),
an array (30 max) of student objects.
- A sort routine to be used by the constructor (sort after
all records have been read).
- Finally, write a test driver for your objects (main) which
will
- Construct a class object using the file "class.dat" (the
same file used for search.cpp)
- Print a report of the class using the class report
method of the ClassRec class.
- Ask the user for a name to search for, search the class for
that student, printing the information about that student
(using the Print method of the student class).
Due: Wednesday, May 5 (Last day of classes!)
Please let me know if you have any questions. Many thanks!