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.
180 lines
3.1 KiB
180 lines
3.1 KiB
1 year ago
|
#include<stdio.h>
|
||
|
#include<string.h>
|
||
|
int i=0;
|
||
|
struct data
|
||
|
{
|
||
|
char num[10];
|
||
|
char clas[10];
|
||
|
char name[20];
|
||
|
float grade1;
|
||
|
float grade2;
|
||
|
float grade3;
|
||
|
float total;
|
||
|
};
|
||
|
struct data stu[100];
|
||
|
int main()
|
||
|
{
|
||
|
void menu();
|
||
|
menu();
|
||
|
}
|
||
|
void print(struct data a)
|
||
|
{
|
||
|
printf("%s %s %s %3.1f %3.1f %3.1f %3.1f",a.num,a.clas,a.name,a.grade1,a.grade2,a.grade3,a.grade1+a.grade2+a.grade3);
|
||
|
}
|
||
|
void menu()
|
||
|
{
|
||
|
void input();
|
||
|
void delet();
|
||
|
void select();
|
||
|
void order();
|
||
|
void output();
|
||
|
printf(" 1.input\n");
|
||
|
printf(" 2.delete\n");
|
||
|
printf(" 3.select\n");
|
||
|
printf(" 4.order\n");
|
||
|
printf(" 5.output\n");
|
||
|
printf(" 6.quit\n");
|
||
|
printf("please input your option\n");
|
||
|
int a;
|
||
|
scanf("%d",&a);
|
||
|
if(a==1)
|
||
|
{
|
||
|
input();
|
||
|
}
|
||
|
else if(a==2)
|
||
|
{
|
||
|
delet();
|
||
|
}
|
||
|
else if(a==3)
|
||
|
{
|
||
|
select();
|
||
|
}
|
||
|
else if(a==4)
|
||
|
{
|
||
|
order();
|
||
|
}
|
||
|
else if(a==5)
|
||
|
{
|
||
|
output();
|
||
|
}
|
||
|
else printf("\n");
|
||
|
|
||
|
|
||
|
}
|
||
|
void input()
|
||
|
{
|
||
|
void menu();
|
||
|
char a[5];
|
||
|
printf("Id ");
|
||
|
scanf("%s",stu[i].num);
|
||
|
printf("class ");
|
||
|
scanf("%s",stu[i].clas);
|
||
|
printf("name ");
|
||
|
scanf("%s",stu[i].name);
|
||
|
printf("score1 ");
|
||
|
scanf("%f",&stu[i].grade1);
|
||
|
printf("score2 ");
|
||
|
scanf("%f",&stu[i].grade2);
|
||
|
printf("score3 ");
|
||
|
scanf("%f",&stu[i].grade3);
|
||
|
stu[i].total=stu[i].grade1+stu[i].grade2+stu[i].grade3;
|
||
|
printf("continue?(yes or no)\n");
|
||
|
scanf("%s",a);
|
||
|
if(strcmp(a,"yes")==0)
|
||
|
{
|
||
|
i++;
|
||
|
input();
|
||
|
}
|
||
|
else menu();
|
||
|
}
|
||
|
void delet()
|
||
|
{
|
||
|
void menu();
|
||
|
char a[10];
|
||
|
char b[10];
|
||
|
printf("请输入要删除的学生学号或者姓名 ");
|
||
|
scanf("%s",a);
|
||
|
struct data temp;
|
||
|
for(int j=0;j<i+1;j++)
|
||
|
{
|
||
|
if(strcmp(a,stu[j].num)==0||strcmp(a,stu[j].name)==0)
|
||
|
{
|
||
|
stu[j]=stu[i];
|
||
|
i--;
|
||
|
}
|
||
|
if(i==0) break;
|
||
|
}
|
||
|
printf("continue?(yes or no)\n");
|
||
|
scanf("%s",b);
|
||
|
if(strcmp(b,"yes")==0&&i!=0)
|
||
|
delet();
|
||
|
else menu();
|
||
|
}
|
||
|
void select()
|
||
|
{
|
||
|
void menu();
|
||
|
void print(struct data a);
|
||
|
char a[10];
|
||
|
char b[10];
|
||
|
printf("请输入要查询的学生的学号或班级 ");
|
||
|
scanf("%s",a);
|
||
|
for(int j=0;j<i+1;j++)
|
||
|
{
|
||
|
if(strcmp(stu[j].num,a)==0||strcmp(stu[j].clas,a)==0)
|
||
|
print(stu[j]);
|
||
|
printf("\n");
|
||
|
}
|
||
|
printf("continue?(yes or no)\n");
|
||
|
scanf("%s",b);
|
||
|
if(strcmp(b,"yes")==0&&i!=0)
|
||
|
select();
|
||
|
else menu();
|
||
|
|
||
|
}
|
||
|
void order()
|
||
|
{
|
||
|
struct data temp;
|
||
|
void menu();
|
||
|
for(int j=0;j<i+1;j++)
|
||
|
{
|
||
|
for(int p=j+1;p<i+1;p++)
|
||
|
{
|
||
|
if(strcmp(stu[j].clas,stu[p].clas)>0)
|
||
|
{
|
||
|
temp=stu[j];
|
||
|
stu[j]=stu[p];
|
||
|
stu[p]=temp;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
for(int j=0;j<i+1;j++)
|
||
|
{
|
||
|
for(int p=j+1;p<i+1;p++)
|
||
|
{
|
||
|
if(stu[j].total<stu[p].total&&strcmp(stu[j].clas,stu[p].clas)==0)
|
||
|
{
|
||
|
temp=stu[j];
|
||
|
stu[j]=stu[p];
|
||
|
stu[p]=temp;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
for(int j=0;j<i+1;j++)
|
||
|
{
|
||
|
print(stu[j]);
|
||
|
printf("\n");
|
||
|
}
|
||
|
menu();
|
||
|
}
|
||
|
void output()
|
||
|
{
|
||
|
void print(struct data a);
|
||
|
void menu();
|
||
|
for(int j=0;j<i+1;j++)
|
||
|
{
|
||
|
print(stu[j]);
|
||
|
printf("\n");
|
||
|
}
|
||
|
menu();
|
||
|
}
|