// main() - get input marks, and find out whether or not the instructor
// decides to enforce the "need to pass the final exam to pass the course"
// rule. Then compute (and print) the final grade. If a student fails the
// final exam, but his/her combined average is 50% or more, then a mark of
// 49% will be printed.
cout << "Enter your total lab mark (/ 200): ";
cin >;>; labs;
cout << "Enter your midterm mark (/ 90): ";
cin >;>; midterm;
cout << "Enter your assignment mark (/ 60): ";
cin >;>; assignment;
cout << "Enter your final exam mark (/ 120): ";
cin >;>; final;
// ask if the "fail final, fail course" rule is in effect
cout << "Will you fail the course if you failed the final exam?\n";
cout << "Enter Y or N: ";
cin >;>; failFinalFailCourse;
// compute the combined mark and the final mark
total = combinedMark( labs, midterm, assignment, final );
finalGrade = adjustMark( total, final, failFinalFailCourse );
// display the final mark as an integer
integerGrade = finalGrade + 0.5; // round off
cout << "Your final grade for the course is "
<< integerGrade << "%.\n";
return 0;
}
// combinedMark - function to combine the labs marks (out of 200), midterm
// marks (out of 90), assignments (out of 60), and final exam mark (out of 120)
// to obtain a final mark for the course. The weight of each is:
// labs: 15%
// midterm: 25%
// assignment: 15%
// final: 45%
float combinedMark( float labs, float midterm, float assignment, float final )
{
// Pre: labs, midterm, and final are all >;= 0
// Post: return the tentative final mark for the course
// Adjust marks so that if one fails the final exam and the "fail the
// final, fail the course" rule is in effect, then a final grade of 49%
// is assigned.
float adjustMark( float rawTotal, float final, char failFinalFailCourse )
{
// Pre: rawTotal and final are >;= 0, and
// failFinalFailCourse is either 'Y' or 'N'
// Post: return the student's assigned course grade