该系统基于C语言,运用了指针、结构体和文件读写等技术路线实现了一些功能:
包括(输入学生数据,修改学生数据,查找学生资料,排列学生数据,保存学生成绩,调出学生成绩,显示学生资料等7个功能)
1、首先,定义学生结构体:
typedef struct Link
{
int number;
char name[10];
char sex[4];
int Chinese;
int English;
int Match;
float average;
struct Link *next;
}Student;
2、初始化学生链表:
Student *InitStudent()
{
Student *Q;
Q = (Student*)malloc(sizeof(Student));
if (Q != NULL)
{
Q->next = NULL;
return Q;
}
else
return NULL;
}
3、创建学生数据表:
int CreatStudent(Student *Q)
{
int flag, n;
Student *s;
n = 0;
while (flag)
{
s = (Student*)malloc(sizeof(Student));
if (s == NULL)
{
printf("创建失败!");
return 0;
}
printf("请输入学号(输入0退回上一步):");
scanf("%d", &s->number);
if (s->number == 0)
goto endp;
if (n == s->number)
{
printf("输入学号已存在!\n");
goto end;
}
while (s->number<0)
{
getchar();
printf("\n学号不能为小于零!");
printf("\n请输入学号,输入0退回上一步:");
scanf("%d", &s->number);
}
printf("请输入姓名:");
scanf("%s", s->name);
printf("请输入性别m/w:");
scanf("%s", s->sex);
printf("请输入语文成绩:");
scanf("%d", &s->Chinese);
while (s->Chinese>100 || s->Chinese<0)
{
getchar();
printf("请输入语文成绩:");
scanf("%d", &s->Chinese);
}
printf("请输入数学成绩:");
scanf("%d", &s->Match);
while (s->Match>100 || s->Match<0)
{
getchar();
printf("请输入数学成绩:");
scanf("%d", &s->Match);
}
printf("请输入英语成绩:");
scanf("%d", &s->English);
while (s->English>100 || s->English<0)
{
getchar();
printf("请输入英语成绩:");
scanf("%d", &s->English);
}
s->average = (s->Chinese + s->English + s->Match) / 3;
n = s->number;
s->next = Q->next;
Q->next = s;
amount++;
end: printf("是否继续输入数据:1/0\n");
scanf("%d", &flag);
}
endp:printf("创建完毕!\n");
printf("输入了%d个学生", amount);
return 1;
}
4、以学号为前提查找学生数据:
Student *FindStudent(Student *Q, int x)
{
Student *q;
q = Q->next;
while (q != NULL&&q->number != x)
q = q->next;
if (q != NULL)
return q;
else
return NULL;
}
5、按科目修改学生数据:
int ModifStudent(Student *Q, int x)
{
int flag, n;
Student *q;
q = Q->next;
while (q != NULL&&q->number != x)
q = q->next;
if (q != NULL)
{
while (n)
{
printf("\n修改成绩科目:1.语文 2.英语 3.数学:");
scanf("%d", &flag);
if (flag == 1)
{
getchar();
printf("\n请输入语文成绩:");
scanf("%d", &q->Chinese);
while (q->Chinese>100 || q->Chinese<0)
{
getchar();
printf("\n请输入语文成绩:");
scanf("%d", &q->Chinese);
}
}
else if (flag == 2)
{
getchar();
printf("\n请输入数学成绩:");
scanf("%d", &q->Match);
while (q->Match>100 || q->Match<0)
{
getchar();
printf("\n请重新输入数学成绩:");
scanf("%d", &q->Match);
}
}
else if (flag == 3)
{
getchar();
printf("\n请输入英语成绩:");
scanf("%d", &q->English);
while (q->English>100 || q->English<0)
{
printf("\n请重新英语成绩:"