/*
NUR ALEEYA SYAKILA BINTI MUHAMAD SUBIAN A19EC0127 000726100810
NUR HADIRAH MUNAWARAH BINTI ROZMIZAN A19EC0201 000526060076
*/

#include <iostream>
#include <fstream>
#include <iomanip>
#define max 999
using namespace std;

void readFile (char file[15],float faran [], int &read)
{
	ifstream inp;
	inp.open(file);

	if(!inp)
	{
		cout<<"ERROR!!"<<endl;
		exit(0);
	}
	while(inp>>faran[read])
	{
		read++;
	}
	
	inp.close();
	
}

float computeC(float faran [], float celci[], int &read)
{
	for (int i=0; i<read; i++)
	{
		float celcius = 5.00/9.00 * (faran[i] - 32.00);
		celci[i]=celcius;
	}
}

float average(float celci[],int &read)
{

	float sum=0;
	for(int i=0; i<read;i++)
	{
		sum+=celci[i];
	}
	
	float ave=sum/(read);
	return ave;
}

char grade(float celci)
{
    if (celci<20)
    return 'L';
    else if (celci<35)
    return 'M';
    else
    return 'H';
 	
 }

void writeFile(float faran[],float celci[],int &read)
{
	ofstream out;
	out.open("output3.txt");
	out<<fixed<<setprecision(2);
	out << "C(Celcius)"<<setw(23)<< "F (Farenheit)"<<setw(16)<<"Description"<<endl;
	out <<"=========="<<setw(18)<<"========="<<setw(18)<< "====="<<endl;
	for (int i=0;i<read;i++)
	{
		out <<"  "<< left<<setw(20)<<celci[i]<<setw(21)<<faran[i]<<setw(15)<<grade(celci[i])<<endl;
	}

	out.close();
}
int totalGrade(float celci[], int &read, int &high, int &medium, int &low)
{
	for(int i=0;i<read;i++)
	{
		char g=grade(celci[i]);
		if (g=='H')
			high++;
		else if(g=='M')
			medium++;
		else if (g=='L')
			low++;
	}
	
}
int main()
{
	cout<<fixed<<setprecision(1);
	ofstream out("output3.txt");
	float f[max];
	float c[max];
	int r=0,h=0,m=0,l=0;
	
	readFile("input3.txt",f,r);
	computeC(f,c,r);
	float a=average(c,r);
	totalGrade(c,r,h,m,l);
 	writeFile(f,c,r);
	
	cout<<"Average of the temperature: "<<a<<endl;
	cout<<"Number of high temperature: "<<h<<endl;
	cout<<"Number of medium temperature: "<<m<<endl;
	cout<<"Number of low temperature: "<<l<<endl;
	
	return 0;
}
