|
|
|
@ -0,0 +1,163 @@
|
|
|
|
|
/*成绩打印*/
|
|
|
|
|
void PrintScore(Lnode *h)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
Lnode *p = h->next;
|
|
|
|
|
printf("%-14s%-8s%-8s%-8s%-8s%-8s\n","排名", "学号", "姓名", "数学", "英语", "数据结构", "平均绩点");
|
|
|
|
|
while (p != NULL)
|
|
|
|
|
{
|
|
|
|
|
printf("%-14s%-8s%-8d%-8d%-8d%.2f\n", p->ID, p->Name, p->Score[0], p->Score[1], p->Score[2], p->Ave_Sco);
|
|
|
|
|
p = p->next;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*成绩修改*/
|
|
|
|
|
void ModifyScore(Lnode *h)
|
|
|
|
|
{
|
|
|
|
|
Lnode *p = h->next;
|
|
|
|
|
char name[10], id[15];
|
|
|
|
|
int Math, English, Datastruct;
|
|
|
|
|
printf("请输入学生姓名:");
|
|
|
|
|
scanf("%s", name);
|
|
|
|
|
printf("请输入学生学号:");
|
|
|
|
|
scanf("%s", id);
|
|
|
|
|
|
|
|
|
|
while (p)
|
|
|
|
|
{
|
|
|
|
|
if (strcmp(p->Name, name)==0 && strcmp(p->ID, id)==0)
|
|
|
|
|
{
|
|
|
|
|
printf("当前学生信息:\n");
|
|
|
|
|
printf("%-14s%-8s%-8s%-8s%-8s\n", "学号", "姓名", "数学", "英语", "数据结构");
|
|
|
|
|
printf("%-14s%-8s%-8d%-8d%-8d\n", p->ID, p->Name, p->Score[0], p->Score[1], p->Score[2]);
|
|
|
|
|
printf("请输入更正后的数学成绩:");
|
|
|
|
|
scanf("%d", &Math);
|
|
|
|
|
printf("请输入更正后的英语成绩:");
|
|
|
|
|
scanf("%d", &English);
|
|
|
|
|
printf("请输入更正后的数据结构成绩:");
|
|
|
|
|
scanf("%d", &Datastruct);
|
|
|
|
|
p->Score[0] = Math;
|
|
|
|
|
p->Score[1] = English;
|
|
|
|
|
p->Score[2] = Datastruct;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
p = p->next;
|
|
|
|
|
}
|
|
|
|
|
}//while循环结束
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*信息查找*/
|
|
|
|
|
void FindInf(Lnode *h)
|
|
|
|
|
{
|
|
|
|
|
Lnode *p = h->next;
|
|
|
|
|
char name[10], id[15];
|
|
|
|
|
printf("请输入学生姓名:");
|
|
|
|
|
scanf("%s", name);
|
|
|
|
|
printf("请输入学生学号:");
|
|
|
|
|
scanf("%s", id);
|
|
|
|
|
|
|
|
|
|
while (p)
|
|
|
|
|
{
|
|
|
|
|
if (strcmp(p->Name, name) == 0 && strcmp(p->ID, id) == 0)
|
|
|
|
|
{
|
|
|
|
|
printf("当前学生信息:\n");
|
|
|
|
|
printf("%-14s%-8s%-8s%-8s%-8s\n", "学号", "姓名", "数学", "英语", "数据结构");
|
|
|
|
|
printf("%-14s%-8s%-8d%-8d%-8d\n", p->ID, p->Name, p->Score[0], p->Score[1], p->Score[2]);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
p = p->next;
|
|
|
|
|
}
|
|
|
|
|
}//while循环结束
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*删除*/
|
|
|
|
|
void Delete(Lnode *h)
|
|
|
|
|
{
|
|
|
|
|
Lnode *p = h, *q;
|
|
|
|
|
q = p->next;
|
|
|
|
|
char name[10], id[15];
|
|
|
|
|
printf("请输入学生姓名:");
|
|
|
|
|
scanf("%s", name);
|
|
|
|
|
printf("请输入学生学号:");
|
|
|
|
|
scanf("%s", id);
|
|
|
|
|
|
|
|
|
|
while (q)
|
|
|
|
|
{
|
|
|
|
|
if (strcmp(q->Name, name) == 0 && strcmp(q->ID, id) == 0)
|
|
|
|
|
{
|
|
|
|
|
p->next = q->next;
|
|
|
|
|
free(q); //删除p节点
|
|
|
|
|
printf("删除成功\n");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
p = p->next;
|
|
|
|
|
q = q->next;
|
|
|
|
|
}
|
|
|
|
|
}//while循环结束
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*退出系统*/
|
|
|
|
|
void Quit(Lnode *h)
|
|
|
|
|
{
|
|
|
|
|
SaveInf(h); //退出时保存信息
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*打开文件*/
|
|
|
|
|
void LoadInf(Lnode *h)
|
|
|
|
|
{
|
|
|
|
|
Lnode *p = h;
|
|
|
|
|
Lnode *q; //临时变量 用于保存从文件中读取的信息
|
|
|
|
|
FILE* file = fopen("./Information.dat", "rb");
|
|
|
|
|
if (!file)
|
|
|
|
|
{
|
|
|
|
|
printf("文件打开失败!");
|
|
|
|
|
return ;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
使用feof判断文件是否为结束要注意的问题:
|
|
|
|
|
当读取文件结束时,feof函数不会立即设置标志符为-1,而是
|
|
|
|
|
需要再读取一次后,才会设置。所以要先读一次。
|
|
|
|
|
*/
|
|
|
|
|
q = (Lnode *)malloc(sizeof(Lnode));
|
|
|
|
|
fread(q, sizeof(Lnode), 1, file);
|
|
|
|
|
while (!feof(file)) //一直读到文件末尾
|
|
|
|
|
{
|
|
|
|
|
p->next = q;
|
|
|
|
|
p = q;
|
|
|
|
|
q = (Lnode *)malloc(sizeof(Lnode));
|
|
|
|
|
fread(q, sizeof(Lnode), 1, file);
|
|
|
|
|
} //while循环结束
|
|
|
|
|
|
|
|
|
|
p->next = NULL;
|
|
|
|
|
fclose(file);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*保存信息到文件中*/
|
|
|
|
|
void SaveInf(Lnode *h)
|
|
|
|
|
{
|
|
|
|
|
Lnode *p = h->next;
|
|
|
|
|
int flag;
|
|
|
|
|
FILE* file = fopen("./Information.dat", "wb");
|
|
|
|
|
if (!file)
|
|
|
|
|
{
|
|
|
|
|
printf("文件打开失败!");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
while (p != NULL)
|
|
|
|
|
{
|
|
|
|
|
flag = fwrite(p, sizeof(Lnode), 1, file); //将p的内容写到文件中
|
|
|
|
|
if (flag != 1)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
p = p->next;
|
|
|
|
|
}
|
|
|
|
|
fclose(file);
|
|
|
|
|
}
|