The short answer to your question is yes, there are better ways to accomplish the result.
The longer answer is that due to the nature of your assignment and the requirements that you have to deal specifically with memory allocation and deallocation (which, by the way, I don't see where you are deallocating the testscores for each student. You need to loop through each student before deleting it and delete the test scores array), it limits you from using things like std::vector
, which would handle all of the array issues for you.
Just to help with the memory management a bit:
struct StudentData
{
StudnetData() : studentID(0), testsArray(NULL), testAverage(0.0), courseGrade('N')
{
}
~StudentData()
{
delete [] testsArray;
}
string studentName;
int studentID;
double *testsArray; //pointer to an array of test scores
double testAverage; //calculated average test score
char courseGrade; //calculated course letter grade (A-F)
private:
StudentData(const StudentData&); // unimplemented intentionally
StudentData& operator= (const StudentData&); // unimplemented intentionally
};
Then, when you delete the student array:
delete [] allStudents;
Any tests they have will also be deleted.