// SECJ1013-01 Assignment 1
// Group Members:
// AHMAD ZULHAKIM BIN ZAINAL  A19EC0179
// LEE TONG MING              A19EC0069
// Question 3

#include <iostream>
#include <iomanip>
using namespace std;

//Fuction prototypes
float calculateSum(float &); 		 // Function to calculate the sum of the mark
float calculateAverage(float, int);  // Function to calculate the average mark
float getMark(int); 				 // Fuction to get mark of each assessment
void getGrade(float);				 // Function to get the grade of average marks

int main ()
{	
	int numAssessment;	  // To hold the number of assessments
	float mark;			  // To hold the mark of each assessment
	float sum;			  // To hold the sum of the marks
	float average;		  // To hold the average of the marks
	
	// Get the number of assessments.
	cout << "Enter the number of assessments: ";
	cin >> numAssessment;
	cout << fixed << setprecision(2);
	
	for (int i=1; i <= numAssessment; i++)
	{
		mark = getMark(i);			  // Calling function getMark
		sum += calculateSum(mark);	  // Calling function calculateSum
	}

	// Calling function calculateAverage.
	average = calculateAverage(sum, numAssessment);

	// Calling function getGrade and display the letter grade.
	getGrade(average);
	system("pause");
	return 0;
}

// Definition of function getMark.
// This function asks user for mark of each assessment and returns the validated marks.
float getMark(int a)
{	
	float mark;		// Mark of each assessment
	
	do
	{
	// Get mark of each assessment.
	cout << "Enter mark of assessment " << a 
	<< "(between 1-100):  ";
	cin >> mark;
	
	// Validate the mark entered.
	if ((mark < 0) || (mark > 100))
		cout << "\nPlease enter the mark in the range of 0-100.\n";
	
	} while ((mark < 0) || (mark > 100));	
	return mark;
}

// Definition of function calculateSum.
// This function calculates the sum of the marks.
// The float parameter sum is a reference variable
// and this function returns sum in a float.
float calculateSum (float& sum)
{
	return sum;
}

// Definition of function calculateAverage.
// This function calculates the average of the marks.
// This function uses float parameter, s and int parameter, n
// and returns s divided by n as a float.
float calculateAverage(float s, int n)
{
	return s / n;
}

// Definition of function getGrade.
// This function determine the letter grade of the average marks.
void getGrade(float avrg)
{
	if (avrg >= 90)
		cout << "The grade is A\n";
	else if ((avrg >= 80) && (avrg <=89))
		cout << "The grade is B\n";
	else if ((avrg >= 70) && (avrg <= 79))
		cout << "The grade is C\n";
	else if ((avrg >= 60) && (avrg <=69))
		cout << "The grade is D\n";
	else
		cout << "The grade is F\n";
}