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.
223 lines
5.0 KiB
223 lines
5.0 KiB
#include<stdio.h>
|
|
#include<stdlib.h>
|
|
#include<string.h>
|
|
#include<malloc.h>
|
|
int n;//学生总数
|
|
struct student
|
|
{
|
|
char id[20];
|
|
char name[20];
|
|
int math,chinese,english,sum;
|
|
float avg;
|
|
struct student *next;
|
|
};
|
|
//函数声明
|
|
struct student *creat(); //数据输入
|
|
struct student *put(struct student *head); //数据输出显示
|
|
struct student *delet(struct student *head,char *id); //数据删除
|
|
struct student *query(struct student *head,char *id); //数据查询
|
|
struct student *update(struct student *head,char *id); //数据修改
|
|
struct student *order(struct student *head,int sum); //成绩排序
|
|
|
|
int menu_select()
|
|
{
|
|
char a;
|
|
do
|
|
{
|
|
printf("\t\t ╭══════════════ ╮\n");
|
|
printf("\t\t | 学生成绩管理系统 │\n");
|
|
printf("\t\t╰═══════════════╯\n");
|
|
printf("\t\t ┌────────────────┐\n");
|
|
printf("\t\t │ 1. 信息输入 2. 显示记录 │\n");
|
|
printf("\t\t │ │\n");
|
|
printf("\t\t │ 3. 信息查询 4. 成绩排序 │\n");
|
|
printf("\t\t │ │\n");
|
|
printf("\t\t │ 5. 修改信息 6. 删除信息 │\n");
|
|
printf("\t\t │ │\n");
|
|
printf("\t\t │ 0. 退出系统 │\n");
|
|
printf("\t\t └────────────────┘\n");
|
|
printf("\t\t请您选择(0-6):");
|
|
a=getchar();
|
|
}while(a>'6'||a<'0');
|
|
return (a-'0');
|
|
}
|
|
|
|
struct student *creat()
|
|
{
|
|
struct student *head;
|
|
struct student *p1;
|
|
p1=(struct student*)malloc(sizeof(struct student));
|
|
while(p1)
|
|
{
|
|
p1=p1->next;
|
|
printf("\t现在开始输入学生信息");
|
|
printf("\t请输入学生学号;");
|
|
scanf("%s",&p1->id);
|
|
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;
|
|
}
|
|
}
|
|
|
|
|
|
struct student *put(struct student *head)
|
|
{
|
|
struct student *p2;
|
|
printf("-------------------------------------------------------------");
|
|
printf("|学号 姓名 高等数学 大学语文 大学英语 平均分 总分 | ");
|
|
printf("-------------------------------------------------------------");
|
|
p2=head;
|
|
do
|
|
{
|
|
printf("-%s",p2->id);
|
|
printf("-%s",p2->name);
|
|
printf("-%d",p2->math);
|
|
printf("-%d",p2->chinese);
|
|
printf("-%d",p2->english);
|
|
printf("-%f",p2->avg);
|
|
printf("-%d",p2->sum);
|
|
p2->next;
|
|
}while(p2!=NULL);
|
|
}
|
|
|
|
struct student *query(struct student *head,char *id)
|
|
{
|
|
struct student *p3;
|
|
p3=head;
|
|
for(;p3;p3=p3->next)
|
|
if(strcmp(p3->id,id)==0)
|
|
{
|
|
printf("%s",p3->id);
|
|
printf("%s",p3->name);
|
|
printf("%d",p3->math);
|
|
printf("%d",p3->chinese);
|
|
printf("%d",p3->english);
|
|
printf("%f",p3->avg);
|
|
printf("%d",p3->sum);
|
|
}
|
|
|
|
}
|
|
|
|
struct student *update(struct student *head,char *id)
|
|
{
|
|
struct student *p4,*p7;
|
|
p7=(struct student*)malloc(sizeof(struct student));
|
|
p4=head;
|
|
if(head==NULL)
|
|
{
|
|
printf("链表为空");
|
|
}
|
|
else{
|
|
while(p4->id!=id&&p4->next!=NULL)
|
|
{
|
|
p7=p4;
|
|
p4=p4->next;
|
|
}
|
|
if(p4->id==id)
|
|
{
|
|
p4->chinese=p7->chinese;
|
|
p4->math=p7->math;
|
|
p4->english=p7->english;
|
|
p7->sum=p7->math+p7->english+p7->chinese;
|
|
p7->avg=(p7->math+p7->english+p7->chinese)/3;
|
|
}}
|
|
}
|
|
|
|
struct student *delet(struct student *head,char *id)
|
|
{
|
|
struct student *p5,*p6;
|
|
p5=head;
|
|
if(head==NULL)
|
|
{
|
|
printf("链表为空");
|
|
}
|
|
else
|
|
{
|
|
while(id!=p5->id&&p5->next!=NULL)
|
|
{
|
|
p6=p5;
|
|
p5=p5->next;
|
|
}
|
|
if(p5->id==id)
|
|
{
|
|
if(p5==head)
|
|
head=p5->next;
|
|
else
|
|
{
|
|
p6->next=p5->next;
|
|
n=n-1;
|
|
free(p5);
|
|
}
|
|
}
|
|
else
|
|
printf("该学号不在系统中,无法操作");
|
|
}
|
|
}
|
|
|
|
struct student *order(struct student *head,int sum)
|
|
{
|
|
struct student *p8,*p9;
|
|
int t;
|
|
p8=head;
|
|
for(p8;p8!=NULL;p8->next) {
|
|
for(p9=p8->next; p9!=NULL; p9=p9->next) {
|
|
if(p8->sum>p9->sum)
|
|
{
|
|
t=p8->sum;
|
|
p8->sum = p9->sum;
|
|
p9->sum=t;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
int main()
|
|
{
|
|
int n;
|
|
struct student *head;
|
|
head=(struct student*)malloc(sizeof(struct student));
|
|
head->next=NULL;
|
|
switch(menu_select())
|
|
{
|
|
case 1:
|
|
printf("学生信息输入");
|
|
struct student *creat();
|
|
break;
|
|
case 2:
|
|
printf("学生信息显示");
|
|
struct student *put(struct student *head);
|
|
break;
|
|
case 3:
|
|
printf("学生信息查找");
|
|
struct student *query(struct student *head,char *id);
|
|
break;
|
|
case 4:
|
|
printf("学生成绩排序");
|
|
struct student *order(struct student *head,int sum);
|
|
break;
|
|
case 5:
|
|
printf("学生成绩修改");
|
|
struct student *update(struct student *head,char *id);
|
|
struct student *put(struct student *head);
|
|
break;
|
|
case 6:
|
|
printf("学生成绩删除");
|
|
struct student *delet(struct student *head,char *id);
|
|
struct student *put(struct student *head);
|
|
break;
|
|
case 0:
|
|
printf("\n\t\t谢谢使用,再见!\n");
|
|
printf("\n\t\t");
|
|
system("pause");
|
|
exit(0);
|
|
}
|
|
}
|
|
|