/*	Muhammad Anas Alif Shah Bin Azeli Shah
	001102-10-0219
	Section 2
	
	Muhammad Irfan Daniel Bin Abd Karim
	000717-10-0667
	Section 2
	
	Date of submission : 30 November 2019 */

#include <iostream>
#include <fstream>
#include <iomanip>
#define R 20
using namespace std;

void getInput(string name[R], int intake[R], int enrol[R], int output[R])
{
	ifstream input ("input1.txt");
	ofstream output1("output.txt");
	
	if (!input.is_open())
	{
		cout << "The input is error !";
		exit(0);
	}	
	
	while (!input.eof())
	{
		for (int i = 0; i < R; i++)
		{
			input >> name[i] >> intake[i] >> enrol[i] >> output[i];
		}
	}
	
	input.close();
	output1.close();

}

int calTotal (int total[])
{
	int sum = 0;
	for (int i = 0; i < R; i++)
	{
		sum += total[i];
	}
			
	return sum;
}

float calAvg (int total[])
{
	float sum = 0.0, a = 0, average;
	for (int i = 0; i < R; i++)
	{
		sum += total[i];
		a++;
	}
	average = sum / a;
	return average;	
}

int getLowest (int lowest[], int a)
{
	int low = 999999;
	for (int i = 0; i < R; i++)
	{
		if (low > lowest[i])
		{
			low = lowest[i];
			a = i;
		}
	}
	return a;
}

int getHighest (int highest[], int b)
{
	int high = -999999;
	for (int i = 0; i < R; i++)
	{
		if (high < highest[i])
		{
			high = highest[i];
			b = i;
		}
	}
	return b;
}

int main ()
{
	ifstream input ("input1.txt");
	ofstream output1 ("output.txt");
	
	string name[R];
	int lowintake, lowenrol, lowoutput, highintake, highenrol, highoutput, intake[R], enrol[R], output[R], a = 0, b = 0;
	
	getInput(name, intake, enrol, output);
	
	output1 << endl;
	output1 << "\tNUMBER OF STUDENTS' INTAKE, ENROLMENT AND OUTPUT" << endl;
	output1 << "\t\tIN PUBLIC UNIVERSITIES (2015)" << endl << endl;
	output1 << "---------------------------------------------------------------" << endl;
	output1 << setw(15) << "UNIVERSITY" << setw(12) << "INTAKE" << setw(15) << "ENROLMENT" << setw(15) << "OUTPUT" << endl;
	output1 << "---------------------------------------------------------------" << endl;	
	
	for (int i = 0; i < R; i++)
	{
		output1 << setw(12) << name[i] << setw(15) << right << intake[i] << setw(15) << enrol[i] << setw(15) << output[i] << endl;
	}
	
	output1 << "---------------------------------------------------------------" << endl;
	output1 << fixed << setprecision(2);
	output1 << setw(12) << "TOTAL" << setw(15) << calTotal(intake) << setw(15) << calTotal(enrol) << setw(15) << calTotal(output) << endl;
	output1 << setw(12) << "AVERAGE" << setw(15) << calAvg(intake) << setw(15) << calAvg(enrol) << setw(15) << calAvg(output) << endl;
	output1 << "---------------------------------------------------------------" << endl << endl;
	
	lowintake = getLowest(intake, a);
	lowenrol = getLowest(enrol, a);
	lowoutput = getLowest(output, a);
	highintake = getHighest(intake, b);
	highenrol = getHighest(enrol, b);
	highoutput = getHighest(output, b);
	
	output1 << "THE LOWEST NUMBER OF STUDENTS' INTAKE = " << intake[lowintake] << "(" << name[lowintake] << ")" << endl;
	output1 << "THE LOWEST NUMBER OF STUDENTS' ENROLMENT = " << enrol[lowenrol] << "(" << name[lowenrol] << ")" << endl;
	output1 << "THE LOWEST NUMBER OF STUDENTS' OUTPUT = " << output[lowoutput] << "(" << name[lowoutput] << ")" << endl << endl;
	output1 << "THE HIGHEST NUMBER OF STUDENTS' INTAKE = " << intake[highintake] << "(" << name[highintake] << ")" << endl;
	output1 << "THE HIGHEST NUMBER OF STUDENTS' ENROLMENT = " << enrol[highenrol] << "(" << name[highenrol] << ")" << endl;
	output1 << "THE HIGHEST NUMBER OF STUDENTS' OUTPUT = " << output[highoutput] << "(" << name[highoutput]  << ")" << endl << endl;
	output1 << "THE RANGE OF NUMBER OF STUDENTS' INTAKE = " << intake[highintake] - intake[lowintake] << endl;
	output1 << "THE RANGE OF NUMBER OF STUDENTS' ENROLMENT = " << enrol[highenrol] - enrol[lowenrol] << endl;
	output1 << "THE RANGE OF NUMBER OF STUDENTS' OUTPUT = " << output[highoutput] - output[lowoutput] << endl << endl;
	
	output1 << "---------------------------------------------------------------" ;	
	
	input.close();
	output1.close();
	
	return 0;
}































































































