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.
203 lines
3.6 KiB
203 lines
3.6 KiB
#include <stdio.h>
|
|
#include <time.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
void input();
|
|
void delete1();
|
|
void select1();
|
|
void order();
|
|
void output();
|
|
void output1();
|
|
void quit();
|
|
void menu();
|
|
int sum=0;
|
|
|
|
struct stu
|
|
{
|
|
int Id;
|
|
int clas;
|
|
char name[100];
|
|
float score1;
|
|
float score2;
|
|
float score3;
|
|
float score;
|
|
}stu[1000];
|
|
int main()
|
|
{
|
|
while(1)
|
|
{
|
|
menu();
|
|
}
|
|
}
|
|
void menu()
|
|
{
|
|
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 t;
|
|
scanf("%d",&t);
|
|
switch(t)
|
|
{
|
|
case 1:input();break;
|
|
case 2:delete1();break;
|
|
case 3:select1();break;
|
|
case 4:order();break;
|
|
case 5:output();break;
|
|
case 6:quit();break;
|
|
}
|
|
}
|
|
void input()
|
|
{
|
|
sum=sum+1;
|
|
printf("Id ");
|
|
scanf("%d",&stu[sum].Id);
|
|
printf("class ");
|
|
scanf("%d",&stu[sum].clas);
|
|
printf("name ");
|
|
scanf("%s",&stu[sum].name);
|
|
printf("score1 ");
|
|
scanf("%f",&stu[sum].score1);
|
|
printf("score2 ");
|
|
scanf("%f",&stu[sum].score2);
|
|
printf("score3 ");
|
|
scanf("%f",&stu[sum].score3);
|
|
stu[sum].score=stu[sum].score3+stu[sum].score2+stu[sum].score1;
|
|
printf("continue?\n");
|
|
char a[10];
|
|
scanf("%s",&a);
|
|
if(a[0]=='y'&&a[1]=='e'&&a[2]=='s')
|
|
{
|
|
input();
|
|
}
|
|
else if(a[0]=='n'&&a[1]=='o')
|
|
{
|
|
menu();
|
|
}
|
|
}
|
|
void delete1()
|
|
{
|
|
printf("please input the id or name of the deleted person\n");
|
|
char b[100];
|
|
scanf("%s",&b);
|
|
int c=-56356,f=1,len1,len=strlen(b);
|
|
if(b[0]>'0'&&b[0]<'9')
|
|
{
|
|
c=0;
|
|
for(int k=0;k<len;k++)
|
|
{
|
|
c=c*10+b[k]-'0';
|
|
}
|
|
}
|
|
if(sum>1)
|
|
{
|
|
for(int i=1;i<=sum;i++)
|
|
{
|
|
f=1;
|
|
len1=strlen((stu[i].name));
|
|
for(int x=0;x<len1;x++)
|
|
{
|
|
if(stu[i].name[x]!=b[x])
|
|
{
|
|
f=0;
|
|
}
|
|
}
|
|
if(stu[i].Id==c||f)
|
|
{
|
|
for(int j=i;j<=sum;j++)
|
|
{
|
|
stu[j]=stu[j+1];
|
|
}
|
|
sum=sum-1;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
printf("number of people cannot be 0\n");
|
|
menu();
|
|
}
|
|
output1();
|
|
printf("continue?\n");
|
|
char a[10];
|
|
scanf("%s",&a);
|
|
if(a[0]=='y'&&a[1]=='e'&&a[2]=='s')
|
|
{
|
|
delete1();
|
|
}
|
|
else if(a[0]=='n'&&a[1]=='o')
|
|
{
|
|
menu();
|
|
}
|
|
}
|
|
void select1()
|
|
{
|
|
int b;
|
|
scanf("%d",&b);
|
|
for(int i=1;i<=sum;i++)
|
|
{
|
|
if(stu[i].Id==b||stu[i].clas==b)
|
|
{
|
|
printf("%d %d %s %.1f %.1f %.1f %.1f\n",stu[i].Id,stu[i].clas,stu[i].name,stu[i].score1,stu[i].score2,stu[i].score3,stu[i].score) ;
|
|
}
|
|
}
|
|
printf("continue?\n");
|
|
char a[10];
|
|
scanf("%s",&a);
|
|
if(a[0]=='y'&&a[1]=='e'&&a[2]=='s')
|
|
{
|
|
select1();
|
|
}
|
|
else if(a[0]=='n'&&a[1]=='o')
|
|
{
|
|
menu();
|
|
}
|
|
}
|
|
void order()
|
|
{
|
|
for(int i=1;i<=sum;i++)
|
|
{
|
|
for(int j=i;j<=sum;j++)
|
|
{
|
|
if(stu[i].clas>stu[j].clas)
|
|
{
|
|
stu[sum+1]=stu[i];
|
|
stu[i]=stu[j];
|
|
stu[j]=stu[sum+1];
|
|
}
|
|
else if(stu[i].clas==stu[j].clas)
|
|
{
|
|
if(stu[i].Id>stu[j].Id)
|
|
{
|
|
stu[sum+1]=stu[i];
|
|
stu[i]=stu[j];
|
|
stu[j]=stu[sum+1];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
output();
|
|
}
|
|
void output()
|
|
{
|
|
for(int i=1;i<=sum;i++)
|
|
{
|
|
printf("%d %d %s %.1f %.1f %.1f %.1f\n",stu[i].Id,stu[i].clas,stu[i].name,stu[i].score1,stu[i].score2,stu[i].score3,stu[i].score);
|
|
}
|
|
menu();
|
|
}
|
|
void output1()
|
|
{
|
|
for(int i=1;i<=sum;i++)
|
|
{
|
|
printf("%d %d %s %.1f %.1f %.1f %.1f\n",stu[i].Id,stu[i].clas,stu[i].name,stu[i].score1,stu[i].score2,stu[i].score3,stu[i].score);
|
|
}
|
|
}
|
|
void quit()
|
|
{
|
|
exit(0);
|
|
}
|