// Name: Tan Ming Hui (A20EC0155)
// Name: Kalaivani A/P Subramaniam (A20EC0056)
// Date : 2021/01/27

#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;

const int size=10;

struct Rainfall
 {
 	float totalrainfall, hightemp, lowtemp;
 	int rainydays;
 	char month[size];
 };
 	
int main()
{
	ifstream inp1;
	inp1.open("data.txt"); // open file
	float average[12];
	float monthlyaverage=0, highest=0, lowest=99999, maverage, total=0;
	int j,k;
	
	//task 1
	if (!inp1.is_open())
	{
		cout << "The file cannot be opened, terminating..." << endl;
		exit (1);
	}

	const int num_month=12;
	Rainfall year[12];
	
	for (int i=0; i<12;i++)
	{
		inp1>> year[i].totalrainfall; 
		inp1>> year[i].rainydays;
		inp1>> year[i].hightemp;
		inp1>> year[i].lowtemp;
		inp1.getline(year[i].month,20);
		total+= year[i].totalrainfall;
		average[i]= (year[i].hightemp+ year[i].lowtemp)/2;
		monthlyaverage+= year[i].totalrainfall;
		
		 if(year[i].hightemp>highest)
		 {
		 	highest=year[i].hightemp;
			k=i;
		 }
		 
		if(year[i].lowtemp <lowest)
		{
			lowest= year[i].lowtemp;
			j=i;
		}
	}
			maverage= monthlyaverage/12;
	
	cout << left << fixed << setprecision(2) ;
	cout << "Total rainfall:  "  << total << endl;
	cout << "Average Monthly Rain:  " << maverage << endl;
	cout << "Highest Temperature:  " << highest << " (Month " << k+1 << ": "<< year[k].month <<")" <<endl;
	cout << "Lowest Temperature:  " << lowest << " (Month " << j+1<< ": "<< year[j].month << ")"<<endl;
	cout << endl << endl;
	cout << setw(12) << "Month" 
		 << setw(8) << "Rain" 
		 << setw(10) << "Rain days"
		 << setw(8) << "Hi TEMP"
		 << setw(8) <<"Lo TEMP"
		 << setw(8) <<"Avg TEMP" << endl;
		 
	cout << setw(12) <<"========="
		 << setw(8) <<"======"
		 << setw(10) <<"========="
		 << setw(8) <<"======="
		 << setw(8) <<"======="
		 << setw(8) <<"========" << endl;

	for (int i=0;i<12;i++) {
		cout<< setw(12) << year[i].month
			<< setw(8) << year[i].totalrainfall 
			<< setw(10) << year[i].rainydays 
			<< setw(8) << year[i].hightemp 
			<< setw(8) << year[i].lowtemp 
			<< setw(8) << average[i] << endl;
	}
	
	inp1.close(); //close file
	return 0;
}
