Question
#ifndef STUDENTTESTSCORES_H #define STUDENTTESTSCORES_H #include using namespace std; const double DEFAULT_SCORE = 0.0; class StudentTestScores { private: string studentName; // The student's name double *testScores;
#ifndef STUDENTTESTSCORES_H
#define STUDENTTESTSCORES_H
#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)
{ numTestScores = size;
testScores = new double[size];
for (int i = 0; i < size; i++)
testScores[i] = DEFAULT_SCORE; }
public:
// Constructor
StudentTestScores(string name, int numScores)
{ studentName = name;
createTestScoresArray(numScores); }
// Destructor
~StudentTestScores()
{ delete [] testScores; }
// The setTestScore function sets a specific
// test score's value.
void setTestScore(double score, int index)
{ testScores[index] = score; }
// Set the student's name.
void setStudentName(string name)
{ studentName = name; }
// Get the student's name.
string getStudentName() const
{ return studentName; }
// Get the number of test scores.
int getNumTestScores()
{ return numTestScores; }
// Get a specific test score.
double getTestScore(int index) const
{ return testScores[index]; }
};
#endif
The name of the file must be studentmain.cpp
- Download the header file StudentTestScores.h
- Carefully read the class declaration and understand how its inline functions work.
- Design a program that will use the class and allow the user to enter and read multiple students names and grades.
- Add a copy constructor, as discussed in lecture, and test your program for how the constructor will be used.
For example: The statement StudentTestScores stu2 = stu1;
Will call the copy constructor that will initialize stu2 with all the member data in stu1 including values in the testScores member array of stu1.
DO NOT make any changes in StudentTestScores class other than adding the copy constructor
DO NOT add a default constructor You do not have to use vectors
Design the output in any way you want so that you fully demonstrate the class, all its member functions, and the copy constructor for multiple of students
Hint: check how to define an array of pointers
Sample Output (as a guide)
Enter number of students: 3
Enter name of student 1: John Doe
Enter number of test scores for John Doe: 4
Test Score 1: 70
Test Score 2: 90
Test Score 3: 80
Test Score 4: 98
Enter name of student 2: Allan Smith
Enter number of test scores for Allan Smith: 3
Test Score 1: 90
Test Score 2: 83
Test Score 3: 72
Enter name of student 3: Tom Allen
Enter number of test scores for Tom Allen: 5
Test Score 1: 81
Test Score 2: 74
Test Score 3: 61
Test Score 4: 90
Test Score 5: 56
The above is not the full output. You should demonstrate the operation of other member functions and the copy constructor in the class.
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