/* grader7.cpp computes a final course average using the homework
 * average, the average on tests, and a final exam score, and
 * assigns a letter grade.
 *
 * Input:  Three real values representing a student's homework
 *            average, average on tests, and a final exam score
 * Output: The final average and the letter grade
 *******************************************************************/

#include <iostream.h>                  // cin, cout, >>, <<

char LetterGrade(double weightedAverage);

int main()
{
  const double HOMEWORK_WEIGHT = 0.2, // weights for homework,
               TEST_WEIGHT = 0.5,     //   tests,
               EXAM_WEIGHT = 0.3;     //   and the exam.

  cout << "This program computes a final course grade using the\n"
          "homework average, test average, and a final exam "
          "score.\n";
  
  cout << "\nEnter the homework average, test average, "
          "and exam score:\n";

  double homeworkAverage,     // the average of the homework scores
         testAverage,         // the average of the test scores
         examScore;           // the final exam score

  cin >> homeworkAverage >> testAverage >> examScore;
  
  double finalAverage = HOMEWORK_WEIGHT * homeworkAverage +
                        TEST_WEIGHT * testAverage +
			EXAM_WEIGHT * examScore;

  char grade = LetterGrade(finalAverage);    // the letter grade received

  cout << "Final Average = " << finalAverage
       << ", Grade = " << grade << "\n\n";
}

/* LetterGrade computes the appropriate Grade for a given weightedAverage.
 *
 * Receive:      a (double) weighted average.
 * Precondition: 0 <= weightedAverage<= 100.
 * Return:        the appropriate (char) letter grade (A, B, C, D, or F) ************************************************************************/

char LetterGrade(double weightedAverage)
{
  switch ( int(weightedAverage) / 10 )
    {
    case 10:                // int(100)/10 -> 10
    case 9:                 // int(90-99)/10 -> 9
      return 'A';
    case 8:                 // int(80-89)/10 -> 8
      return 'B';
    case 7:                 // int(70-79)/10 -> 7
      return 'C';
    case 6:                 // int(60-69)/10 -> 6
      return 'D';
    default:                // not so good!
      return 'F';
    }
}

