Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include #include using namespace::std; #include StudentTestScore.h void isValid(StudentTestScores& obj,int); int main() { StudentTestScores std1(Juan Casado, 3), std2(Luis Gomez, 4); double score=0; int index; bool tryAgain;

#include #include using namespace::std; #include "StudentTestScore.h" void isValid(StudentTestScores& obj,int); int main() { StudentTestScores std1("Juan Casado", 3), std2("Luis Gomez", 4); double score=0; int index; bool tryAgain;

cout << "Entre las " << std1.getNumTestScores() << " notas del estudiante: " << std1.getStudentName() << ":" << endl; for (index = 0; index < std1.getNumTestScores(); index++) { cin >> score; std1.setTestScore(score, index); } tryAgain = true; while (tryAgain) { try { isValid(std1, score); tryAgain = false; } catch (string exceptionString) { cout << exceptionString; cout << "Entre el denominador de la segunda fraccion:"; cin >> score; } std1.display(); cout << "Entre las " << std2.getNumTestScores() << " notas del estudiante: " << std2.getStudentName() << ":" << endl; for (index = 0; index < std2.getNumTestScores(); index++) { cin >> score; std2.setTestScore(score, index); } std2.display();

StudentTestScores std3(std1); std3.display(); system("pause"); return 0; } }

void isValid(StudentTestScores &obj,int score) { if ( score < 0) { string exceptionString = "ERROR: Score cant be lower than zero "; throw exceptionString; } }

--------

#include using namespace::std; #include "StudentTestScore.h" void StudentTestScores::createTestScoresArray(int size) { numTestScores = size; testScores = new double[size]; for (int i = 0; i < size; i++) testScores[i] = DEFAULT_SCORE; } StudentTestScores::StudentTestScores(string name, int numScores) { studentName = name; createTestScoresArray(numScores); }

StudentTestScores::StudentTestScores(const StudentTestScores& obj) { studentName = obj.studentName; numTestScores = obj.numTestScores; testScores = new double[numTestScores]; for (int i = 0; i < numTestScores; i++) testScores[i] = obj.testScores[i]; }

StudentTestScores::~StudentTestScores() { delete[] testScores; }

void StudentTestScores::setTestScore(double score, int index) { testScores[index] = score; }

void StudentTestScores::setStudentName(string name) { studentName = name; }

string StudentTestScores::getStudentName() const { return studentName; }

int StudentTestScores::getNumTestScores() const { return numTestScores; }

double StudentTestScores::getTestScore(int index) const { return testScores[index]; } void StudentTestScores::display() const { cout << "Las notas del estudiante " << getStudentName() << " son :" << endl; for (int index = 0; index < getNumTestScores(); index++) { cout << getTestScore(index) << ","; } cout << endl; }

-------

#ifndef STUDENTTESTSCORES_H #define STUDENTTESTSCORES_H #include using namespace std; const double DEFAULT_SCORE = 0.0; class StudentTestScores { private: string studentName; double* testScores; int numTestScores; public: void createTestScoresArray(int size);

StudentTestScores(string name, int numScores);

StudentTestScores(const StudentTestScores& obj); ~StudentTestScores();

void setStudentName(string name);

string getStudentName() const;

int getNumTestScores() const;

void setTestScore(double score, int index); double getTestScore(int index) const; void display() const;

}; #endif #pragma once

Modify code with the following requirements(C++):

1.The StudentTestScores class was removed from the string variable and changed to char * in the studentName attribute.
2.Added a Copy Constructor member function

3. The this pointer was added to return the values contained in the attributes of the class and the invocation of its member functions.

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

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

What must a creditor do to become a secured party?

Answered: 1 week ago

Question

When should the last word in a title be capitalized?

Answered: 1 week ago

Question

1. Identify and control your anxieties

Answered: 1 week ago