📄 400mfcdlg.cpp
字号:
do //read the tab key behind the chinese
{
if (1 != fread(rbuf, 1, 1, FH))
{
student_num--;
MessageBox("error 22\nthis line no math!");
goto go_out_read_choose_file;
}
if (0x09 == rbuf[0])
{
continue;
}
if (rbuf[0]>0 && rbuf[0]<0x20)
{
student_num--;
MessageBox("error 23\nthis line no math!");
goto go_out_read_choose_file;
}
else
{
break;
}
} while(1);
if (rbuf[0]>='A' && rbuf[0]<='C')
{
stu[student_num].math = rbuf[0];//read math
}
else
{
student_num--;
MessageBox("error 24\nthis line math isn't A-C!");
goto go_out_read_choose_file;
}
if (1 != fread(rbuf, 1, 1, FH))
{
student_num--;
MessageBox("error 25\nthis line no school!");
goto go_out_read_choose_file;
}
if (0x09 != rbuf[0])
{
student_num--;
MessageBox("error 26\nthis line math is error!");
goto go_out_read_choose_file;
}
do //read the tab key behind the math
{
if (1 != fread(rbuf, 1, 1, FH))
{
student_num--;
MessageBox("error 27\nthis line no school!");
goto go_out_read_choose_file;
}
if (0x09 == rbuf[0])
{
continue;
}
if (rbuf[0]>0 && rbuf[0]<0x20)
{
student_num--;
MessageBox("error 28\nthis line no school!");
goto go_out_read_choose_file;
}
else
{
break;
}
} while(1);
stu[student_num].school[0] = rbuf[0];
i = 1;
do //read school
{
if (1 != fread(rbuf, 1, 1, FH))
{
stu[student_num].school[i] = 0;
break;
}
if (rbuf[0]>0 && rbuf[0]<0x20)
{
if (0x09 == rbuf[0])
{
student_num--;
MessageBox("error 29\nthis line school have tab key!");
goto go_out_read_choose_file;
}
else if (0x0d == rbuf[0])
{
;
}
else if (0x0a == rbuf[0])
{
if (0x0d == stu[student_num].school[i-1])
{
stu[student_num].school[i-1] = 0;
}
else
{
stu[student_num].school[i] = 0;
}
break;
}
else
{
student_num--;
MessageBox("error 30\nthis line school have other chars!");
goto go_out_read_choose_file;
}
}
stu[student_num].school[i] = rbuf[0];
i++;
if (i > 48)
{
student_num--;
MessageBox("error 31\nthis line school is too long!");
goto go_out_read_choose_file;
}
} while(1);
if (school_num == 0)
{
school_num = 1;
strcpy(sch[school_num].school, stu[student_num].school);
sch[school_num].studentnum = 1;
sch[school_num].num[sch[school_num].studentnum] = student_num;
}
else
{
for (i=1; i<=school_num; i++)
{
if (strcmp(stu[student_num].school,sch[i].school) == 0)
{
sch[i].studentnum++;
sch[i].num[sch[i].studentnum] = student_num;
break;
}
}
if (i>school_num)//
{
school_num++;
if (school_num >= SCH_NUM_ALL)
{
student_num--;
MessageBox("error 32\nthis line school num too more!");
goto go_out_read_choose_file;
}
strcpy(sch[school_num].school,stu[student_num].school);
sch[school_num].studentnum = 1;
sch[school_num].num[sch[school_num].studentnum] = student_num;
}
}
}
go_out_read_choose_file:
fclose(FH);
if (m_bSaveMiddleFile)
{
FH = fopen("ReadByLzx.txt","w");
fprintf(FH,"序号 姓名 性别 语文 数学 生源地\n");
for (i=1; i<=student_num; i++)
{
fprintf(FH, "%d %s %s %c %c %s\n",
stu[i].NUM, stu[i].name, stu[i].sex, stu[i].chinese, stu[i].math, stu[i].school);
}
fclose(FH);
}
MessageBox("OK\nEnd to read\nPlease check the student num!");
m_address_file = dlg.GetPathName();
m_nStuNum = student_num;
UpdateData(FALSE);
}
///////////////////////////////////////////////////////////////////////////////////////////////////
void CMy400MFCDlg::OnStart()
{
// TODO: Add your control notification handler code here
CTime SysTime;
int average_class = 0;//the average of student num
int i = 0;
int j = 0;
int x = 0;
int y = 0;
int z = 0;
int peoplebuf[STU_NUM_ALL40]={0};//缓存
SysTime = CTime::GetCurrentTime();
CString CSFileNamesBuf;
srand(atoi(SysTime.Format("%m%d%H%M%S")));//the seek of rand
UpdateData(TRUE);//m_nClaNum,m_bSaveMiddleFile
if (m_nClaNum >= CLA_NUM_ALL)
{
MessageBox("error 33\nThe class num is too many!");
return;
}
if (0 == m_nClaNum)
{
MessageBox("error 34\nThe class num can not is 0 !");
return;
}
i = m_nStuNum/m_nClaNum;
if (0 == i)
{
MessageBox("error 35\nThe class num is too many\nor student num too few!");
return;
}
if (i >= 200)
{
MessageBox("error 36\nThe class num is too few\nor student num too many!");
return;
}
for (i=1; i<=(int)m_nClaNum; i++)
{
cla[i].studentnum = 0;
}
class_num = m_nClaNum;
average_class = 1;
for (x=1; x<=school_num; x++)
{
if (sch[x].studentnum > class_num*4)//think about school sex and mark
{
memset(peoplebuf,0,STU_NUM_ALL40);
for (y=1; y<=sch[x].studentnum; y++)//
{
do
{
z = rand();
z = z%sch[x].studentnum +1;
} while(peoplebuf[z] != 0);
peoplebuf[z] = y;
}
for (i=1; i<=5; i++)//mark
{
for (z=1; z<=sch[x].studentnum; z++)
{
if (0 == strcmp(stu[sch[x].num[peoplebuf[z]]].sex, "男") && FindMark(sch[x].num[peoplebuf[z]])==i)
{
cla[average_class].studentnum++;
cla[average_class].num[cla[average_class].studentnum] = sch[x].num[peoplebuf[z]];
stu[sch[x].num[peoplebuf[z]]].classnum = average_class;
stu[sch[x].num[peoplebuf[z]]].clssssign = cla[average_class].studentnum;
average_class++;
if (average_class>class_num)
{
average_class = 1;
}
}
}
}
for (i=1; i<=5; i++)//mark
{
for (z=1; z<=sch[x].studentnum; z++)
{
if (0 == strcmp(stu[sch[x].num[peoplebuf[z]]].sex, "女") && (FindMark(sch[x].num[peoplebuf[z]]) == i))
{
cla[average_class].studentnum++;
cla[average_class].num[cla[average_class].studentnum] = sch[x].num[peoplebuf[z]];
stu[sch[x].num[peoplebuf[z]]].classnum = average_class;
stu[sch[x].num[peoplebuf[z]]].clssssign = cla[average_class].studentnum;
average_class++;
if (average_class>class_num)
{
average_class = 1;
}
}
}
}
}
else if (sch[x].studentnum > class_num*2)//> class_num*2 and < class_num*5 只考虑成绩
{
memset(peoplebuf,0,STU_NUM_ALL40);
for (y=1; y<=sch[x].studentnum; y++)//
{
do
{
z = rand();
z = z%sch[x].studentnum +1;
} while(peoplebuf[z] != 0);
peoplebuf[z] = y;
}
for (i=1; i<=5; i++)//mark
{
for (z=1; z<=sch[x].studentnum; z++)
{
if (FindMark(sch[x].num[peoplebuf[z]]) == i)
{
cla[average_class].studentnum++;
cla[average_class].num[cla[average_class].studentnum] = sch[x].num[peoplebuf[z]];
stu[sch[x].num[peoplebuf[z]]].classnum = average_class;
stu[sch[x].num[peoplebuf[z]]].clssssign = cla[average_class].studentnum;
average_class++;
if (average_class>class_num)
{
average_class = 1;
}
}
}
}
}
// else if (sch[x].studentnum > class_num*3)//> class_num*3 and < class_num*5 只考虑性别
// {
// memset(peoplebuf,0,N_CLA_PEO_ALL40);
// for (y=1; y<=sch[x].studentnum; y++)//
// {
// do
// {
// z = rand();
// z = z%sch[x].studentnum +1;
// } while(peoplebuf[z] != 0);
// peoplebuf[z] = y;
// }
// for (z=1; z<=sch[x].studentnum; z++)
// {
// if (FindSex(sch[x].num[peoplebuf[z]]) == BOY)
// {
// cla[average_class].studentnum++;
// cla[average_class].num[cla[average_class].studentnum] = sch[x].num[peoplebuf[z]];
// Recordclass(sch[x].num[peoplebuf[z]], average_class, cla[average_class].studentnum);
// average_class++;
// if (average_class>class_num)
// {
// average_class = 1;
// }
// }
// }
// for (z=1; z<=sch[x].studentnum; z++)
// {
// if (FindSex(sch[x].num[peoplebuf[z]]) == GIRL)
// {
// cla[average_class].studentnum++;
// cla[average_class].num[cla[average_class].studentnum] = sch[x].num[peoplebuf[z]];
// Recordclass(sch[x].num[peoplebuf[z]], average_class, cla[average_class].studentnum);
// average_class++;
// if (average_class>class_num)
// {
// average_class = 1;
// }
// }
// }
// }
else//if the student number is less than class_num*3,then the sex\grade all wo't take into account
{
memset(peoplebuf,0,STU_NUM_ALL40);
for (y=1; y<=sch[x].studentnum; y++)//
{
do
{
z = rand();
z = z%sch[x].studentnum +1;
} while(peoplebuf[z] != 0);
peoplebuf[z] = y;
}
for (z=1; z<=sch[x].studentnum; z++)
{
cla[average_class].studentnum++;
cla[average_class].num[cla[average_class].studentnum] = sch[x].num[peoplebuf[z]];
stu[sch[x].num[peoplebuf[z]]].classnum = average_class;
stu[sch[x].num[peoplebuf[z]]].clssssign = cla[average_class].studentnum;
average_class++;
if (average_class>class_num)
{
average_class = 1;
}
}
}
}
if (m_bSaveMiddleFile)
{
CSFileNamesBuf = CString("ClaNoSignTrue-") + m_SSaveFileName;
FH = fopen(CSFileNamesBuf, "w");//分班未分学号,公平
fprintf(FH,"序号 姓名 性别 班级 暂时座号 毕业学校\n");//
for (j=1; j<=class_num; j++)//printf
{
for (i=1; i<=cla[j].studentnum; i++)
{
if (cla[j].num[i] > 0)
{
x= cla[j].num[i];
fprintf(FH,"%d %s %s %d %d %s\n",
stu[x].NUM, stu[x].name, stu[x].sex, stu[x].classnum, i, stu[x].school);
}
}
fprintf(FH,"\n\n");
}
fclose(FH);
}
//////////////////////////////////////////////////////change some student
if (NULL != ReadChange())
{
average_class = 40;
y = 1;
while (average_class != 1)
{
if (1 == y)
{
average_class--;
}
else
{
break;
}
y = 0;
for (i=1; i<=change_num; i++)
{
x = 0;
if (change[i].classnum > class_num)
{
i++;
continue;
}
for (j=1; j<=student_num; j++)
{
if (change[i].num == (unsigned int)stu[j].NUM)
{
x = j;
}
}
if (0 == x)
{
i++;
continue;
}
if (stu[x].classnum != change[i].classnum)
{
y = 1;//the sign of change
// j = stu[x].clssssign;//find the local of student at class
// if (j > cla[change[i].classnum].studentnum)//maybe the student num is not the same
// {
// j = cla[change[i].classnum].studentnum;
// }
// else
// {
j = rand()%cla[change[i].classnum].studentnum + 1;
// }
for (z=1; z<=student_num; z++)
{
if (cla[change[i].classnum].num[j] == stu[z].NUM)
{
break;
}
}
if (z > student_num)
{
i++;
continue;
}
cla[change[i].classnum].num[j] = x;//班级的该位置记录序号
cla[stu[x].classnum].num[stu[x].clssssign] = z;
stu[z].clssssign = stu[x].clssssign; //学生的座号调换
stu[x].clssssign = j;
stu[z].classnum = stu[x].classnum;//学生班级调换
stu[x].classnum = change[i].classnum;
}
}
}
if (1 == average_class)
{
MessageBox("error 37\nerror of user's logic");
}
if (m_bSaveMiddleFile)
{
FH = fopen("c:\\ReadChange.txt", "w");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -