// assn2.cpp
// This program is intended to read in student grade data and calculate final
// grades according to the syllabus for the class.

// In this implementation I use local static varialbes inside the recursive
// function.

#include <iostream>
#include <string>

// Declare the function.
double min(double n1,double n2);
void recursiveRead();

void main() {

	recursiveRead();

}

double min(double n1,double n2) {
	return(n1<n2 ? n1 : n2);
}

void recursiveRead() {
	// Declare the static variables.  Remember that they only get initialized
	// at the beginning of the program.
	static int As=0;
	static int Bs=0;
	static int Cs=0;
	static int Ds=0;
	static int Fs=0;
	static double sum=0.0;
	static int studentCount=0;

	string firstName;
	string lastName;

	cin >> firstName;
	if(firstName=="quit") {
		// Do final output.  In this implementation it has to happen here
		// because the variables that store those values are local statics.
		cout << "There were " << studentCount << " students in the class.\n";
		if(studentCount>0) {
			cout << "The average grade was " << sum/studentCount << ".\n";
			cout << "There were " << As << " students with As.\n";
			cout << "There were " << Bs << " students with Bs.\n";
			cout << "There were " << Cs << " students with Cs.\n";
			cout << "There were " << Ds << " students with Ds.\n";
			cout << "There were " << Fs << " students with Fs.\n";
		} else {
			cout << "With no students there was no average and no grades of any type.\n";
		}
		return;
	}
	cin >> lastName;

	// Variables for storing the assignment grades.
	double assn1;
	double assn2;
	double assn3;
	double assn4;
	double assn5;
	double assn6;
	double assn7;
	double assn8;

	// Variables for storing the quiz grades.
	double quiz1;
	double quiz2;
	double quiz3;
	double quiz4;
	double quiz5;
	double quiz6;

	// Variables for storing the test grades.
	double test1;
	double test2;

	double classParticip;

	// Read all the data in.
	cin >> assn1 >> assn2 >> assn3 >> assn4 >> assn5 >> assn6 >> assn7 >> assn8;
	cin >> quiz1 >> quiz2 >> quiz3 >> quiz4 >> quiz5 >> quiz6; 
	cin >> test1 >> test2;
	cin >> classParticip;

	// Calculate assignment average.
	double assnAverage=(assn1+assn2+assn3+assn4+assn5+assn6+assn7+assn8)/8.0;

	// Calculate quiz average.
	double quizMin=min(quiz1,min(quiz2,min(quiz3,min(quiz4,min(quiz5,quiz6)))));
	double quizAverage=(quiz1+quiz2+quiz3+quiz4+quiz5+quiz6-quizMin)/5.0;

	// Calculate test average.
	double testAverage=(test1+test2)/2.0;

	// Calculate final average.
	double finalAverage=0.5*assnAverage+0.3*testAverage+0.1*quizAverage+0.1*classParticip;

	// Output line for student.
	cout << firstName << " " << lastName << " " << finalAverage << endl;
	
	// Increment the sum of the grades.
	sum+=finalAverage;
	studentCount++;

	// Decide grade type and increment.
	if(finalAverage>=90.0) {
		As++;
	} else if(finalAverage>=80.0) {
		Bs++;
	} else if(finalAverage>=70.0) {
		Cs++;
	} else if(finalAverage>=60.0) {
		Ds++;
	} else {
		Fs++;
	}

	recursiveRead();
}