#include <iostream>
using namespace std;

void displayLine();
void getData(int [], double [][5], int);
void calculatePayRoll(double [][5], int);
void printData(int [], double [][5], int);
void highestOvertime(int [], double [][5], int);

int main()
{
	int EMPLOYEE=5, empID[EMPLOYEE];
	double empRecord[EMPLOYEE][5];
	
	getData(empID, empRecord, EMPLOYEE);
	calculatePayRoll(empRecord, EMPLOYEE);
	printData(empID, empRecord, EMPLOYEE);
	highestOvertime(empID, empRecord, EMPLOYEE);
	
	
	
	
	return 0;
}

void displayLine()
{
	for(int i=0;i<105;i++)
	{
		cout << "-";
	}
	cout << endl;
}

void getData(int empID[], double empRecord[][5], int employee)
{
	int i, j;
	
	for(i=0; i<employee;i++)
	{
		
		
		cout << "ID : ";
		cin >> empID[i];
		cout << endl;
		
		for(j=0;j<2;j++)
		{
			cout << "Hours worked : ";
			cin >> empRecord[i][j];
			cout << endl;
			
			j++;
			
			cout << "Rate of Pay (RM per hour) : ";
			cin >> empRecord[i][j];
			cout << endl;
		}	
	}
}

void calculatePayRoll(double empRecord[][5], int EMployee)
{
	int i,j, exceed;
	for(i=0;i< EMployee;i++)
	{
		for(j=2;j<EMployee;j++)
		{
			j=2;
		
			empRecord[i][j]= empRecord[i][j-2] * empRecord [i][j-1];
		
			j++;
		
			if(empRecord[i][j-3] > 40)
			{
				exceed =empRecord[i][j-3] - 40;
				empRecord[i][j]= exceed * 1.5 * empRecord[i][j-2];
			}
			else
			{
				empRecord[i][j]= 0;
			}
		
			j++;
			
			empRecord[i][j]= empRecord[i][j-2] + empRecord[i][j-1];
		
		}
	}
}

void printData(int empID[], double empRecord[][5], int Employee)
{
	int i, j;
	
	cout << "Payroll Final Report" << endl;
	displayLine();
	cout << "ID    HOURS    RATE(RM)    REGULAR PAY (RM)    OVERTIME (RM)    TOTAL(RM) " << endl;
	displayLine();
	
	for(i=0;i<Employee;i++)
	{
		cout << empID[i] << "     ";
		
		for(j=0;j<5;j++)
		{
			cout << empRecord[i][j] << "     ";
			j++;
			
			cout << empRecord[i][j] << "     ";
			j++;
			
			cout << empRecord[i][j] << "     ";
			j++;
			
			cout << empRecord[i][j] << "     ";
			j++;
			
			cout << empRecord[i][j] << endl;
		}
	}
	
	cout << endl;
	
}

void highestOvertime(int empID[], double empRecord[][5], int EmployeE)
{
	int i, mark;
	double highest=empRecord[0][3];
	
	for(i=1;i<EmployeE;i++)
	{
		if(empRecord[i][3]>highest)
		{
			highest=empRecord[i][3];
			mark=i;
		}
	}
	
	cout << "Staff " << empID[mark] << " have the highest pay overtime of RM" << highest << endl;
	
	
}
