Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Creat a C++ class that represents a student in a normal college class in the con

ID: 3771609 • Letter: C

Question

Creat a C++ class that represents a student in a normal college class in the context of an instructor's gradebook application. The student class will contain the following:

An integer attribute named ID (Defaults to 0)

A string attribute named name (Defaults to an empty string)

Three float attributes named test1, test2, and test3 (Defaults to 0.0)

A no-argument constructor that creates a default object

Accessor and mutator methods for all attributes

A method named CalcFinalScore that computes and returns the average of the three test scores as a float

A method named CalcFinalGrade that calls CalcFinalScore and returns a letter grade as a char according to the standard 100-90 equals A, 89-80 equals B, etc.

Write a test program that creates a Student object with an ID number of 672365, a name of Roscoe Meriwether, and Test scores of 95, 88, and 90. Create a neatly formatted output line that includes all five attributes and the numeric and letter grades.

Explanation / Answer

#include <iostream>
#include <string>
using namespace std;

class Student {
private:
   int ID;
   string name;
   float test1, test2, test3;

public:
   Student() {
       ID = 0;
       name = "";
       test1 = 0;
       test2 = 0;
       test3 = 0;
   }

   float CalcFinalScore() {
       return (test1 + test2 + test3) / 3.0;
   }

   char CalcFinalGrade() {
       float avg = CalcFinalScore();
       if (avg >= 90 && avg <= 100)
           return 'A';
       else if (avg >= 80 && avg <= 89)
           return 'B';
       else if (avg >= 70 && avg <= 79)
           return 'C';
       else if (avg >= 60 && avg <= 69)
           return 'D';
       else
           return 'E';
   }

   int getID() {
       return ID;
   }

   void setID(int sid) {
       ID = sid;
   }

   string getName() {
       return name;
   }

   void setName(string sname) {
       name = sname;
   }

   int getTest1() {
       return test1;
   }

   void setTest1(int score) {
       test1 = score;
   }

   int getTest2() {
       return test2;
   }

   void setTest2(int score) {
       test2 = score;
   }

   int getTest3() {
       return test3;
   }

   void setTest3(int score) {
       test3 = score;
   }
};


int main() {

   Student std = Student();
   std.setID(672365);
   std.setName("Roscoe Meriwether");
   std.setTest1(95);
   std.setTest2(88);
   std.setTest3(90);

   cout << "Student ID: " << std.getID()
          << " NAme: " << std.getName()
          << " Test1: " << std.getTest1()
          << " Test2: " << std.getTest2()
          << " Test3: " << std.getTest3()
          << " Final Score: " << std.CalcFinalScore()
          << " Grade: " << std.CalcFinalGrade() <<endl;
   return 0;
}

---output--

Student ID: 672365 NAme: Roscoe Meriwether Test1: 95 Test2: 88 Test3: 90 Final Score: 91 Grade: A