/*	Top Colleges by Enrollment program.
	Displays the average enrollment of all colleges, and a list of the five 
	colleges with the largest enrollments according to the database 
	accessed by college.h.                                                           */

#include <iostream.h>
#include <college.h>
#include <toplist.h>

using namespace std;	// October 5, 2001

//--------------------------------------------------------------------------------
void WriteTopColleges(const TopListClass &CollegeList)
/*	Displays the CollegeList in a tabular format
	Post: A formatted list is displayed              */
{
	for (int i=1; i<=CollegeList.GetListSize(); i++) {
		cout.unsetf(ios::right);	//required by CW
		cout.setf(ios::left);
		cout.width(40);
		cout << CollegeList.GetName(i);
		cout.unsetf(ios::left);		//required by CW
		cout.setf(ios::right);
		cout << CollegeList.GetScore(i) << endl;
	}
}
//--------------------------------------------------------------------------------
int main()
{
	CollegeClass College;

	const int ListSize = 5;
	TopListClass EnrollmentList("enroll.dat", ListSize);

	EnrollmentList.ClearData();
	int Count = 0;
	long Sum = 0;
	while (College.CurrentIsValid()) {
		Count++;
		Sum += College.GetEnrollment();
		EnrollmentList.AddItem(College.GetEnrollment(),College.GetName());
		College.GetNext();
	}
	cout << "Average enrollment over " << Count << " colleges: " 
		<< double(Sum)/Count << endl;

	WriteTopColleges(EnrollmentList);
	return (0);
}

