(C++ PROJECT )Course Grades In a course, a teacher gives the following tests and
ID: 3660569 • Letter: #
Question
(C++ PROJECT )Course Grades
In a course, a teacher gives the following tests and assignments:
* A lab activity that is observed by the teacher and assigned a numeric score.
* A pass/fail exam that has 10 questions. The minimum passing score is 70.
* An essay that is assigned a numeric score.
* A final exam that has 50 questions.
Write a class named CourseGrades. The class should have a member named grades that is an array of GradedActivity pointers. The grades array should have four elements, one for each of the assignments previously described. The class should have the following member functions:
setLab: This function should accept the address of a GradedActivity object as its argument. This object should already hold the student s score for the lab activity. Element 0 of the grades array should reference this object.
setPassFailExam: This function should accept the address of a PassFailExam object as its argument. This object should already hold the student s score for the pass/fail exam. Element 1 of the grades array should reference this object.
setEssay: This function should accept the address of an Essay object as its argument. (See Programming Challenge 6 for the Essay class. If you have not completed Programming Challenge 6, use a GradedActivity object instead.) This object should already hold the student s score for the essay. Element 2 of the grades array should reference this object.
setPassFailExam: This function should accept the address of a FinalExam object as its argument. This object should already hold the student s score for the nal exam. Element 3 of the grades array should reference this object.
print: This function should display the numeric scores and grades for each element in the grades array. Demonstrate the class in a program.
Explanation / Answer
import java.util.Scanner; 02 03 public class CourseGrades { 04 05 06 public static void main(String[] args){ 07 08 09 //Create an array to get grades. 10 11 :blink: grades[] array = (int, 12 13 /** 14 * A class that holds a grade for a graded activity. 15 */ 16 class GradedActivity { 17 18 19 private double score; // Numeric score 20 21 /** 22 * The setScore method stores its argument in 23 * the score field. 24 */ 25 26 public void setScore(double s) 27 { 28 score = s; 29 } 30 31 /** 32 * The getScore method returns the score field. 33 */ 34 35 public double getScore() 36 { 37 return score; 38 } 39 40 /** 41 * The getGrade method returns a letter grade 42 * determined from the score field. 43 */ 44 45 public char getGrade() 46 { 47 char letterGrade; // To hold the grade 48 49 if (score >= 90) 50 letterGrade = 'A'; 51 else if (score >= 80) 52 letterGrade = 'B'; 53 else if (score >= 70) 54 letterGrade = 'C'; 55 else if (score >= 60) 56 letterGrade = 'D'; 57 else letterGrade = 'F'; 58 59 return letterGrade; 60 } 61 } 62 } 63 }
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.