Basically I need to change the Two StudentType* functions to const but i know its not letting me because of the &ersand sign on the ReadStudentData function, is there anyway around this?
I am not asking for someone to do my hw just point me in right direction
it brings up a whole bunch of errors when I try to throw const in it
this is what i am trying to get (StudentType * SortStudentByName( const StudentType* student, int size);
void ReadStudentData(ifstream& infile, StudentType*& student, int& numOfStudents)
{
string firstName, lastName;
int testScore;
int count = 0;
infile >> numOfStudents;
try
{
student = new StudentType[numOfStudents];
while( infile >> firstName >> lastName >> testScore)
{
if( testScore >= 0 && testScore <=100)
{
student[count].studentName = lastName + ", " + firstName;
student[count].testScore = testScore;
count++;
}
}
numOfStudents = count;
} catch (bad_alloc)
{
cout << "Failed to allocate memory" << endl;
numOfStudents = 0;
student = NULL;
}
}
StudentType* SortStudentsByName(StudentType* student, int numStudents)
{
int startScan,
minIndex;
for (startScan = 0; startScan < (numStudents-1); startScan++)
{
minIndex = startScan;
for ( int index = startScan; index < numStudents; index++)
{
if( student[index].studentName < student[minIndex].studentName)
minIndex = index;
}
StudentType temp = student[minIndex];
student[minIndex] = student[startScan];
student[startScan] = temp;
}
cout << endl;
cout << "List of Students sorted Alphabetically "<< endl;
DisplayAllStudents(student, numStudents);
return student;
}
StudentType* SortStudentsByScore(StudentType* student, int numStudents)
{
int startScan,
minIndex;
for (startScan = 0; startScan < (numStudents-1); startScan++)
{
minIndex = startScan;
for ( int index = startScan; index < numStudents; index++)
{
if( student[index].testScore>student[minIndex].testScore)
minIndex = index;
}
StudentType temp = student[minIndex];
student[minIndex] = student[startScan];
student[startScan] = temp;
}
cout <<"List of Students sorted by Score from Highest to Lowest" << endl;
DisplayAllStudents(student, numStudents);
return student;
}