STU *display_student(STU *stu_head);
STU *search_by_name(STU *stu_head, char name[]);
STU *search_by_nb(STU *stu_head, unsigned long nb);
#endif
3.store.h
#ifndef _STORE_H_
#define _STORE_H_
void save_student(STU *stu_head);
STU *init_student(STU *stu_head);
#endif
4.students.c
这个文件是本设计的核心部分,包括各个模块的实现函数,包括添加,删除,修改,查找,显示学生信息这几个模块的实现。
#include
#include "students.h"
STU *select_sort(STU *g, char flag)
{
STU *p,*q,*t,*s,*h;
h=(STU *)malloc(sizeof(STU));
h->next=g;
p=h;
while(p->next->next!=NULL)
{
for(s=p,q=p->next;q->next!=NULL;q=q->next)
{
if(flag == '1')
if(q->next->IDnext->ID)
s=q;
if(flag == '2')
if(q->next->chinesenext->chinese)
s=q;
if(flag == '3')
if(q->next->mathnext->math)
s=q;
if(flag == '4')
if(q->next->englishnext->english)
s=q;
if(flag == '5')
if(q->next->averagenext->average)
s=q;
}
if(s!=q)
{
t=s->next;
s->next=t->next;
t->next=p->next;
p->next=t;
}
p=p->next;
}
g=h->next;
free(h);
return g;
}
STU *add_student(STU *stu_head)
{
STU *stu;
STU *head = stu_head;
STU *node = stu_head;
STU *node_fd;
int sel;
ASK_STU(stu);
stu->next = NULL;
printf("请输入学生学号:");
scanf("%d", &stu->ID);
while(search_by_nb(node, stu->ID)){
printf("已经存在该学号!请重新输入一个学号:");
scanf("%d", &stu->ID);
}
printf("请输入学生名字:");
scanf("%s", stu->name);
printf("请输入该学生英语成绩:");
scanf("%f", &stu->english);
while(stu->english < 0.0 || stu->english > 100.0){
printf("输入错误,请重新输入英语成绩:");
scanf("%f", &stu->english);
}
printf("请输入该学生数学成绩:");
scanf("%f", &stu->math);
while(stu->math < 0.0 || stu->math > 100.0){
printf("输入错误,请重新输入数学成绩:");
scanf("%f", &stu->math);
}
printf("请输入该学生语文成绩:");
scanf("%f", &stu->chinese);
while(stu->chinese < 0.0 || stu->chinese > 100.0){
printf("输入错误,请重新输入数学成绩:");
scanf("%f", &stu->chinese);
}
stu->all_sub = stu->chinese+stu->math+stu->english;
stu->average = stu->all_sub/3;
if(!head){
head = stu;
return head;
}
while(node->next)
node = node->next;
node->next = stu;
head = select_sort(head, '1');
return head;
}
STU *del_all(STU *stu_head)
{
if(!stu_head)
return NULL;
del_all(stu_head->next);
free(stu_head);
stu_head = NULL;
return NULL;
}
STU *del_one(STU *stu_head, int flag)
{
STU *node = stu_head;
STU *head = stu_head;
STU *pre;
char name[10];
unsigned long ID;
if(head = NULL){
printf("没有任何学生信息!\n");
return head;
}
if(flag == '2'){
p