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

Create a class Student. The class has member data: name and tests (array of 3 te

ID: 3631161 • Letter: C

Question

Create a class Student. The class has member data: name and tests (array of 3 test scores). It has several functions: setName, getName, setTests, and displayResult. The function setTests will copy the test scores from the integer array argument into the class data tests. The function displayResult will first calculate the average score from the 3 test scores. It then displays student’s name, 3 test scores and the average score on the same line. You must create Student.h file to store class definition; Student.cpp file to store the class implementation code; and mid2.cpp to store the main function of the program.

Hint: the main function may contain the following codes:

int main()
{
Student student;

string n; // student name

int t[3]; // student test scores

cout << "Enter student name: ";
getline( cin, n ); // input first name and last name

student.setName( n );

cout << "Enter student test scores: ";
cin >> t[0] >> t[1] >> t[2]; // input three test scores

student.setTests( t );

student.displayResults();

system("pause");
return 0;
}

Explanation / Answer

please rate - thanks

Student.h file in red

Student.cpp in green

mid2.cpp in black

sorry I don't work in multiple files--I answer too many questions and my disk is already a disaster because of it. let me know if you have a problem separating them

#include <iostream>
using namespace std;
class Student
{private:
    string name;
    int tests[3];
public:
    void setName(string);
    string getName();
    void setTests(int[]);
    void displayResults();
};
void Student::setName(string n)
       {name=n;
       }
string Student::getName()
     {return name;
     }
void Student::setTests(int t[])
    {int i;
    for(i=0;i<3;i++)
       tests[i]=t[i];
    }
void Student::displayResults()
   {int i,sum;
   double average;
   sum=0;
   for(i=0;i<3;i++)
       sum+=tests[i];
   average=sum/3.;
   cout<<"Name: "<<name<<" test scores: ";
   for(i=0;i<3;i++)
        cout<<tests[i]<<" ";
   cout<<"average: "<<average<<endl;
}
      
     

int main()
{
Student student;
string n; // student name
int t[3]; // student test scores
cout << "Enter student name: ";
getline( cin, n ); // input first name and last name
student.setName( n );
cout << "Enter student test scores: ";
cin >> t[0] >> t[1] >> t[2]; // input three test scores
student.setTests( t );
student.displayResults();
system("pause");
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote