Write a program that will compute average grades and letter grades for 5 student
ID: 3642592 • Letter: W
Question
Write a program that will compute average grades and letter grades for 5 students.Create a C++ class called Grade with three accessor member functions: getGrades(), which will prompt for the grades for the 5 students, computeAvg(), which will calculate the average grade and giveLetter() which will assign a letter grade A though F.
The grade is to be calculated for two quizzes, each worth 20 percent of the grade, and two exams, each worth 30 percent of the grade.
Use an array of type Grade for the 5 students.
For each student output their average and letter grade.
Explanation / Answer
using namespace std; #include class Grade { public: double grades[4]; // the 4 grades (2 quizzes & 2 tests) double average; // the calculated average char letter; // the letter grade void getGrades(); // get grades from users void computeAvg(); // compute the average of grades void giveLetter(); // assigned letter grade }; void Grade::getGrades() { cout > grades[0]; cout > grades[1]; cout > grades[2]; cout > grades[3]; return; } void Grade::computeAvg() { // weighted average of grades quizzes = 20% each, exams = 30% each average = grades[0] * 0.2 + grades[1] * 0.2 + grades [2] * 0.3 + grades[3] * 0.3; return; } void Grade::giveLetter() { if (average < 60) { // 0% = 60% = F letter = 'F'; } else if (average < 70) { // 60% - 70% = D letter = 'D'; } else if (average < 80) { // 70% - 80% = C letter = 'C'; } else if (average < 90) { // 80% - 90% = B letter = 'B'; } else { // 90% - 100% = A letter = 'A'; } return; } int main() { Grade classGrades[5]; // Input data for (int i=0;iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.