Fill This Form To Receive Instant Help

Help in Homework
trustpilot ratings
google ratings


Homework answers / question archive / Please fix this code in C++ 1

Please fix this code in C++ 1

Computer Science

Please fix this code in C++

1. Implement the assign (* this) operator.

2. Add the student's name dynamically.

3. Implement the >> (istream) and (ostream) << operators

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

++++++++++++++++++++++++++

//Students TestScores.h

#ifndef STUDENTTESTSCORES_H

#define STUDENTTESTSCORES_H

#include <string>

using namespace::std;

const double DEFAULT SCORE = 0.0;

class StudentTestScores {

private:

string *studentName;

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

int numTestScores;

void create TestScoresArray(int size);

public:

StudentTestScores(string name, int numScores);

StudentTestScores(const StudentTestScores& obj);

~StudentTestScores();

void setTestScore(double score, int index);

void setStudentName(string name);

string getStudentName() const;

int getNumTestScores();

double getTestScore(int index) const;

void operator=(const StudentTestScoresé& right);

friend ostream& operator <<(ostream& strm, const StudentTestScores& obj);

friend istream& operator >>(istream& strm, StudentTestScores& obj);

};

#endif

+++++++++++++++

//StudentTestScores.cpp

#include <string>

using namespace::std;

#include "StudentTestScores.h"

void StudentTestScores::createTestScoresArray(int size) {

this->numTestScores = size;

this->testScores = new double[size];

for (int i = 0; i < size; i++)

testScores|i] = DEFAULT SCORE;

}

StudentTestScores::StudentTestScores(string name, int numScores) {

this->studentName = name;

this->create TestScoresArray(numScores);

}

StudentTestScores::StudentT estScores(const StudentTestScores & obj) {

this->studentName = obj.studentName;

this->numTestScores = obj.numTestScores;

testScores = new double[numT estScores];

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

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

}

StudentTestScores::~StudentTestScores() {

delete[] testScores;

}

void StudentTestScores::set TestScore(double score, int index) {

testScores[index] = score;

}

void StudentTestScores::setStudentName(string name) {

studentName = name;

}

string StudentTestScores::getStudentName() const {

return studentName;

}

int StudentTestScores::getNumTestScores() {

return numTestScores;

}

double StudentTestScores::getTestScore(int index) const {

return testScores|[index];

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

delete[] testScores;

this->studentName = right.studentName;

this->numTestScores = right.numTestScores;

testScores = new double[numT estScores];

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

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

}

istream& operator>>(istream& strm, StudentTestScores& obj) {

string name;

cout << "Enter student name: ";

getline(strm, name);

obj.setStudentName(name);

int n = obj.getNumTestScores();

double score = 0.0;

for (int i = 0; 1 < n; ++i)

{

cout << "Enter test " << (i+ 1) <<" score: ";

sirm >> score;

obj.setTestScore(score, 1);

}

return strm;

}

ostream& operator<<(ostream& strm, const StudentTestScores& obj) {

cout << "[Student Details]";

strm << "Student Name: " << obj.getStudentName() << endl;

int n = obj.getNumTestScores();

strm << "Number of test scores: " << n << endl;

for (int i = 0; | < n; +41)

{

strm << "Test Score " << (i+ 1) << "=" << obj.getTestScore(i) << endl;

}

strm << endl:

return strm;

}

+++++++++++++++++++++++

//StudentTestScoresMain.cpp

#include <iostream>

#include "StudentT estScores.h"

using namespace std;

void displayStudent(StudentTestScores);

int main() {

StudentTestScores student1("Kelly Thorton", 3);

student1.setTestScore(100.0, 0);

student1.setTestScore(95.0, 1);

student! .setlTestScore(80, 2);

StudentTestScores student2("Jimmy Griffin", 5);

student2 = student1;

displayStudent(student1);

displayStudent(student2);

return 0;

}

 

Purchase A New Answer

Custom new solution created by our subject matter experts

GET A QUOTE