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

Construct a class named Student consisting of an integer studcnt 10 number, an a

ID: 3548052 • Letter: C

Question

Construct a class named Student consisting of an integer studcnt 10 number,

an array of five double-precision grades, and an integer representing the total number of grades

entered. The constructor for this class should initialize all Student data members to O.

Included in the class should be member methods to 1) enter a student 10 number, 2) enter a

single test grade and update the total number of grades entered, and 3) compute an average

grade and display the student 10 followed by the average grade.


Include the class constructed in Exercise Sa in the context of a complete program. Your

program should declare two objects of type Student and accept and display data for the two

objects to verify operation of the member methods.

Explanation / Answer

#include<iostream>
using namespace std;

class student
{
      private:
              long int studentId;
              double grades[5];
              int noOfGrades;
      public:
             student();
             void enterStudentId();
             void enterGrades();
             void computeAvgGrade();
      };

student::student()
{
     studentId = 0;
     for (int i=0;i<5;i++)
     {
         grades[i] = 0;
         }
     noOfGrades = 0;
}

void student::enterStudentId()
{
     cout<<"Enter the Student Number: ";
     cin>>studentId;
}

void student::enterGrades()
{
     cout<<"Enter Grade: ";
     cin>>grades[noOfGrades];
     noOfGrades++;
}

void student::computeAvgGrade()
{
     double avg = 0;
     for (int i =0;i<noOfGrades;i++)
     {
         avg += grades[i];
         }
      avg = avg/noOfGrades;
     
      cout<<"Average Grade: "<<avg<<endl;
      cout<<"Student Number: "<<studentId<<endl;
}

int main()
{
    student student1 = student();
    student student2 = student();
   
    student1.enterStudentId();
    student1.enterGrades();
    student1.computeAvgGrade();
    student2.enterStudentId();
    student2.enterGrades();
    student2.computeAvgGrade();
   
    return 0;
}