I am trying to get my program to do the following:
If the student ID for the mark to enter has already got a record in the program, then the newly entered mark will replace the previous mark corresponding to the student ID. This is essentially an update of the student mark.
At the moment, I have successfully allowed the program to create the student record, but I have no idea as to updating it.
found = linearSearch(student,id,totalStudents);
if (found!=-1)
{
cout << "Record already exists." << endl << endl;
}
else
{
recPoint = new StudentRecord;
populate(recPoint,id);
dispOne(recPoint);
student[totalStudents].studentID=recPoint->studentID;
student[totalStudents].studentMark=recPoint->studentMark;
totalStudents++;
}
Why have you dynamically allocated a temporary StudentRecord when adding a new one? You could declare one in the same place you've allocated one from the heap. It's not released back to the heap, so you leak a StudentRecord object everytime you add one.
Update might look something like:
1 2 3 4 5
int index = linearSearch(student,i d, totalStudents);
if (index >= 0)
{
student[index]->studentMark = revised_score;
}
You really should move all this Student stuff into a class and use some kind of data abstraction rather than this procedural style.