要求用C语言并结合数据结构链表编写一个学生信息管理系统
发布网友
发布时间:2022-05-25 14:53
我来回答
共1个回答
热心网友
时间:2022-06-26 05:04
//xieai999
#include <stdio.h>
typedef struct study
{
int a;
char b[10];
int c[5][1];
int total;
double pg;
}LT;
typedef struct e
{
LT *e[10];
int top;
}LY;
void creat(LY **s)
{
(*s)=(LY *)malloc(sizeof(LY));
(*s)->top=-1;
}
void pop(LT **s)
{
(*s)=(LT *)malloc(sizeof(LT));
printf("学号:");
int s1;
scanf("%d",&s1);
(*s)->a=s1;
printf("姓名:");
char s2[10];
scanf("%s",&(*s)->b);
int i=0,m=0;
for(i;i<5;i++)
{
printf("科%d:",i+1);
int x;
scanf("%d",&x);
(*s)->c[i][0]=x;
m=m+x;
}
(*s)->total=m;
(*s)->pg=(*s)->total/5.0;
}
void print(LT *s)
{
printf("学号:%d ",s->a);
printf("姓名: %s ",s->b);
int i=0;
for(i;i<5;i++)
printf("科%d:%d ",i+1,s->c[i][0]);
printf("\n总分: %d",s->total);
printf("平均分: %.01f\n",s->pg);
}
void IN(LY *s,LT *a)
{
pop(&a);
s->top++;
s->e[s->top]=a;
}
void Delete(LY *s,int a)
{
int i=0;
for(i;i<=s->top;i++)
{
if(s->e[i]->a==a)
{
LT *x;
if(i!=s->top)
{
x=s->e[i];
s->e[i]=s->e[s->top];
s->e[s->top]=x;
}
s->top--;
break;
}
}
}
void paishu(LY *s)
{
printf("1,按学好升序\n2,按总分降序\n");
int x1;
int i,j;
scanf("%d",&x1);
switch(x1)
{
case 1:
for(i=0;i<=s->top;i++)
{
for(j=0;j<s->top-i;j++)
{
LT *x;
if(s->e[j]->a<s->e[j+1]->a)
{
x=s->e[j];
s->e[j]=s->e[j+1];
s->e[j+1]=x;
}
}
}
break;
case 2:
for(i=0;i<=s->top;i++)
{
for(j=0;j<s->top-i;j++)
{
LT *x;
if(s->e[j]->total>s->e[j+1]->total)
{
x=s->e[j];
s->e[j]=s->e[j+1];
s->e[j+1]=x;
}
}
}
break;
}
}
main()
{
int k=0,j=0;
LY *A;
creat(&A);
LT *r[100]={NULL};
for(k; ;k++)
{
printf("1,新建学生数据\n2,输出学生数据\n3,增加学生数据\n4,删除学生数据\n5,排序\n6,查询\n7,按其他数字键退出\n");
int x,i=0,n,m=0;
scanf("%d",&x);
switch(x)
{
case 1:
IN(A,r[j]);
j++;
break;
case 2:
for(i=A->top;i>-1;i--)
print(A->e[A->top]);
break;
case 3:
IN(A,r[j]);
j++;
break;
case 4:
scanf("%d",&n);
Delete(A,n);
break;
case 5:
paishu(A);
break;
case 6:
printf("暂时无此功能\n");
break;
default:
m=1;
break;
}
if(m==1)
break;
}
return 0;
}
第六项功能你自己加吧 我有事情要做了