//*************************************************************
 
//     File: highestAvg.cpp
//     Name: DMN    
//     Project or HW or Lab name: Notes example
/*     Description: - Given a list of midn names/alpha codes followed                  
                      by a list of grades followed by a ;  
-        Print out the name of the student with the highest average   
   (and the average). 
                                      
        - Input format is demonstrated in this example: 
        
               John Jeffery Jones m090101 85, 95, 22, 54; 
               Sandra Smith m090201 99, 98; 
               Xavier Xenon Jr m090400 78, 80, 82, 84, 86, 88, 90; 
 
  For this input, program would output 
           “Sandra Smith had the highest average, a 98.5”. 
*/
//*********************************************************************
 
 
 
 
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
 
 
int main()
{
 string name;
 string tempStr;
 char tempChar;
 int tempInt;
 int gradeSum;
 double highestAvg = 0.0;
 string highestName = " ";
 int count;
 double tempAvg = 0.0; 
 
    ifstream fin("data.txt"); // see if file is really there
        
        if(!fin)
        {
               cout << "File not found ";
               exit(1);
        }
 
while (fin){   // loop while something to read in file 
  gradeSum = 0;  // reset counters
  count = 0;
 
  fin >> name>> tempStr;  // build up multi-part name
  name = name+" "+tempStr;
  
  while (fin>> tempChar && tempChar !='m') // m means its an alphacode
  {
          fin >> tempStr;
          name = name + " " + tempChar + tempStr;   
  } // while fin
 
  fin >> tempStr; // toss alphacode
 
 while (fin>> tempInt>> tempChar) //read in a score, or score; pair
 {
   gradeSum = gradeSum+tempInt;
   count++;
   if (tempChar ==  ';')  // end of line
           break;
 } // if fin
 
  tempAvg = gradeSum/(double)count;  //(want floating point division)
  if (tempAvg > highestAvg) // new highest
  {
          highestAvg = tempAvg;
      highestName = name;
  } // if tempAvg
 
} // while !eof fin
  cout << highestName << " " << highestAvg << endl;
  return 0;
}