CS 12 - Lab 10
In this lab you are going to use class inheritance. You will need the
Student class from last week's lab (but not the SSN
class).
Note that the program must be written, compiled, and executed under Linux.
Changes to Student Class
First of all, make the following changes to the Student class from
last week's lab:
- Change the social security number from an object of type SSN
to a char *. This way, you will not need the SSN class,
which will simplify the code. This means you should no longer
include ssn.h in any of your files.
- Modify the Student class constructor so it no longer uses a
member initializer to initialize the social security number (since
the SSN class is no longer being used). Instead, just set
the social security number to an empty string, same as for the first
name and the last name.
- Modify the setData method to use strdup to save the
social security number passed in. Note that you do not have to
validate the social security number; you can assume it is valid.
- Modify the print method to use the new social security number
variable when printing out the data.
- Add a second class constructor that takes the same parameters as
setData, namely a first name, last name, GPA, and social
security number. The constructor should call setData to
set the data. If setData returns false, meaning that the
GPA is not valid, the constructor should initialize the member data
variables to "empty" values, same as the original constructor.
The UCRStudent Class
Write a class called UCRStudent that maintains information about a
UCR student. This class should be publicly inherited from the Student
class and contain the following additional data members:
- Year The student's year (1, 2, 3, 4, 5, etc., where 1 means a
freshman, 2 means a sophomore, and so on. If the student
has graduated, the year should be set to 0.)
- Financial Status The student's current financial status:
up-to-date, late, or lapsed. Use an enumeration
(enum) to create a constant for each status.
- Academic Probation A flag (of type bool) specifying
whether the student is currently on academic probation
or not.
The UCRStudent class should contain two constructors.
The first constructor takes no arguments and simply initializes the member
data variables: the year should be set to 1, the financial status to
up-to-date, and the academic probation flag to false. The other (inherited)
member variables should be set to "empty" values. Note that the Student
no-argument constructor does this automatically, so you do not have to add any
code to do it.
The second constructor should have 6 parameters. These parameters are
exactly the same as those passed to the setData method described
below. This constructor should use a member initializer to initialize
the inherited member data (i.e. the first name, last name, GPA, and social
security number), then set the non-inherited data members (i.e. the year and
financial status) from the remaining parameters.
The class should also define the following methods:
- bool setData( char *fname, char *lname, double GPA, char *ssn,
int year, int financial_status );
- void print();
- void setAcademicStatusByGPA();
Details
Create a C++ header file, ucrstudent.h, and place your definition for
the UCR student class in it. Also, create a C++ file, ucrstudent.cc,
and put the implementation for the class in it.
Following are descriptions of the needed methods:
bool setData( char *fname, char *lname, double GPA, char *ssn,
int year, int financial_status )
This class method is passed information needed to set the data members.
To set the first name, last name, GPA, and social security number, the
setData() method in the Student class should be called. If
there is an error (the GPA is less than 0.0, the year is less than 0, or the
financial status is not valid), the method should do nothing but return
false, else it should set the data members and return true.
(You can assume the parameters other than GPA, year, and financial status
are always valid.)
Notice that no value is passed for the academic status. The method should
call the setAcademicStatusByGPA method, after setting the GPA,
to set this value. The setAcademicStatusByGPA method is described
below.
void print()
This class method prints all of the information about the UCR student. Call
the print method in the Student class to print the first name,
last name, GPA, and social security number.
If the year is 0, the method should print that the student has graduated,
else it should show the year (1, 2, etc.). For the financial and academic
status, the method should print, in English, the student's status.
void setAcademicStatusByGPA()
This should be a private method that sets the academic status flag
by comparing the GPA data member to 3.0. If the GPA is less than 3.0,
the flag should be set to true, else it should be set to false.
There is a problem with writing this method, namely that the GPA is a
private member variable of the Student class, so it can not be
accessed from the UCR student class. Therefore, modify the Student
class by making its private section protected instead.
Main Program
Place your main program in the file main.cc. The function should
create 2 UCRStudent objects. The first should be created by calling
the no-argument constructor, the second by calling the constructor that takes
arguments. Note that for both UCR students, you should prompt the user for
all of the information needed for the student. Make sure to print the
information for both students as well.
Compiling With a Makefile
Copy your makefile from lab9 and modify it to compile your lab10
assignment.
Grading
When you have finished the program, your TA will grade it. To receive full
credit, your TA will check all of the following:
- The program works correctly
- You created the .cc files and .h files as specified
- You have a makefile to compile your program
- The program is properly commented. Each function should have a comment
at the beginning explaining what it does, what each of its parameters
are for, and the return value (if any). In addition, the code within
each function should have comments as appropriate to explain how it
works.
- The program is well formatted (i.e. style). For example, you should
be consistent with your indenting in the program.
At the end of this week, the TA will be submitting your lab grades for the
quarter. Therefore, you should verify that your TA has all of your scores
and that they are correct. Any discrepencies should be dealt with by you
and the TA prior to the TA submitting the lab grades.