班级学生成绩管理系统

#include
#include
#include
#include
int shoudsave=0; //判断是否有过改动痕迹的相关数
struct student
{
char num[10]; //学号
char name[20]; //姓名
char sex[4]; //性别
int age; //年龄
char Class[4]; //班级
char tele[11]; //电话
int computer; //计算机成绩
int math; //数学成绩
int English; //英语成绩
int totle; //总成绩
};
typedef struct Lnode
{
struct student data;
struct Lnode *next;
}LNode,*LinkList;
void menu()
{
printf("********************************************************\n");
printf("* 欢进迎入学生成绩管理系统 *\n");
printf("* *\n");
printf("* 1:表示输入学生资料 *\n");
printf("* 2:表示删除学生资料 *\n");
printf("* 3:表示查询学生资料 *\n");
printf("* 4:表示修改学生资料 *\n");
printf("* 5:表示显示学生资料 *\n");
printf("* 6:表示排序学生成绩 *\n");
printf("* 7:表示保存学生资料 *\n");
printf("* 8:表示获取帮助信息 *\n");
printf("* 0:表示退出系统 *\n");
printf("* *\n");
printf("********************************************************\n");
}
void Disp(LinkList L) //显示学生成绩资料
{
int count=0;
LNode *p;
p=L->next;
if (!p)
{
printf("\n=====>不好意思!没有资料可以显示!\n");
return;
}
printf("\t\t\t\t显示结果\n");
printf("------------------------------------------------------------------------------\n");
printf("学号\t姓名\t性别\t年龄\t班级\t电话\t计算机\t数学\t英语\t总成绩\n");
while (p)
{
printf("%s\t%s\t%s\t%d\t%s\t%s\t%d\t%d\t%d\t%d\n",p->data.num,p->https://www.360docs.net/doc/ce8003460.html,,p->data.sex,p->data.age,p->data.Class,p->data.tele,p->https://www.360docs.net/doc/ce8003460.html,puter,p->data.math,p->data.English,p->data.totle);
p=p->next;
}
printf("------------------------------------------------------------------------------\n");
}
void Add(LinkList L) //增加学生
{
LNode *p,*r,*s;
char num[10];
r=L;
s=L->next;
while (r->next!=NULL)
r=r->next; //将指针置于最末尾
while (1)
{
printf("请你输入学号(输入'0'返回上一级菜单:)");
scanf("%s",num);
if (strcmp(num,"0")==0)
break;
while (s)
{
if (strcmp(s->data.num,num)==0)
{
printf("=====>学号

为'%s'的学生已经存在,若要修改请你选择'4 修改'!\n",num);
printf("------------------------------------------------------------------------------\n");
printf("学号\t姓名\t性别\t年龄\t班级\t电话\t计算机\t数学\t英语\t总成绩\n");
printf("%s\t%s\t%s\t%d\t%s\t%s\t%d\t%d\t%d\t%d\n",s->data.num,s->https://www.360docs.net/doc/ce8003460.html,,s->data.sex,s->data.age,s->data.Class,s->data.tele,s->https://www.360docs.net/doc/ce8003460.html,puter,s->data.math,s->data.English,s->data.totle);
printf("------------------------------------------------------------------------------\n");
printf("\n");
return;
}
s=s->next;
}
p=(LNode *)malloc(sizeof(LNode));
strcpy(p->data.num,num);
printf("请你输入姓名:");
scanf("%s",p->https://www.360docs.net/doc/ce8003460.html,);
printf("请你输入性别:");
scanf("%s",p->data.sex);
printf("请你输入年龄:");
scanf("%d",&p->data.age);
printf("请你输入班级:");
scanf("%s",p->data.Class);
printf("请你输入电话:");
scanf("%s",p->data.tele);
printf("请你输入计算机成绩:");
scanf("%d",&p->https://www.360docs.net/doc/ce8003460.html,puter);
printf("请你输入数学成绩:");
scanf("%d",&p->data.math);
printf("请你输入英语成绩:");
scanf("%d",&p->data.English);
p->data.totle=p->https://www.360docs.net/doc/ce8003460.html,puter+p->data.math+p->data.English;
p->next=NULL;
r->next=p;
r=p;
shoudsave=1;
}
}
LNode* Locate(LinkList L,char findmess[],char nameornumorClass[]) //该函数用于定位连表中符合要求的接点,并返回该指针
{
LNode *p;
if (strcmp(nameornumorClass,"num")==0) //按学号查询
{
p=L->next;
while (p)
{
if (strcmp(p->data.num,findmess)==0)
return p;
p=p->next;
}
}
else if (strcmp(nameornumorClass,"name")==0) //按姓名查询
{
p=L->next;
while (p)
{
if (strcmp(p->https://www.360docs.net/doc/ce8003460.html,,findmess)==0)
return p;
p=p->next;
}
}
return 0;
}
void Del(LinkList L) //删除
{
int sel;
LNode *p,*r;
char findmess[20];
if (!L->next)
{
printf("\n=====>很抱歉!没有资料可以删除!\n");
return;
}
printf("\n=====>1按学号删除\n=====>2按姓名删除\n");
scanf("%d",&sel);
if (sel==1)
{
printf("请你输入要删除的学号:");
scanf("%s",findmess);
p=Locate(L,findmess,"num");
if (p)
{
r=L;
while (r->next!=p)
r=r->next;
r->next=p->next;
free(p);
printf("\n=====>恭喜你,该学生已经成功删除!\n");
shoudsave=1;
}
else
printf("\n=====>很抱歉!没有找到该

学生!\n");
}
else if (sel==2)
{
printf("请你输入要删除的姓名:");
scanf("%s",findmess);
p=Locate(L,findmess,"name");
if (p)
{
r=L;
while (r->next!=p)
r=r->next;
r->next=p->next;
free(p);
printf("\n=====>恭喜你,该学生已经成功删除!\n");
shoudsave=1;
}
else
printf("\n=====>很抱歉!没有找到该学生!\n");
}
else
printf("\n=====>对不起,你输入错误!\n");
}
void Qur(LinkList L) //查询学生
{
int sel;
char findmess[20];
LNode *p;
if (!L->next)
{
printf("\n=====>对不起,没有资料可以查询!\n");
return;
}
printf("\n=====>1按学号查询\n=====>2按姓名查询\n");
scanf("%d",&sel);
if (sel==1)//学号
{
printf("请你输入要查询的学号:");
scanf("%s",findmess);
p=Locate(L,findmess,"num");
if (p)
{
printf("恭喜你,查询成功!\n");
printf("你所查询学生的信息为:\n");
printf("------------------------------------------------------------------------------\n");
printf("学号\t姓名\t性别\t年龄\t班级\t电话\t计算机\t数学\t英语\t总成绩\n");
printf("%s\t%s\t%s\t%d\t%s\t%s\t%d\t%d\t%d\t%d\n",p->data.num,p->https://www.360docs.net/doc/ce8003460.html,,p->data.sex,p->data.age,p->data.Class,p->data.tele,p->https://www.360docs.net/doc/ce8003460.html,puter,p->data.math,p->data.English,p->data.totle);
printf("------------------------------------------------------------------------------\n");
}
else
printf("\n=====>很抱歉!没有找到该学生!\n");
}
else if (sel==2) //姓名
{
printf("请你输入要查询的姓名:");
scanf("%s",findmess);
p=Locate(L,findmess,"name");
if (p)
{
printf("恭喜你,查询成功!\n");
printf("你所查询学生的信息为:\n");
printf("------------------------------------------------------------------------------\n");
printf("学号\t姓名\t性别\t年龄\t班级\t电话\t计算机\t数学\t英语\t总成绩\n");
printf("%s\t%s\t%s\t%d\t%s\t%s\t%d\t%d\t%d\t%d\n",p->data.num,p->https://www.360docs.net/doc/ce8003460.html,,p->data.sex,p->data.age,p->data.Class,p->data.tele,p->https://www.360docs.net/doc/ce8003460.html,puter,p->data.math,p->data.English,p->data.totle);
printf("------------------------------------------------------------------------------\n");
}
else
printf("\n=====>很抱歉!没有找到该学生!\n");
}
else
printf("\n=====>对不起,你输入错误!\n");
}
void Modify(LinkList L) //修改成绩函数
{
LNode *p;
char findmess[20];
if (!L->next)
{
printf("\n=====>对不起,没有资料可以修改!\n");
return;
}
printf("请

你输入要修改的学生学号:");
scanf("%s",findmess);
p=Locate(L,findmess,"num");
if (p)
{
printf("请你输入新的计算机成绩(原来是%d分):",p->https://www.360docs.net/doc/ce8003460.html,puter);
scanf("%d",&p->https://www.360docs.net/doc/ce8003460.html,puter);
printf("请你输入新的数学成绩(原来是%d分):",p->data.math);
scanf("%d",&p->data.math);
printf("请你输入新的英语成绩(原来是%d分):",p->data.English);
scanf("%d",&p->data.English);
p->data.totle=p->https://www.360docs.net/doc/ce8003460.html,puter+p->data.math+p->data.English;
printf("\n=====>提示:资料修改成功!\n");
shoudsave=1;
}
else
printf("\n=====>很抱歉,没有找到该学生!\n");
}
void sort(LinkList &L) //排序函数
{
LinkList t1, t2;
t2 =L->next;
while (t2)
{
t1 = L->next;
while (t1 && t1->next)
{
if (t1->data.totle < t1->next->data.totle) //排序主体部分
{
struct student s = t1->data;
t1->data = t1->next->data;
t1->next->data = s;
}
t1 = t1->next;
}
t2 = t2->next;
}
printf("排序的结果为:\n");
Disp(L);
}
void Save(LinkList L) //保存
{
FILE* fp;
LNode *p;
int flag=1,count=0;
fp=fopen("student","wb");
if (fp==NULL)
{
printf("\n=====>重新打开文件时发生错误!\n");
exit(1);
}
p=L->next;
while (p)
{
if (fwrite(p,sizeof(LNode),1,fp)==1)
{
p=p->next;
count++;
}
else
{
flag=0;
break;
}
}
if (flag)
{
printf("\n=====>恭喜你!文件保存成功.(有%d条记录已经保存.)\n",count);
shoudsave=0;
}
printf("保存的记录为:\n");
Disp(L);
fclose(fp);
}
void main() //主函数
{
LinkList L;//连表
FILE *fp; //文件指针
int sel;
char ch;
int count=0;
LNode *p,*r;
printf("\t\t\t\t学生成绩管理系统\n\t\t\t-------------------------------\n");
L=(LNode*)malloc(sizeof(LNode));
L->next=NULL;
r=L;
fp=fopen("student","ab+");
if (fp==NULL)
{
printf("\n=====>对不起,文件不能打开!\n");
exit(0);
}
printf("\n=====>文件已经打开,正在导入记录......\n");
while (!feof(fp))
{
p=(LNode*)malloc(sizeof(LNode));
if (fread(p,sizeof(LNode),1,fp)==1) //将文件的内容放入接点中
{
p->next=NULL;
r->next=p;
r=p; //将该接点挂入连中
count++;
}
}
fclose(fp); //关闭文件
printf("\n=====>记录导入完毕,共导入%d条记录.\n",count);
menu();
while (1)
{
printf("请你选择操作:");
scanf("%d",&sel);
if (sel==0)
{


if (shoudsave==1)
{
getchar();
printf("\n=====>资料已经改动,是否将改动保存到文件中(y/n)?\n");
scanf("%c",&ch);
if (ch=='y'||ch=='Y')
Save(L);
}
printf("\n=====>你已经退出系统,再见!\n");
break;
}
switch (sel)
{
case 1:
Add(L);
break; //增加学生
case 2:
Del(L);
printf("删除后的结果为:\n");
Disp(L);
break;//删除学生
case 3:
Qur(L);
break;//查询学生
case 4:
Modify(L);
printf("修改后的结果为:\n");
Disp(L);
break;//修改学生
case 5:
Disp(L);
break;//显示学生
case 6:
sort(L);
break;//从大到小的排序
case 7:
Save(L);
break;//保存学生
case 8:
printf("\t\t\t==========帮助信息==========\n");
menu();
break;
default:
printf("\n=====>对不起,你输入错误!\n");
break;
}
}
while (L) //释放链表L(不是L)所占用的内存!
{
p = L;
L = L->next;
free(p);
}
}

相关文档
最新文档