# Deborah R. Fowler

## Weighted Grade Average

Posted Jan 8 2015

Often grades are computed using weighted grading. For example, in my classes the exercise and projects are given different weights toward your final grade.

How is a weighted grade computed?

For example, if a class weighting is given as:

10% for Exercise 1

20% for Exercise 2

30% for Exercise 3

40% for Exercise 4

You have four assignments. These four assignments will be used to compute your grade (out of a total possible 100%).

Recall that percentages really mean "per 100". So if an exercise is worth 10% it is worth 10/100 or .1 of your total grade.

Therefore - your weightings should total 100% (a good error checking test in a computer program would be to check this and have the user re-enter weights if this is incorrect).

To calculate the grade you would take the weighted value of each grade:

Suppose you received grades of 90, 80, 85, and 95 on Exercise 1 to 4. You calculation would be:

weightedAverage = .1 * 90 + .2 * 80 + .3 * 85 + .4 * 95 = 88.5

Looking at it another way, consider when you compute a non-weighted average of grades.

The numbers are added together and divided by the number of exercises. This means each exercise is given an equal weighting. So for example, (90+ 80 +85 + 95) / 4 = 87.5

Really this is simply a weighting with each exercise being worth equal weighting, 100%/4 = 25% or weighted

.25 * 90 + .25 * 80 + .25 * 85 + .25 * 95 = 87.5

or we could have rewritten it as (90 + 80 + 85 + 95) * 1/4

or (90 + 80 + 85 + 95) * .25 and then distributed

In C++, you might have the weighting stored in a vector or array (perhaps eventually as part of a class (as we move into OOP). A simple code snippet may look something like this:

// declare and initalize your sum to zero

float weightedAverage = 0;

for (int i = 0; i < numberOfGrades; ++i)

{

weightedAverage += weights[i] * grades[i];

}

Here is a simple sample program weightedAverage.cpp