
//
//  File: main.C
//
//  This is a simple program to demonstrate the use of STL maps.
//  See the lab description for more details.
//


#ifdef GNU
#include <iostream.h>
#define std
#else
#include <iostream>
#endif

#include "student.h"
#include <map> 


int
main()
{ 
  std::map < std::string, StudentRecord, std::less<std::string> > students;

  //
  //  A. Inserting into a map using the [] operator.
  //
  students["Stewart"] = StudentRecord( "stewac", "freshman", "12234567890" );
  students["Smith"] = StudentRecord( "smithm", "junior", "29384756102",
					 1000.0, 0, 0 );
  std::cout << students["Smith"] << "\n";
  std::cout << students["Jones"] << "\n" << std::endl;

  //
  //  B. Inserting using the "insert" operator.  The syntax gets a bit ugly...
  //
  std::pair< std::string, StudentRecord >
    stu_value( "Anderson", StudentRecord("anders", "senior", "12121212121" ));
  std::pair< std::map<std::string, StudentRecord, std::less<std::string> >::iterator,bool >
    insert_result = students.insert( stu_value );
  if ( insert_result.second ) {
    std::cout << "Successful." << std::endl;
    //  C. 
  }
  else
    std::cout << "Unsuccessful." << std::endl;

  //
  // D.
  //
  typedef std::map< std::string, StudentRecord, std::less<std::string> > StudentMap;
  typedef StudentMap::value_type StudentPair;

  // 
  // E.
  //
  students["Stewart"].add_grades( 4, 16.0 );
  std::cout << "Stewart's gpa is now " << students["Stewart"].gpa()
	        << std::endl;
  students["Barnes"].pay( 9000 );
  std::cout << "Barnes has paid $" << students["Barnes"].get_tuition()
	    << "  in tuition.\nHer student id is  "
	    << students["Barnes"].get_id() << std::endl;

  return 0; 
}


  
