Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

MAKE THE FILES THE MAIN.CPP AND STUDENTESTSCORES.CPP for this code. b. Add the student's name dynamically. c. Implement the operator >>, and. Show each of

MAKE THE FILES THE MAIN.CPP AND STUDENTESTSCORES.CPP for this code.


b. Add the student\'s name dynamically.

c. Implement the operator >>,

and. Show each of the operators in the main program.

// StudentTestScores.h

#ifndef STUDENTTESTSCORES_H

#define STUDENTTESTSCORES_H

#include

#include

using namespace std;

const double DEFAULT_SCORE = 0.0;

class StudentTestScores {

private:

string studentName; // The student\'s name

double *testScores; // Points to array of test scores

int numTestScores; // Number of test scores

// Private member function to create an

// array of test scores.

void createTestScoresArray(int size);

public:

// Constructor

StudentTestScores(string name, int numScores);

// Copy constructor

StudentTestScores(const StudentTestScores &obj);

// Destructor

~StudentTestScores();

// The setTestScore function sets a specific

// test score\'s value.

void setTestScore(double score, int index);

// Set the student\'s name.

void setStudentName(string name);

// Get the student\'s name.

string getStudentName() const;

// Get the number of test scores.

int getNumTestScores();

// Get a specific test score.

double getTestScore(int index) const;

// Overloaded = operator

void operator=(const StudentTestScores &right);

friend ostream &operator

friend istream &operator>>(istream &in,StudentTestScores s);

};

#endif

// StudentTestScores.cpp

#include\"StudentTestScores.h\"

void StudentTestScores::createTestScoresArray(int size)

{

this->numTestScores = size;

this->testScores = new double[size];

for (int i = 0; i

testScores[i] = DEFAULT_SCORE;

}

// Constructor

StudentTestScores::StudentTestScores(string name, int numScores)

{

this->studentName = name;

this->createTestScoresArray(numScores);

}

// Copy constructor

StudentTestScores::StudentTestScores(const StudentTestScores &obj)

{

this->studentName = obj.studentName;

this->numTestScores = obj.numTestScores;

testScores = new double[numTestScores];

for (int i = 0; i

testScores[i] = obj.testScores[i];

}

// Destructor

StudentTestScores::~StudentTestScores()

{

delete [] testScores;

}

// The setTestScore function sets a specific

// test score\'s value.

void StudentTestScores::setTestScore(double score, int index)

{

testScores[index] = score;

}

// Set the student\'s name.

void StudentTestScores::setStudentName(string name)

{

studentName = name;

}

// Get the student\'s name.

string StudentTestScores::getStudentName() const

{

return studentName;

}

// Get the number of test scores.

int StudentTestScores::getNumTestScores() {

return numTestScores;

}

// Get a specific test score.

double StudentTestScores::getTestScore(int index) const

{

return testScores[index];

}

// Overloaded = operator

void StudentTestScores::operator=(const StudentTestScores &right)

{

delete [] testScores;

this->studentName = right.studentName;

this->numTestScores = right.numTestScores;

testScores = new double[numTestScores];

for (int i = 0; i

testScores[i] = right.testScores[i];

}

ostream& operator

out

out

for(int i=1; i

out

}

return out;

}

istream& operator>>(istream &in,StudentTestScores s) {

delete[] s.testScores;

cout

in>>s.studentName;

cout

int n;

in>>n;

s.createTestScoresArray(n);

for(int i=0; i

cout

cin>>s.testScores[i];

}

}

Attachments:


Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Recommended Textbook for

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions

Question

What is the least squares estimator of ?????

Answered: 1 week ago