#pragma
#ifndef STUDENTSDEF
#define STUDENTSHEADERDEF
#include <string>
#include <iostream>
usingnamespace std;
class Student
{
private:
double mlibrary_Fine;
public:
string mName;
double mtuition_Fees;
//Default Constructor
Student();
//over-ridden constructor
Student(string, double, double);
//Copy constructor
Student(const Student&);
//Destructor
~Student();
//Assignment operator
Student& operator=(const Student&);
//To show the details of the student as output.
void showStudent();
//Method to calculate the total money.
double calculateTotal();
//Method to enter the details of the student.
void enterDetails();
/*The library fines owed by the students must be a nonnegative number. Enforce this by making a student’s library fines a private
member of the class. Write one method that allows the user to set this variable only to nonnegative values, and another method that
can be used to access this private variable. Both methods should be public members of the class.*/
//Method to set value for library fine
void SetLibraryFine();
//Method to view the library fine
void ViewFine();
//Friend function to pass library fine by reference
frienddouble* passLibraryFine(Student&);
};
//Default constructor
Student::Student()
{
mName = "John";
mlibrary_Fine = 0.0;
mtuition_Fees = 0.0;
}
//Over-ridden constructor
Student::Student(string Name, double fines, double fees)
{
mName = Name;
mlibrary_Fine = fines;
mtuition_Fees = fees;
}
//Copy Constructor
Student::Student(const Student& otherStudent)
{
Student A;
mName = otherStudent.mName;
mlibrary_Fine = otherStudent.mlibrary_Fine;
mtuition_Fees = otherStudent.mtuition_Fees;
}
//Overloading the assignment operator.
Student& Student::operator=(const Student& anotherStudent)
{
mName = anotherStudent.mName;
mlibrary_Fine = anotherStudent.mlibrary_Fine;
mtuition_Fees = anotherStudent.mtuition_Fees;
return *this;
}
//Destructor
Student::~Student()
{
}
//Method to show details of the student.
void Student::showStudent()
{
cout << "Name of student = "<< mName << endl;
cout << "Library Fines = " << mlibrary_Fine << endl;
cout << "Fees = " << mtuition_Fees << endl;
}
//Method to calculate the total money owed by the student.
double Student::calculateTotal()
{
double total;
total = mlibrary_Fine + mtuition_Fees;
return total;
}
//Method to change the member variables of the student object.
void Student::enterDetails()
{
cout << "What is the name of the student?" << endl;
getline(cin, mName);
cout << "What is the total fines for the student?" << endl;
cin >> mlibrary_Fine;
cout << "What are the total fees for the student ?" << endl;
cin >> mtuition_Fees;
}
void Student::SetLibraryFine()
{
do
{
cout << "What is the value for the library fine? Ensure it isn't a negative value " << endl;
cin >> mlibrary_Fine;
if (mlibrary_Fine <= 0)
{
cout << "You entered a negative value, re-enter a positive value " << endl;
cin >> mlibrary_Fine;
}
} while (mlibrary_Fine <= 0);
cout << "You have set the value of the fine to " << mlibrary_Fine << endl;
}
void Student::ViewFine()
{
cout << "The total value of the fines is " << mlibrary_Fine << endl;
}
/*3. Students at the university are either graduate students or undergraduate students. All undergraduate students
are full-time students. Graduate students may be fulltime students or part-time students. Derive a class of graduate
students from the class of students that you have already written with an additional member variable that stores
whether the student is full-time or part-time.*/
class GraduateStudent : public Student
{
public:
char time;
GraduateStudent();
GraduateStudent(char, string, double);
/*4. Graduate students do not pay tuition fees. Use polymorphism to write a method that calculates the
total money owed by a graduate student. This will require the method for calculating the total money owed
to be a virtual function of the parent class.*/
virtualdouble calculateTotal(Student&);
frienddouble* passLibraryFine(Student&);
}
GraduateStudent::GraduateStudent()
{
time = 'N';
mName = "unspecified";
}
GraduateStudent::GraduateStudent(char t, string Nm, double f)
{
time = t;
mName = Nm;
mtuition_Fees = f;
}
double GraduateStudent::calculateTotal(Student& Std)
{
double total = 0.0;
double fine = *passLibraryFine(Std);
total = total + fine;
return total;
}
double* passLibraryFine(Student& Std)
{
double* p_fine = &Std.mlibrary_Fine;
return p_fine;
}
#endif