我正在用Turbo C ++编写一个程序来创建学生记录,并根据用户命令将其修改/删除为二进制文件。
需要知道的主要班级是学生班:
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();
};
get_data()
函数存在一些问题,特别是在分配了卷号的部分中。分配编号的逻辑是:
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();
二进制文件STUDENT.DAT
已存在,但是代码在循环后不存在。它被卡住了。
请帮助