Question
#include #include using namespace std; #include StudentTestScore.h void isValid(StudentTestScores& obj,int); int main() { StudentTestScores std1, std2; double score=0; int index; bool tryAgain; cout < <
#include
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 "StudentTestScore.h" #include
StudentTestScores::StudentTestScores() {
studentName = nullptr; testScores = nullptr; numTestScores = 0; }
void StudentTestScores::createTestScoresArray(int size) { numTestScores = size; testScores = new double[size]; for (int i = 0; i < size; i++) testScores[i] = DEFAULT_SCORE; }
StudentTestScores::StudentTestScores(char* name, int numScores) { setnumoftest(numScores); createTestScoresArray(numScores); setStudentName(name); } void StudentTestScores::setnumoftest(int numScores) { cout << "Enter number of Test: "; cin >> numScores;
} StudentTestScores::StudentTestScores(const StudentTestScores& obj) { numTestScores = obj.numTestScores; testScores = new double[numTestScores]; for (int i = 0; i < numTestScores; i++) testScores[i] = obj.testScores[i]; }
StudentTestScores::~StudentTestScores() { delete[] studentName; delete[] testScores; }
void StudentTestScores::setTestScore(double score, int index) { testScores[index] = score; }
void StudentTestScores::setStudentName(char* name) { delete[] studentName; studentName = new char[strlen(name) + 1]; strcpy_s(studentName, strlen(name) + 1, name); }
char* StudentTestScores::getStudentName() const { cout << "Enter student name: "; cin >> studentName; return this->studentName; }
int StudentTestScores::getNumTestScores() const { return this->numTestScores; }
double StudentTestScores::getTestScore(int index) const { return this->testScores[index]; }
void StudentTestScores::display() const { cout << "Las notas del estudiante " << this->getStudentName() << " son :" << endl; for (int index = 0; index < this->getNumTestScores(); index++) { cout << this->getTestScore(index) << ","; } cout << endl; }
-----
#ifndef STUDENTTESTSCORES_H #define STUDENTTESTSCORES_H #include
Still confused on how to input the a name for std1 and std2, as well on how to make it run ( closes attempt led to a repetition of the set name question). Amount of test scores stuck at 0. Honestly don't know what to do
c++
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started