#include<iostream>
#include<fstream>
#include<cstring>
#include<iomanip>
using namespace std;

const int UNI=20;
const int ROW=3;

ifstream inp("input1.txt") ;
ofstream nmcb("output.txt");
	
void getInput(int dllm[][3],string nameUNI[])
{	
	if (!inp)
	{
	cout << "Error , failed to open file !!" ;
	exit(0);
	}
	int a = 0, b = 0, n;
	for(int i=0;i<UNI;i++)
	{
		inp>>nameUNI[i];
		
		a++;
		for(int j=0;j<ROW;j++)
		{
			inp>>dllm[i][j];
			b++;
		}
	}
	n = a+b;
}

void calTotal(int dllm[][3],double &totalIntake,double &totalEnrol, double &totalOut)
{
	totalIntake=0,totalOut=0,totalEnrol=0;
	
	for(int i=0;i<UNI;i++)
	{	
	totalIntake+= dllm[i][0];	
	}
	
	for(int i=0;i<UNI;i++)
	{
	inp>>dllm[i][1];	
	totalEnrol+= dllm[i][1];	
	}
	
	for(int i=0;i<UNI;i++)
	{
	inp>>dllm[i][2];	
	totalOut+= dllm[i][2];	
    }
	
}

void getHighest(int dllm[][3],string nameUNI[] ,string &w,string &t,string &f,int &highIntake,int &highEnrol,int &highOut)
{
	
	highIntake=0, highEnrol=0, highOut=0;
	for(int i=0;i<UNI;i++)
	{
	if(dllm[i][0]>highIntake)
	{
	
	highIntake=dllm[i][0];
    w=nameUNI[i];
    }
	}
	for(int i=0;i<UNI;i++)
	{
	
	if(dllm[i][1]>highEnrol)
	{
	
	highEnrol=dllm[i][1];
	t=nameUNI[i];
    }
	}
    for(int i=0;i<UNI;i++)
	{
	
	if(dllm[i][2]>highOut)
	{ 
	
	highOut=dllm[i][2];
	f=nameUNI[i];
    }
	}

    
}

void getLowest(int dllm [][3],string nameUNI[], string &n,string &p,string &q,int &lowIntake,int &lowEnrol,int &lowOut)
{
    lowIntake=dllm[0][0],lowEnrol=dllm[0][1],lowOut=dllm[0][2];
    
	for(int i=0;i<UNI;i++)
	{
	if(dllm[i][0]<lowIntake)
	{
	lowIntake=dllm[i][0];
	n = nameUNI[i];
	}
	}

	for(int i=0;i<UNI;i++)
	{
	if(dllm[i][1]<lowEnrol)
	{
	lowEnrol=dllm[i][1];
	q=nameUNI[i];
	}
 
	}
    for(int i=0;i<UNI;i++)
	{
	
	if(dllm[i][2]<lowOut)
	{
	lowOut=dllm[i][2];
	
	p=nameUNI[i];
 	}
	}
		
}

int main ()
{
	double avrgIntake,avrgEnrol,avrgOut,totalIntake=0,totalOut=0,totalEnrol=0;
	int lowIntake,lowEnrol,lowOut,highIntake, highEnrol, highOut;
	string w,t,f,n,p,q;
	
	int dllm [UNI][ROW];
	
	string nameUNI[20];
	
	getInput(dllm,nameUNI);
	
	nmcb<<setw(70)<<"NUMBER OF STUDENTS' INTAKE, ENROLMENT AND OUTPUT "<<endl; 
	nmcb<<setw(63)<<"IN PUBLIC UNIVERSITIES (2015) "<<endl;
    for(int c=0;c<78;c++)
    {
    	nmcb<<"-";
	}
	nmcb<<endl;
	nmcb << left ;
	nmcb<<setw(20)<<"UNIVERSITY"<<setw (20)<<"INTAKE"<<setw(20)<<"ENROLMENT"<<setw(20)<<"OUTPUT"<<endl;
	
	 for(int c=0;c<78;c++)
    {
    	nmcb<<"-";
	}
	nmcb<<endl;
	
	  for(int i=0;i<UNI;i++)
	{
	
		nmcb<<"   "<<setw(20)<<nameUNI[i];
		
		for(int j=0;j<ROW;j++)
		{
		nmcb<<setw(20)<<dllm[i][j];
		
		}
	nmcb<<endl;	
    }
	calTotal(dllm,totalIntake,totalEnrol,totalOut );
	
	avrgIntake=totalIntake/20.0;
	avrgEnrol=totalEnrol/20.0;
	avrgOut=totalOut/20.0;
	
	
	getHighest(dllm,nameUNI,w,t,f,highIntake,highEnrol,highOut);
	
	getLowest(dllm,nameUNI,n,p,q,lowIntake,lowEnrol,lowOut);
		 for(int c=0;c<78;c++)
    {
    	nmcb<<"-";
	}
	nmcb << endl ;
	nmcb<<"   "<<setw(20)<<"TOTAL"<<setw(20)<<totalIntake<<setw(20)<<totalEnrol<<setw(20)<<totalOut<<endl;
	
	nmcb<<fixed<<setprecision(2);
	
	nmcb<<"   "<<setw(20)<<"AVERAGE"<<setw(20)<<avrgIntake<<setw(20)<<avrgEnrol<<setw(20)<<avrgOut<<endl;
	
	 for(int c=0;c<78;c++)
    {
    	nmcb<<"-";
	}
	nmcb<<endl;
	nmcb<< "THE LOWEST NUMBER OF STUDENTS' INTAKE\t   = " <<lowIntake << " (" << n << ")" <<endl ;
	nmcb<< "THE LOWEST NUMBER OF STUDENTS' ENROLMENT  = " <<lowEnrol  << " (" <<q << ")"  << endl ;
	nmcb<< "THE LOWEST NUMBER OF STUDENTS' OUTPUT\t   = " <<lowOut  << " (" <<p << ")"   << endl << endl ;	
	
	nmcb<< "THE HIGHEST NUMBER OF STUDENTS' INTAKE\t  = " << highIntake << " (" <<w<< ")" <<endl ;
	nmcb<< "THE HIGHEST NUMBER OF STUDENTS' ENROLMENT = " << highEnrol<< " (" << t << ")" <<endl ;
	nmcb<< "THE HIGHEST NUMBER OF STUDENTS' OUTPUT\t  = " << highOut << " (" << f << ")" <<endl << endl ;
	
	
	nmcb<< "THE RANGE OF NUMBER OF STUDENTS' INTAKE\t  = " <<highIntake-lowIntake  << endl ;
	nmcb<< "THE RANGE OF NUMBER OF STUDENTS' ENROLMENT = " <<highEnrol-lowEnrol  << endl ;
	nmcb<< "THE RANGE OF NUMBER OF STUDENTS' OUTPUT\t  = " <<highOut-lowOut     << endl ;

    inp.close();
    nmcb.close();

    return 0;
    
}


	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	

