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.
Group18/学籍管理系统步骤7.c

98 lines
2.0 KiB

#include<stdio.h>
#include<string.h>
#define N 7
struct stu_info
{
int num,cls,flag;
char name[10];
float maths,physics,english;
};
struct stu_info stu[N]={{10001,11,0,"Zhang",99.5,88.5,89.5},
{10002,12,0,"Yang",77.9,56.5,87.5},
{10003,11,0,"Liang",92.5,99.0,60.5},
{10004,11,0,"Cai",89.6,56.9,90.5},
{10005,14,0,"Fu",55.6,67.9,98.9},
{10006,12,0,"Mao",22.1,45.9,99.2},
{10007,13,0,"Zhan",35.6,67.9,88.0}};
void sort(struct stu_info *stu,int n)
{
int i,j;
struct stu_info tmp;
for(i=0;i<n;i++)
{
for(j=0;j<n-i-1;j++)
{
if(((stu+j)->cls>(stu+j+1)->cls)||((stu+j)->cls==(stu+j+1)->cls)&&((stu+j)->num>(stu+j+1)->num))
{
tmp = *(stu+j);
*(stu+j) = *(stu+j+1);
*(stu+j+1) = tmp;
}
}
}
return;
}
void fcls()
{
int start,end,i;
scanf("%d-%d",&start,&end);
for(i=0;i<N;i++)
{
if(stu[i].cls<=end&&stu[i].cls>=start)
printf("%d %d %s %.1f %.1f %.1f\n",stu[i].num,stu[i].cls,stu[i].name,stu[i].maths,stu[i].physics,stu[i].english);
}
}
void fnum()
{
int start,end,i;
scanf("%d-%d",&start,&end);
for(i=0;i<N;i++)
{
if(stu[i].num<=end&&stu[i].num>=start)
printf("%d %d %s %.1f %.1f %.1f\n",stu[i].num,stu[i].cls,stu[i].name,stu[i].maths,stu[i].physics,stu[i].english);
}
}
void fname()
{
char q[10];int i,j,flag=1;
scanf("%s",q);
for(i=0;i<N;i++)
{
for(j=0;q[j]!='*';j++)
{
if(q[j]!=stu[i].name[j])
flag=0;break;
}
if(flag)
printf("%d %d %s %.1f %.1f %.1f\n",stu[i].num,stu[i].cls,stu[i].name,stu[i].maths,stu[i].physics,stu[i].english);
flag=1;
}
}
void fsum()
{
int i;
float e;
for(i=0;i<N;i++)
{
if(stu[i].english+stu[i].maths+stu[i].physics>=e)
printf("%d %d %s %.1f %.1f %.1f\n",stu[i].num,stu[i].cls,stu[i].name,stu[i].maths,stu[i].physics,stu[i].english);
}
}
int main()
{
sort(stu,N);
int i,type;
scanf("%d",&type);
switch(type)
{
case 1:fcls();break;
case 2:fnum();break;
case 3:fname();break;
case 4:fsum();break;
}
}