So, you have a list of five test weights:
{ 10, 15, 20, 25, 30 }
(which conveniently sum to 100).
And you have lists of test scores for each test. Here is one of the lists:
{ 80.9, 90.2, 98.5, 89.8, 97.7 }
(which conveniently is also five elements long).
Frankly, I don’t think Nancy has much to worry about for her grade. But I suppose the professor must give her an official final grade anyway.
Test grades rate at 100 points. What you are being asked to do is
twist each of Nancy’s grades to only be worth, say, 10 points.
So, for her first test, Nancy earned 80.9 * 0.1 = 8.09 points. Nancy takes this home and her parents say, “stop chewing bubble gum and start studying!”
But Nancy says, “No, that’s 8 points out of 10. I got a B.”
So her parents take her out for ice cream.
The next exam is adjusted to be only worth 15 points. So again we take Nancy’s 100-point test and scale it: 90.2 * 0.15 = 13.53 points.
Again, that’s 13.53 points out of 15, an A, so Nancy’s parents take her out for ice cream again. Nancy likes the blue sherbet with gelato. She wonders if that cute guy two seats over would like to take her out to get some ice cream.
We keep going. Each grade has a weight applied to it:
weight 10 15 20 25 30
unweighted 80.9 90.2 98.5 89.8 97.7
weighted 8.09 13.53 19.7 22.45 29.31
Now all we need to do is sum all the weighted grades to get Nancy’s final course grade:
8.09 + 13.53 + 19.7 + 22.45 + 29.31
= 93.08
A solid A! Nancy can’t stand ice cream now, but that cute guy has introduced her to power shakes and track and field. Nancy feels much better now, and is considering how to introduce him to her parents, because he has a nose ring.
The salient features are that for each set of grades in a course, you have two same-sized arrays: the weights array and the grades array.
This works just like your standard average:
• before summing a grade into the running total, multiply it by the weight
• when you are done, you must divide by 100 (since the weights are * 100)
The way to figure this out is to write a
separate, small program that does nothing more than find the average of a bunch of numbers input by the user. Here is some help:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
#include <iostream>
using namespace std;
int main()
{
int n;
cout << "n? ";
cin >> n;
double sum = 0.0;
for (int i = 0; i < n; i++)
{
double grade;
cout << "grade? ";
cin >> grade;
sum = /* what do I do here? */
}
double average = /* what do I do here? */
cout << "The average grade is: " << average << "\n";
}
|
Once you get that working, fix it to apply a weight on every loop. You might as well set
n = 5
and use the same weights as in your homework assignment.
And once you have done that, you will see
exactly what you need to do to your loop on lines 119..128 to get a weighted final grade.
Hope this helps.
[edit] Fixed some formatting