I am making a program in turbo C++ to create student records and modify/delete them in a binary file on user's command.
The main class that is needed to know is the student class:
class student
{
private:
int roll_no;
char name[50];
academic ac;
co_curricular cc;
void calculate();
public:
int get_data(int);
void show_data();
void show_tabular();
int ret_roll_no();
};
There is some problem with the get_data() function, specially in the part where the roll number is assigned. The logic to assign the roll number is:
student temp;
fstream fp;
roll_no = random(9000) + 1000;
//Checking if roll number is unique
fp.open("STUDENT.DAT", ios::in);
while(!fp.eof())
{
fp.read((char*)&temp, sizeof(temp));
if(roll_no == temp.ret_roll_no())
roll_no = random(9000) + 1000; //Set roll number to another random value
}
fp.close();
Binary file STUDENT.DAT already exists, but the code doesn't go after the loop. It is somehow stuck.
Please help
temp. There is no problem with taking in the input. There is something which is not allowing the loop to terminate