/* registrar.cpp retrieves a student's data from a file
 *  using their id #.
 * Input (file):     A sequence of Students
 * Input (keyboard): one or more student numbers
 * Output:           that student's data.
 **************************************************************/

#include <iostream.h>                      // cin, cout
#include <fstream.h>                       // ifstream, ofstream
#include <cassert>                         // assert()
#include <string>                          // string
#include <vector>                          // vector<T>
#include <algorithm>                       // find()
#include "Student.h"                       // Student
#include "MyVector.h"                      // Read()

int main()
{
  const string INPUT_FILE = "students.dat";
  
  cout << "This program provides an information retrieval system\n"
          "  by reading a series of student records from "
	<< '\'' << INPUT_FILE << '\''
	<< "\n  and then allowing retrieval of any student's data.\n";
  
  vector<Student> studentVec;
  Read(INPUT_FILE , studentVec);

  long studentID;                              // the student we seek
  vector<Student>::iterator position;          // position of the student
  
  for (;;)                                     // repeat:
  {
    cout << "\nEnter the ID # of a student (eof to quit): ";
    cin >> studentID;                         //  get the student
    
    if (cin.eof()) break;                     //  if finished, quit

    position = find(studentVec.begin(),        //  search
		    studentVec.end(),          //   the vector for
		    Student(studentID,         //   this student id #
			    "", "",            //   using placeholder
			    "", 0, 0));        //   arguments
    
    if (position != studentVec.end())          //   if found
      cout << endl << *position << endl;       //     display student
    else                                       //   otherwise, tell user
      cerr << "\nThere is no student with ID # "
	   << studentID  << ".\n";
  }
}

