// student.h -- Declaration of the Student class

#ifndef STUDENT_H_ 
#define STUDENT_H_

#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

class Student {
   int mid;
   int final;
   int hmwks;
   string lname;
   string fname;
public:
   // Constructor for Student: just default values
   Student();
   
   // Constructor for Student: specific initialization for the fields
   Student(char flname[], char ffname[], int fmid, int ffinal, int fhmwks);
   
   // Read values of a Student from a specified istream
   friend istream& operator>>(istream& fin, Student &y)
     {
       fin >> y.lname >> y.fname >> y.mid >> y.final >> y.hmwks;
	   return fin;
     }
   
   // Write values of a Student to a specified ostream
   friend ostream& operator<<(ostream& fout, const Student &y)
     {
       fout << setiosflags(ios::left) << y.lname << "\t\t"
	    << y.fname << "\t\t"
	    << setw(9) << setiosflags(ios::right) << y.mid   
	    << setw(9) << y.final 
	    << setw(9) << y.hmwks;
	   return fout;
     }
   
   // Compute grade of a student 
   double grade() const;
   
   // Comparison operator for grades
   friend int operator<(const Student &x, const Student &y)
     {  
       return (0.4*x.final+0.4*x.hmwks+0.2*x.mid 
	       < 0.4*y.final+0.4*y.hmwks+0.2*y.mid);
     }
};

// Help functions for Student

// It prints out to the standard output the first
// n records of a
void printStudentTable(const Student a[], int n);


// Reads a file filein of students into array a with at most n records
// and returns the number of records actually read (-1 if there is no
// such file)
int readStudentFile(const char *filein, Student a[], int n);

// Writes a file fileout of students record from the first n
// elements of the array a of Students. It returns 0 in case of success,
// -1 if failure
int writeStudentFile(const char *fileout, const Student a[], int n);

#endif
