Worksheet 9 - Using Classes! In this worksheet you'll build a useful utility to help you figure out your grade in any class! Later on there are some ideas on how to expand this to make it even more useful. 1) We will call our class "Grades" 2) In our class, we will have 5 grades and 5 weights. In addition, it'd be helpful to also have 5 grade categories. 3) Create a class called grades with private data for all 5 grade categories, grades and weights. (Use static arrays for efficiency!) 4) Write a constructor that has no parameters. This constructor should initialize all weights to 0.2 and all grades to 100. 5) Write a single mutator that reads in user input to fill in all categories, grades and weights. Go ahead and use cout and cin in this function, to make things easy. Let's call this mutator readAll. 6) Your mutator should check the sum of all the weights. If the sum is not between .999 and 1.001, then force the user to enter all the weights again. 7) Write an average function that returns the weighted average. There should be no cout/cin in this function. It should work like this: The average is: weight1*grade1 + weight2*grade2 + weight3*grade3 + weight4*grade4 + weight5*grade5 If you used arrays, you can do this much more easily in a for loop. Let's call this average function getAverage. 8) Here's a sample main: int main() { Grades mygrades; mygrades.readAll(); cout << "My course grade is: " << mygrades.getAverage() << endl; } ---- Some Extensions ---- Add Quizzes -- Difficulty: Moderate 1) Add a function to handle the functionality of worksheet #8. In this function you will: A) Ask the user how many quizzes they had. B) Read in both maximum quiz scores and achieved quiz scores. C) Compute the overall average by summing the achieved and dividing by the sum of the maximum. D) Lastly return this value. 2) When the user describes a category as a "Quiz", run this function to set the appropriate grade. If the user types "Quiz" for the first category, your program should then run the function above and assign grade[0] to the result. Of course, you're not likely to be explicitly referring to grade[0], but rather grade[i] or something similar inside a for loop. 3) If you get this far, you can completely handle the average of your grade in this course. Add Dynamics! -- Difficulty: Hard 1) Switch to dynamic arrays for grade categories, grades and weights. 2) This requires the constructor to know how many categories there will be and to get the memory for these dynamic arrays. Thus, change (or remove) the 0 parameter constructor and make a 1 parameter constructor that takes in the number of categories there will be so that you may allocate the memory for the arrays. Remember to initalize the values as before. 3) Now, in the readAll function, you should be able to allow only 2 categories or 10. You should be able to use everything else in the same way, assuming you've set up your loops with good programming practice. ---- E.C. ---- Show this working with all extensions to Dr. Ramsey next week!