// main.cpp -- main program, and driver, for the class Student

#include <iostream>

using namespace std;

#include "student.h"


int main()
{
  Student me("Ingargiola", "Giorgio", 80, 85, 90);
  
  cout << "I am: " << me << endl;
  cout << " with grade " << me.grade() << endl;
  
  enum {TABLESIZE=100};
  Student *table[TABLESIZE];
  
  // Read the content of student.txt into table
  int n = readStudentFile("students.txt", table, TABLESIZE);
  if (n < 0)
    {
      cout << "Failure in reading the students.txt data file" << endl;
      return 1;
    } else if (n == 0)
      {
	cout << "The Student data file is empty" << endl;
	return 0;
      }
  
  // Display the content of table
  printStudentTable(table, n);
  
  // Write to students.out the content of table
  if (writeStudentFile("students.out", table, n) < 0)
    cout << "Failure in writing the students.out data file" << endl;

  cout << endl << endl;

  // Sort the array, print, and save the table
  
  sortStudent(table, n);
  printStudentTable(table, n);
  if (writeStudentFile("sstudents.out", table, n) < 0)
    cout << "Failure in writing the sstudents.out data file" << endl;

  // Here we let the system deallocate the instances created with new.
  return 0;
}
