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

1-declare an object pointer for the Student class ? 2.create an Student object u

ID: 665371 • Letter: 1

Question

1-declare an object pointer for the Student class ?

2.create an Student object using the new operator and the default constructor ? c

3.all showStudentData(Student *) function and pass the object pointer to this function. This function displays the values of studentID, studentName, and the average test score result. ?

4.call updateStudentData(Student *) function and pass the object pointer to this function. This function ask the user to enter the values of studentID, studentName, and three test scores and call the appropriate member functions to set member values. ?

Explanation / Answer

Coding

#include <iostream>

#include <iomanip>

#include <string>

using namespace std;

const int MAX = 3;

class Student

{

private:

     string StdName;        

     float Exam[MAX];  

     float ExamAvg;    

     float TermGrade;       

     float GradeFinal;      

     float TotalGrade;      

     char AlphaGrade;       

     void CalcExamAvg()

     {

          float MinExamGrade = Exam[0];

          float Tot = Exam[0];

          for (int a = 1; a < MAX; a++)

          {

              Tot += Exam[a];

              if (Exam[a] < MinExamGrade)

                   MinExamGrade = Exam[a];

          }

          ExamAvg = (Tot - MinExamGrade) / (MAX - 1);

     }

     void CalcAlphaGrade()

     {

          if (TotalGrade >= 90.0f)

              {AlphaGrade = 'A';}

          else if (TotalGrade >= 80.0f)

              {AlphaGrade = 'B';}

          else if (TotalGrade >= 70.0f)

              {AlphaGrade = 'C';}

          else if (TotalGrade >= 60.0f)

              {AlphaGrade = 'D';}

          else {

              AlphaGrade = 'F';}

     }

     void CalcNumGrade()

     {

          CalcExamAvg();

          TotalGrade = 0.5f * ExamAvg + 0.3f * GradeFinal + 0.2f *           TermGrade;

     }

public:

     Student()

     {

          StdName = "";

          ExamAvg = TermGrade = GradeFinal = TotalGrade = 0.0f;

          for (int a = 0; a < MAX; a++)

              Exam[a] = 0.0f;

     }

     void StuData(string na, float tg, float fg, float eg[])

     {

          StdName = na;

          TermGrade = tg;

          GradeFinal = fg;

          for (int a = 0; a < MAX; a++)

              Exam[a] = eg[a];

     }

     void CalcTotalGrade()

     {

          CalcNumGrade();

          CalcAlphaGrade();

     }

     void Out()

     {

          cout << " Student name: " << StdName;

          cout << " Number grade:   " << TotalGrade;

          cout << " Letter grade:   " << AlphaGrade;

     }

};

void GetStuData(string&,float&,float&,float[]);

int main()

{

     Student* stuPtr;

     int NumOfStu;

     cout << "Enter no. of students: ";

     cin >> NumOfStu;

     stuPtr = new Student[NumOfStu];

     string StuName;

     float Term;

     float Final;

     float Egrade[MAX];

     for(int a=0;a<NumOfStu;a++)

     {

          GetStuData(StuName,Term,Final,Egrade);

          (stuPtr+a)->StuData(StuName,Term,Final,Egrade);

          (stuPtr+a)->CalcTotalGrade();

     }

     system("cls");

     for(int a=0;a<NumOfStu;a++)

          (stuPtr+a)->Out();

          delete [] stuPtr;

          getchar();

          return 0;

}

void GetStuData(string &na, float &tg, float &fg, float eg[])

{

     cout << "Student name:   ";

     getline(cin, na);

     cout << "Enter term grade: ";

     cin >> tg;

     cout << "Enter final grade:    ";

     cin >> fg;

     for(int a=0;a<MAX;a++)

     {

          cout << "Exam " << a+1 << " grade: ";

          cin >> eg[a];

     }

}