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

Consider the class specification below. Write the implementation of the overload

ID: 3546220 • Letter: C

Question

Consider the class specification below.  Write the implementation of the overloaded instersion operator (<<).  The insertion operaator is to output  the data members of an instance of class StudentTestScores into an output file stream.  The function should ouput the student name followed by  the number of test scores followed by the test scores all on the same line and seperated by tabs.   The operator should allow for chaining of intersion operations.

#include <string>

using namespace std;

class StudentTestScores{

    private:

       string studentName;

       float *testScores;  // used to point to an array of test scores

       int numTestScores;  // number of test scores

   public:

       // Class default constructor

// Class copy constructor

// Class destructor

//class accessors

//class mutators

// Overloaded insertion opertaor.

// other functions

};

Explanation / Answer

/* defination outside the class*/

ostream& operator<<(ostream& out, const StudentTestScores& C) {

out << C.studentName << " " << C.numTestScores;

for(int i=0; i<C.numTestScores; i++)

out << " " << testScores[i];

// out << " "; // optional line, if you want newline character at the end

return out;

}