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

Design a TestScores class that has member variables to hold three test scores. T

ID: 3539438 • Letter: D

Question

Design a TestScores class that has member variables to hold three test scores. The class should have a constructor, accessor, and mutator functions for the test score fields, and a member function that returns the average of the test scores. Demonstrate the application and the class by writing three separate programs. You are to provide a driver to demonstrate the functionality of an instance of this class. You many choose to use the hardwired data or have user to input the test data from the console.

The program should ask the user to enter three test scores, which are stored in the TestScores object.
The application program, lab9.cpp, should display the average of the scores, as reported by the TestScores object.

Submit this lab in thee files, explained in Ch. 13-5 (p.729): lab9.cpp, testScores.h, and testScores.cpp.


PLEASE SPLIT UP THE CODE INTO THREE FILES JUST LIKE THE PROGRAM ASKS! THANKS!

Explanation / Answer

// TestScores.h

class TestScores
{
private: int score[3];
public:
TestScores();
void set_score(int i,int sc);
int get_score(int i);
double get_average();
};

// END of TestScores.h


// START of TestScores.cpp
#include "TestScores.h"

TestScores::TestScores()
{
for(int i=0; i<3; i++)
score[i] =0;
}
void TestScores::set_score(int i, int sc)
{
     score[i] = sc;
}
int TestScores::get_score(int i)
{
    return score[i];
}
double TestScores::get_average()
{
double sum = 0;
for(int i=0; i<3; i++)
sum += score[i];
return sum/3.0;
}

// END of TestScores.cpp

// MAIN DRIVER PROGRAM.
#include<iostream>
#include "TestScores.h"
using namespace std;
int main()
{
int a[3] = {4,5,6};
TestScores TS;
for(int i=0; i<3; i++)
TS.set_score(i,a[i]);
cout << "Aveare of test scores given by " << TS.get_average() << endl;
system("pause");
return 0;
}