It's not random, it's being read from the file:
void readData() {
51 Student student;
52 ifstream read;
53 read.open("student.txt");
54 while (!read.eof()) {
55 read >> student.id;
Only when you add a new student, do you set a "new" value - but you don't check if that value has already been used! So if you read the existing students when you start up, then add a new student, you will have two students with an ID of zero (and quite possibly related info in other files which uses that ID to relate grades to students for example).
You need to find the largest existing ID, and add a student with an ID one greater than that, rather than assuming 0 is "sensible" as the next ID.