/* This program uses the data file 'student.dat' and creates a file
   'deans.dat' containing all students making the dean's list.

   Input(student.dat):  A sequence of student data records
   Output(deans.dat):   All student IDs whose GPA >= 3.0
------------------------------------------------------------------*/

#include <iostream.h>
#include <fstream.h>
#include <stdlib.h>

#include "Student.h"

int main(void)
{
   const double
      DeanListCutoff = 3.0,                 // min. Dean's List GPA
      FullTime = 9.0;                       // min. full-time credits

   cout << "\nThis program reads the records in the file "
        << "'student.dat',"
        << "\n\tand displays the dean's list in the file "
        << "'deans.dat'.\n";

   fstream
      InStream("student.dat", ios::in),     // open input file
      OutStream("deans.dat", ios::out);     // open output file

   if (InStream.fail())                     // check for success
   {
      cerr << "\n*** Unable to open 'student.dat' for input!\n";
      exit (-1);
   }
   else if (OutStream.fail())
   {
      cerr << "\n*** Unable to open 'dean.dat' for output!\n";
      exit (-1);
   }

   OutStream << "\n\tThe Dean's List\n\n";  // print a heading

   Student
      Stu;                                  // Student being processed

   InStream >> Stu;                         // input first Student

   while (!InStream.eof())                  // while not end-of-file:
   {
      if ((Stu.GPA() >= DeanListCutoff) &&  //   if high-enough GPA
            (Stu.Credits() >= FullTime))    //     and full-time,
         OutStream << Stu << endl;          //     output the Student
      InStream >> Stu;                      //   input next Student
   }

   InStream.close();                        // close the files
   OutStream.close();

   return 0;
}

