|
|
#include<stdio.h>
|
|
|
#include<stdlib.h>
|
|
|
#include<string.h>
|
|
|
#include<malloc.h>
|
|
|
#include<conio.h>
|
|
|
FILE *fp;
|
|
|
int flag; //判断
|
|
|
|
|
|
struct student
|
|
|
{
|
|
|
long long int id;
|
|
|
char name[20];
|
|
|
int math,chinese,english,sum;
|
|
|
float avg;
|
|
|
struct student *next;
|
|
|
};
|
|
|
//函数声明
|
|
|
struct student *creat(struct student *head); //数据输入
|
|
|
struct student *put(struct student *head); //数据输出显示
|
|
|
struct student *delet(struct student *head,long long int id); //数据删除
|
|
|
struct student *query(struct student *head); //数据查询
|
|
|
struct student *update(struct student *head,long long int id); //数据修改
|
|
|
struct student *order(struct student *head,int sum); //成绩排序
|
|
|
|
|
|
|
|
|
struct student * creat(struct student * head) //建立基础的学生信息库
|
|
|
{
|
|
|
struct student *p1,*p2;
|
|
|
p1=(struct student *)malloc(sizeof(struct student)); //开辟存储空间
|
|
|
printf("\t输入学生的学号为0时,停止录入.\n");
|
|
|
printf("请输入学生学号:");
|
|
|
scanf("%lld",&p1->id);
|
|
|
if(p1->id!=0)
|
|
|
{
|
|
|
printf("\t请输入学生姓名:");
|
|
|
scanf("%s",&p1->name);
|
|
|
printf("\t请输入学生高等数学成绩:");
|
|
|
scanf("%d",&p1->math);
|
|
|
if(p1->math>100||p1->math<0)
|
|
|
{
|
|
|
printf("\t满分为100,请重新输入高等数学成绩:");
|
|
|
scanf("%d",&p1->math); }
|
|
|
printf("\t请输入学生大学语文成绩:");
|
|
|
scanf("%d",&p1->chinese);
|
|
|
if(p1->chinese>100||p1->chinese<0)
|
|
|
{
|
|
|
printf("\t满分为100,请重新输入大学语文成绩:");
|
|
|
scanf("%d",&p1->chinese); }
|
|
|
printf("\t请输入学生大学英语成绩:");
|
|
|
scanf("%d",&p1->english);
|
|
|
if(p1->english>100||p1->english<0)
|
|
|
{
|
|
|
printf("\t满分为100,请重新输入大学英语成绩:");
|
|
|
scanf("%d",&p1->english); }
|
|
|
p1->avg=(p1->math+p1->english+p1->chinese)/3;
|
|
|
p1->sum=p1->math+p1->english+p1->chinese;}
|
|
|
if(flag==0) //判断链表开头
|
|
|
head=p1; //flag=0代表输入的是第一个数据 //p2的结尾所指向的地址
|
|
|
else p2->next=p1; //把它们连接起来
|
|
|
while(p1->id!=0)
|
|
|
{
|
|
|
flag=flag+1;
|
|
|
if(flag==1)
|
|
|
{
|
|
|
head=p1;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
p2->next=p1;
|
|
|
}
|
|
|
p2=p1;
|
|
|
p1=(struct student *)malloc(sizeof(struct student));
|
|
|
printf("\t输入学生的学号为0时,停止录入.\n");
|
|
|
printf("请输入学生学号:");
|
|
|
scanf("%lld",&p1->id);
|
|
|
if(p1->id!=0)
|
|
|
{
|
|
|
printf("\t请输入学生姓名:");
|
|
|
scanf("%s",&p1->name);
|
|
|
printf("\t请输入学生高等数学成绩:");
|
|
|
scanf("%d",&p1->math);
|
|
|
if(p1->math>100||p1->math<0)
|
|
|
{
|
|
|
printf("\t满分为100,请重新输入高等数学成绩:");
|
|
|
scanf("%d",&p1->math); }
|
|
|
printf("\t请输入学生大学语文成绩:");
|
|
|
scanf("%d",&p1->chinese);
|
|
|
if(p1->chinese>100||p1->chinese<0)
|
|
|
{
|
|
|
printf("\t满分为100,请重新输入大学语文成绩:");
|
|
|
scanf("%d",&p1->chinese); }
|
|
|
printf("\t请输入学生大学英语成绩:");
|
|
|
scanf("%d",&p1->english);
|
|
|
if(p1->english>100||p1->english<0)
|
|
|
{
|
|
|
printf("\t满分为100,请重新输入大学英语成绩:");
|
|
|
scanf("%d",&p1->english); }
|
|
|
p1->avg=(p1->math+p1->english+p1->chinese)/3;
|
|
|
p1->sum=p1->math+p1->english+p1->chinese;}}
|
|
|
p2=p1;
|
|
|
p1=p2->next=NULL; //链表结束标志;;
|
|
|
system("pause");
|
|
|
system("cls");
|
|
|
return (head);
|
|
|
}
|
|
|
|
|
|
struct student *put(struct student *head)
|
|
|
{
|
|
|
struct student *p2;
|
|
|
p2=head;
|
|
|
if(flag!=0)
|
|
|
do
|
|
|
{
|
|
|
printf("\n学号:%lld",p2->id);
|
|
|
printf("\n姓名:%s ",p2->name);
|
|
|
printf("高等数学:%d ",p2->math);
|
|
|
printf("大学语文:%d ",p2->chinese);
|
|
|
printf("大学英语:%d ",p2->english);
|
|
|
printf("平均分:%.2f ",p2->avg);
|
|
|
printf("总分:%d ",p2->sum);
|
|
|
p2=p2->next;
|
|
|
}while(p2!=NULL);
|
|
|
system("pause");
|
|
|
}
|
|
|
|
|
|
struct student *query(struct student *head, long long int id) //按学号查找
|
|
|
{
|
|
|
struct student *p1,*p2;
|
|
|
p1=head;
|
|
|
if(head==NULL) //空链表时返回
|
|
|
{
|
|
|
printf("/n链表为空!/n");
|
|
|
return(head);
|
|
|
}
|
|
|
else{
|
|
|
for(;p1!=NULL;)
|
|
|
{
|
|
|
if(p1->id==id)//比较输入学号是否与链表中学生学号匹配
|
|
|
{
|
|
|
printf("你查找的学生信息为:\n");
|
|
|
printf("学号:%lld ",p1->id);
|
|
|
printf("姓名:%s ",p1->name);
|
|
|
printf("高等数学:%d ",p1->math);
|
|
|
printf("大学语文:%d ",p1->chinese);
|
|
|
printf("大学英语:%d ",p1->english);
|
|
|
printf("平均分:%.2f ",p1->avg);
|
|
|
printf("总分:%d",p1->sum);
|
|
|
break;
|
|
|
}
|
|
|
else{
|
|
|
p1=p1->next;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return (head);
|
|
|
}
|
|
|
|
|
|
|
|
|
struct student *update(struct student *head,long long int id) //修改学生成绩
|
|
|
{
|
|
|
|
|
|
struct student *p4;
|
|
|
if(head==NULL) //空链表返回
|
|
|
{
|
|
|
printf("链表为空");
|
|
|
}
|
|
|
p4=head;
|
|
|
for(;p4!=NULL;)
|
|
|
{
|
|
|
if(p4->id==id)
|
|
|
{
|
|
|
printf("\t请输入学生姓名:");
|
|
|
scanf("%s",&p4->name);
|
|
|
printf("\t请输入学生高等数学成绩:");
|
|
|
scanf("%d",&p4->math);
|
|
|
if(p4->math>100||p4->math<0)
|
|
|
{
|
|
|
printf("\t满分为100,请重新输入高等数学成绩:");
|
|
|
scanf("%d",&p4->math); }
|
|
|
printf("\t请输入学生大学语文成绩:");
|
|
|
scanf("%d",&p4->chinese);
|
|
|
if(p4->chinese>100||p4->chinese<0)
|
|
|
{
|
|
|
printf("\t满分为100,请重新输入大学语文成绩:");
|
|
|
scanf("%d",&p4->chinese); }
|
|
|
printf("\t请输入学生大学英语成绩:");
|
|
|
scanf("%d",&p4->english);
|
|
|
if(p4->english>100||p4->english<0)
|
|
|
{
|
|
|
printf("\t满分为100,请重新输入大学英语成绩:");
|
|
|
scanf("%d",&p4->english); }
|
|
|
p4->avg=(p4->math+p4->english+p4->chinese)/3;
|
|
|
p4->sum=p4->math+p4->english+p4->chinese;
|
|
|
break;
|
|
|
}
|
|
|
else{
|
|
|
p4=p4->next;
|
|
|
}}
|
|
|
return head;
|
|
|
}
|
|
|
|
|
|
struct student *delet(struct student *head,long long int id) //删除学生成绩
|
|
|
{
|
|
|
struct student *p5,*p6;
|
|
|
if(head==NULL)
|
|
|
{
|
|
|
printf("此链表为空");
|
|
|
return (head);
|
|
|
}
|
|
|
p5=head;
|
|
|
while(id!=p5->id&&p5->next!=NULL) // 寻找p6 即寻找要删除的前一项
|
|
|
{
|
|
|
p6=p5;p5=p5->next;
|
|
|
}
|
|
|
if(p5->id==id)
|
|
|
{
|
|
|
if(p5==head) //当p5为第一项时
|
|
|
head=p5->next;
|
|
|
else
|
|
|
p6->next=p5->next; //当p5为中间项时
|
|
|
printf("你要删除的信息为:\n");
|
|
|
printf("\n学号:%lld",p5->id);
|
|
|
printf("\n姓名:%s ",p5->name);
|
|
|
printf("高等数学:%d ",p5->math);
|
|
|
printf("大学语文:%d ",p5->chinese);
|
|
|
printf("大学英语:%d ",p5->english);
|
|
|
printf("平均分:%.2f ",p5->avg);
|
|
|
printf("总分:%d ",p5->sum);
|
|
|
}
|
|
|
flag=flag-1; //输入数减一 为了使输出无误
|
|
|
return (head);
|
|
|
}
|
|
|
|
|
|
struct student *order(struct student *head,int sum) //排序
|
|
|
{
|
|
|
struct student *p8,*p9;
|
|
|
int n=flag,i,j;
|
|
|
int temp,temp1,temp2,temp3,temp4;
|
|
|
char temp5[20];
|
|
|
float temp6;
|
|
|
p8=head;
|
|
|
for(i=0,p8->next;i<(n-1);i++,p8=p8->next) //外循环
|
|
|
for(j=i+1,p9=p8->next;j<n;j++,p9=p9->next) //内循环
|
|
|
if(p8->sum<p9->sum) //交换值
|
|
|
{
|
|
|
temp=p9->sum;p9->sum=p8->sum;p8->sum=temp; //总分交换
|
|
|
temp1=p9->id;p9->id=p8->id;p8->id=temp1; //学号
|
|
|
temp2=p9->math;p9->math=p8->math;p8->math=temp2; //高等数学
|
|
|
temp3=p9->chinese;p9->chinese=p8->chinese;p8->chinese=temp3; //大学英语
|
|
|
temp4=p9->english;p9->english=p8->english;p8->english=temp4; //大学语文
|
|
|
temp6=p9->avg;p9->avg=p8->avg;p8->avg=temp6; //平均分
|
|
|
strcpy(temp5,p9->name);strcpy(p9->name,p8->name);strcpy(p8->name,temp5); //姓名
|
|
|
}
|
|
|
struct student *q;
|
|
|
q=head;
|
|
|
int count=1;
|
|
|
printf("排序后学生信息为:\n");
|
|
|
while(q!=NULL)
|
|
|
{
|
|
|
printf("\n第%d名",count);
|
|
|
printf("\n学号:%lld",q->id);
|
|
|
printf("\n姓名:%s ",q->name);
|
|
|
printf("高等数学:%d ",q->math);
|
|
|
printf("大学语文:%d ",q->chinese);
|
|
|
printf("大学英语:%d ",q->english);
|
|
|
printf("平均分:%.2f ",q->avg);
|
|
|
printf("总分:%d ",q->sum);
|
|
|
count++;
|
|
|
q=q->next;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void estimate(struct student *head)
|
|
|
{
|
|
|
int n=0;
|
|
|
struct student *p,*p1;
|
|
|
p=head;
|
|
|
while(p!=NULL)
|
|
|
{
|
|
|
if(p->math<60)
|
|
|
{
|
|
|
n++;
|
|
|
}
|
|
|
p=p->next;
|
|
|
}
|
|
|
if(n==0)
|
|
|
{
|
|
|
printf("本次高数无人挂科.\n");
|
|
|
}
|
|
|
if(n>0)
|
|
|
{
|
|
|
printf("本次高数挂科人数有%d人\n\n",n);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void out(struct student *head) //将链表保存到文件
|
|
|
{
|
|
|
struct student *p;
|
|
|
p=head;
|
|
|
fp=fopen("student.txt","w");
|
|
|
if(fp==NULL)
|
|
|
{
|
|
|
printf("打开文件失败!");
|
|
|
return;
|
|
|
}
|
|
|
fprintf(fp,"姓名\t学号\t高数\t语文\t英语\t平均分\t总分\t");
|
|
|
fprintf(fp,"\n");
|
|
|
while(p)
|
|
|
{
|
|
|
//输出链表节点数据到文件
|
|
|
fprintf(fp,"%s\t%lld\t%d\t%d\t%d\t%.2f\t%d\t", p->name,p->id,p->math,p->chinese,p->english,p->avg,p->sum);
|
|
|
fprintf(fp,"\n");
|
|
|
p=p->next;
|
|
|
}
|
|
|
fclose(fp);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
|
|
|
void goon()
|
|
|
{
|
|
|
printf("\n按任意键继续程序");
|
|
|
getch(); // <conic.h>文件中
|
|
|
}
|
|
|
|
|
|
void menu()
|
|
|
{
|
|
|
printf("\n\n\t\t ★★★★欢迎使用学生成绩管理系统★★★★");
|
|
|
printf("\n\n\t\t 1.新建学生成绩表 ");
|
|
|
printf("\n\n\t\t 2.输出学生成绩表 ");
|
|
|
printf("\n\n\t\t 3.按学号查找学生成绩信息 ");
|
|
|
printf("\n\n\t\t 4.按总分进行排序 ");
|
|
|
printf("\n\n\t\t 5.按学号修改学生成绩信息 ");
|
|
|
printf("\n\n\t\t 6.按学号删除学生信息 ");
|
|
|
printf("\n\n\t\t 7.高数成绩分析 ");
|
|
|
printf("\n\n\t\t 8.数据保存 ");
|
|
|
printf("\n\n\t\t 0.退出系统 ");
|
|
|
printf("\n\n\t\t ------------------------------------");
|
|
|
printf("\n\n\t\t 请您选择操作选项 ");
|
|
|
printf("\n\n\t\t ------------------------------------");
|
|
|
printf("\n\t\t 请输入您的选择(0-6):");
|
|
|
}
|
|
|
|
|
|
int main()
|
|
|
{
|
|
|
int ckey=1;
|
|
|
long long int query_id,delet_id,update_id;
|
|
|
int sum;
|
|
|
struct student *head,*p;
|
|
|
head=(struct student*)malloc(sizeof(struct student));
|
|
|
head->next=NULL;
|
|
|
while(ckey!=0)
|
|
|
{
|
|
|
system("cls"); //vc++清屏函数,包含在#include<stdlib.h>中
|
|
|
menu();
|
|
|
scanf("%d",&ckey);
|
|
|
switch(ckey)
|
|
|
{
|
|
|
case 0:
|
|
|
system("cls"); //清屏
|
|
|
printf("\n\n");
|
|
|
printf("★★★★期待您的下次使用★★★★");
|
|
|
printf("\n\n");
|
|
|
break;
|
|
|
case 1:
|
|
|
system("cls"); //清屏
|
|
|
printf("\t\t======================================================\n");
|
|
|
printf("\t\t ※欢迎进入学生信息输入系统※ \n");
|
|
|
printf("\t\t \n");
|
|
|
printf("\t\t======================================================\n");
|
|
|
head=creat(head); //创建
|
|
|
break;
|
|
|
case 2:
|
|
|
system("cls");
|
|
|
printf("\t\t======================================================\n");
|
|
|
printf("\t\t ※欢迎进入学生信息输出系统※ \n");
|
|
|
printf("\t\t \n");
|
|
|
printf("\t\t======================================================\n");
|
|
|
put(head); //显示信息
|
|
|
break;
|
|
|
case 3:
|
|
|
system("cls");
|
|
|
printf("\t\t======================================================\n");
|
|
|
printf("\t\t ※欢迎进入学生信息查询系统※ \n");
|
|
|
printf("\t\t \n");
|
|
|
printf("\t\t======================================================\n");
|
|
|
printf("请输入要查询学生的学号:");
|
|
|
scanf("%lld",&query_id);
|
|
|
head=query(head,query_id);
|
|
|
goon();
|
|
|
break;
|
|
|
case 4:
|
|
|
system("cls");
|
|
|
printf("\t\t======================================================\n");
|
|
|
printf("\t\t ※欢迎进入学生信息排名系统※ \n");
|
|
|
printf("\t\t \n");
|
|
|
printf("\t\t======================================================\n");
|
|
|
order(head,sum);
|
|
|
goon();
|
|
|
break;
|
|
|
case 5:
|
|
|
system("cls");
|
|
|
printf("\t\t======================================================\n");
|
|
|
printf("\t\t ※欢迎进入学生信息修改系统※ \n");
|
|
|
printf("\t\t \n");
|
|
|
printf("\t\t======================================================\n");
|
|
|
printf("请输入你要修改的学生的学号:");
|
|
|
scanf("%lld",&update_id);
|
|
|
head=update(head,update_id);
|
|
|
goon();
|
|
|
break;
|
|
|
case 6:
|
|
|
system("cls");
|
|
|
printf("\t\t======================================================\n");
|
|
|
printf("\t\t ※欢迎进入学生信息删除系统※ \n");
|
|
|
printf("\t\t \n");
|
|
|
printf("\t\t======================================================\n");
|
|
|
printf("请输入你要删除的学生的学号:");
|
|
|
scanf("%lld",&delet_id);
|
|
|
head=delet(head,delet_id);
|
|
|
goon();
|
|
|
break;
|
|
|
case 7:
|
|
|
system("cls");
|
|
|
printf("\t\t======================================================\n");
|
|
|
printf("\t\t ※欢迎进入学生高数分析系统※ \n");
|
|
|
printf("\t\t \n");
|
|
|
printf("\t\t======================================================\n");
|
|
|
estimate(head);
|
|
|
goon();
|
|
|
break;
|
|
|
case 8:
|
|
|
system("cls");
|
|
|
printf("将数据保存在文件中");
|
|
|
out(head);
|
|
|
goon();
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
return 0;
|
|
|
}
|
|
|
|