I am trying to get my program to delete existing student records.
I have discovered that my program WILL NOT delete student P1001 if there are still remaining records. For example, if there are only 2 records left (P1001 and P1002), and I enter P1001 to be deleted, it will instead delete P1002. And when I delete all records, this is what it shows on the statistics (case 1):
Number of records: 0
Average mark: -1.#IND
Standard deviation: -1.#IND
Note: P1001 and P1002 are default student records.
recPoint = new StudentRecord;
delete recPoint;
totalStudents--;
you create a completely new 'StudentRecord' struct in the first line, then in the second you destroy it already... but, in the third line you still decrease your counter, so even though you haven't actually deleted anything useful, your counter still shows there being one less student, and therefore, it only appears like the second record has been deleted when really nothing but the struct that you just created was deleted!
The problem is a bit more extensive than that. You are creating a static array of StudentRecords with 30 elements (and you are only initializing the first two elements, so the other 28 elements will contain garbage). This array is fixed at 30 elements. You can't remove or add elements to this array.
Now, you could simulate adding and removing elements by initializing all elements to zero, and assuming these are 'empty' records (or initializing them to -1, or some other arbitrary value to indicate it's 'empty'), and then the act of deleting elements is simply resetting their values to 'empty' value. There are a number of problems with doing this though, and it's really just the wrong way to implement this kind of functionality.