You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

330 lines
8.1 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<malloc.h>
#include<conio.h>
#include<ctype.h>
#define LEN sizeof(struct student)
int flag=0;//判断
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,*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);
printf("\t请输入学生大学语文成绩:");
scanf("%d",&p1->chinese);
printf("\t请输入学生大学英语成绩:");
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{
while(id!=p1->id&&p1->next!=NULL)
{
p2=p1;
p1=p1->next;
}
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);
}}
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);
printf("\t请输入学生大学语文成绩:");
scanf("%d",&p4->chinese);
printf("\t请输入学生大学英语成绩:");
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)
head=p5->next;
else
p6->next=p5->next;
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 goon()
{
printf("\n按任意键继续程序");
getch();
}
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 0.退出系统 ");
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"); //清屏
head=creat(); //创建
break;
case 2:
system("cls");
put(head); //显示信息
break;
case 3:
system("cls");
printf("请输入要查询学生的学号:");
scanf("%lld",&query_id);
head=query(head,query_id);
goon();
break;
case 4:
system("cls");
order(head,sum);
goon();
break;
case 5:
system("cls");
printf("请输入你要修改的学生的学号:");
scanf("%lld",&update_id);
head=update(head,update_id);
goon();
break;
case 6:
system("cls");
printf("请输入你要删除的学生的学号:");
scanf("%lld",&delet_id);
head=delet(head,delet_id);
goon();
break;
}
}
return 0;
}