char Insert()
{
int Password();
char _Print();
float _Sort(struct Student * q);
char _Ts(char x);
char a;
FILE * fp;
q = s;
MessageBoxA(NULL, MsgForBengin, "欢迎", MB_OK);
fopen_s(&fp, "D:\\DateofInsert.mce", "ab+");
if (!fp)
{
MessageBoxA(NULL, "D盘写入错误,请检查D盘是否被保护","抱歉", MB_OK);
exit(0);
}
if (!Password())
{
if(!Password())
{
MessageBoxA(NULL, "账号不存在","关闭提醒", MB_OK);
exit(0);
}
}
for (int i = 0; i<P; i++)
{
Sleep(250);
printf("请输入第%d个学生的数据\n", i + 1);
printf_s("学号:");
scanf_s("%s", s[i].ID,5);
printf_s("\n姓名:");
scanf_s("%s", s[i].name, 6);
printf_s("\n语文:");
scanf_s("%f", &s[i].mark[0], 1);
printf_s("\n数学:");
scanf_s("%f", &s[i].mark[1], 1);
printf_s("\n英语:");
scanf_s("%f", &s[i].mark[2], 1);
}
printf("\n");
printf("请输入将要进行的操作:\n");
printf("\tA,将学生信息按总成绩高低来进行排列,并写入文件中\n\tB,计算机功能\n\tC,打印出所有已经处理的信息\n");
while (1)
{
scanf_s("%c", &a,1);
switch (_Ts(a))
{
case 'A':_Sort(q); break;
case 'C':_Print(); break;
}
}
fclose(fp);
return 0;
}
char _Ts(char x)
{
char y;
if (x >= 97 && x <= 122)
{
y = x - 32;
}
else
{
y = x;
}
return y;
}
int Password()
{
char a[7];
char b[30];
int s, k, y = 1;
FILE * fp1;
fopen_s(&fp1,"D:\\Dateofresgistor.mce", "rb");
if (!fp1)
{
MessageBoxA(NULL, "D盘写入错误,请检查D盘是否被保护", "抱歉", MB_OK);
y = 0;
exit(0);
}
int i, j = 0;
printf(" 请输入用户名:");
scanf_s("%s", b,7);
for (int m = 1; m<100; m++)
{
fread(sx.s, 7, 1, fp1);
fseek(fp1, 7, SEEK_CUR);
if (strcmp(b, sx.s) == 0)
{
k = m;
s = 1;
break;
}
else
{
s = 0;
}
}
if (!s)
{
printf(" 账号不存在!\n");
y = 0;
return y;
}
printf("\n");
printf(" 请输入密码:");
while (1)
{
for (i = 0; i<10; i++)
{
a[i] = _getch();
if (a[i] == '\r')
{
break;
}
if (a[i] != 8)
{
printf("*");
}
}
a[i] = '\0';
getchar();
fseek(fp1, 0, SEEK_SET);
for (int e = 1; e<k + 1; e++)
{
fread(sx.s, sizeof(sx.s), 1, fp1);
fread(sx1.x, sizeof(sx1.x), 1, fp1);
}
if ((strcmp(b, sx.s) == 0) && (strcmp(a, sx1.x) == 0))
{
printf("\n\n\t用户名密码输入正确\n");
Sleep(100);
printf(" 欢");
Sleep(100);
printf("迎");
Sleep(100);
printf("使");
Sleep(100);
printf("用");
Sleep(200);
printf(".");
Sleep(200);
printf(".");
Sleep(200);
printf(".\n");
y = 1;
system("cls"); break;
}
else
{
y = 0;
}
if (!y)
{
printf("\n密码错误!\n");
printf("密码:");
}
}
fclose(fp1);
return y;
}
float _Sort(struct Student *q)
{
FILE * fp;
int i, j, k;
fopen_s(&fp,"D:\\Sort.mce", "wb");
if (!fp)
{
MessageBoxA(NULL, "D盘写入错误,请检查D盘是否被保护", "抱歉", MB_OK);
exit(0);
}
for (int u = 0; u<3; u++)
{
s[u].sum = s[u].mark[0] + s[u].mark[1] + s[u].mark[2];
}
for (i = 0; i<P; i++)
{
k = i;
for (j = i + 1; j<N; j++)
{
if ((q+k)->sum<(q+j)->sum)
{
k = j;
t = *(q + k);
*(q + k) = *(q + i);
*(q + i) = t;
}
}
}
for (int y = 0; y<3; y++)
{
fwrite(&s[y], sizeof(struct Student), 4, fp);
}
printf("请稍等");
Sleep(100);
printf(".");
Sleep(100);
printf(".");
Sleep(100);
printf(".\n");
printf("\n");
printf("操作成功!");
Sleep(1500);
system("cls");
fclose(fp);
printf("\tA,将学生信息按总成绩高低来进行排列,并写入文件中\n\tB,计算机功能\n\tC,打印出所有已经处理的信息\n");
printf("\t请再次输入所求选项\n");
return 0;
}
char _Print()
{
FILE * fp;
fopen_s(&fp, "D:\\Sort.mce", "rb");
if (!fp)
{
MessageBoxA(NULL, "D盘写入错误,请检查D盘是否被保护", "抱歉", MB_OK);
exit(0);
}
printf_s("学号 姓名 语文 数学 英语\n");
for (int w = 0; w < P; w++)
{
fread(&s[w], sizeof(struct Student),4, fp);
printf_s("%s %s %f %f %f", s[w].ID, s[w].name, s[w].mark[0], s[w].mark[1], s[w].mark[2]);
printf_s("\n");
}
fclose(fp);
return 0;
}