/* This file implements the operations on a Student.

-----------------------------------------------------------*/

#include "Student.h"

#include <iomanip.h>

/*----- Class constructor ----- */

/* To initialize a declaration of a Student object
      with individual values for the data elements.

   Precondition:  A Student object has been declared.
   Receive:       Strings FName (default "")
                     and LName (default "")
                  long integer SNumb (default 0)
                  Year object StuYear (default Freshman)
                  double Creds (default 0.0)
                     and GPA (default 0.0)
   Postcondition: The data members of this Student object have
                     been initialized to FName, LName, SNumb,
                     StuYear, Creds, and GPA, respectively.
---------------------------------------------------------------*/

Student::Student (const Strings& FName, const Strings& LName,
                  long SNumb, Year StuYear, double Creds,
                  double GPA)
{
   FirstName_ = FName;
   LastName_ = LName;
   StudentNumber_ = SNumb;
   StudentYear_ = StuYear;
   Credits_ = Creds;
   GPA_ = GPA;
}

// ... various function definitions omitted ...

/*----------------------------------------------------------
   This function inputs a Student from a stream.

   Receive:  In, the istream being read from
             InStu, the Student being filled with data
   Return:   InStu, filled with the input data
             In
------------------------------------------------------------*/

istream& operator>> (istream& In, Student& InStu)
{
  In >> InStu.StudentNumber_ >> InStu.FirstName_
     >> InStu.LastName_ >> InStu.StudentYear_
     >> InStu.Credits_ >> InStu.GPA_;

  return In;
}

/*----------------------------------------------------------
   This function outputs a Student to a stream.

   Receive:  Out, the ostream being written to
             OutStu, Student being written
   Output:   OutStu to OutFile
   Return:   Out
------------------------------------------------------------*/

ostream& operator<< (ostream& Out, const Student& OutStu)
{
  Out << setw(10) << OutStu.StudentNumber_ << '\t'
      << OutStu.FirstName_ << ' ' << OutStu.LastName_ << endl
      << setw(12) << OutStu.StudentYear_
      << setprecision(4)
      << setiosflags(ios::showpoint | ios::fixed)
      << setw(8) << OutStu.Credits_
      << setw(8) << OutStu.GPA_ << endl;

  return Out;
}

/*-------------------------------------------------------------
   These functions are some of the relational operators...
--------------------------------------------------------------*/

Boolean operator==(const Student& Left, const Student& Right)
{
  return Left.FirstName_ == Right.FirstName_ &&
         Left.LastName_ == Right.LastName_;
}

Boolean operator<(const Student& Left, const Student& Right)
{
  return ( Left.LastName_ < Right.LastName_ ) ||
         ( Left.LastName_ == Right.LastName_ &&
           Left.FirstName_ < Right.FirstName_ );
}

Boolean operator>(const Student& Left, const Student& Right)
{
  return ( Left.LastName_ > Right.LastName_ ) ||
         ( Left.LastName_ == Right.LastName_ &&
           Left.FirstName_ > Right.FirstName_ );
}

Boolean operator<=(const Student& Left, const Student& Right)
{
  return (Left == Right) || (Left < Right);
}

