📄 xuesheng.c
字号:
# define N 38
struct student
{
long num;
char name[24];
float average;
int english;
int math;
int computer;
}t;int M=0;
void input(struct student stu[],void *buff)
{
int i;char flag='y';
for(i=0;i<N&&flag=='y';i++)
{
cleardevice();
putimage(0,0,buff,COPY_PUT);
setcolor(YELLOW);
setfillstyle(1,BLACK);
bar(50,40,150,60);
rectangle(50,40,150,60);
place(23,9);
printf("NO: ");
scanf("%ld",&stu[i].num);
bar(50,73,150,93);
rectangle(50,73,150,93);
place(23,11);
printf("NAME: ");
scanf("%s",stu[i].name);
bar(50,104,150,124);
rectangle(50,104,150,124);
place(23,13);
printf("English: ");
scanf("%d",&stu[i].english);
while(stu[i].english>100||stu[i].english<0)
{
bar(50,205,290,240);
rectangle(50,205,290,240);
place(23,20);
printf("ERROR,PLEASE TRY AGAIN!");
place(23,13);
printf("English: ");
scanf("%d",&stu[i].english);
}
bar(50,138,150,158);
rectangle(50,138,150,158);
place(23,15);
printf("Math: ");
scanf("%d",&stu[i].math);
while(stu[i].math>100||stu[i].math<0)
{
place(23,20);
printf("ERROR,PLEASE TRY AGAIN!");
place(23,15);
printf("Math: ");
scanf("%d",&stu[i].math);
}
bar(50,170,150,190);
rectangle(50,170,150,190);
place(23,17);
printf("Computer: ");
scanf("%d",&stu[i].computer );
while(stu[i].computer >100||stu[i].computer<0)
{
place(23,20);
printf("ERROR,PLEASE TRY AGAIN!");
place(23,17);
printf("Computer: ");
scanf("%d",&stu[i].computer );
}
stu[i].average=(float)(stu[i].english+stu[i].math+stu[i].computer)/3;
getchar();
bar(50,205,300,236);
rectangle(50,205,300,236);
place(23,20);
printf("Do you want to input next?y/n");
scanf("%c",&flag);
}
if(i<N-1) stu[i+1].num=0;
M=i;
}
void output(struct student stu[])
{
int i;
setcolor(YELLOW);
setfillstyle(1,BLACK);
bar(1,31,379,239);
place(20,9);
printf("NUMBER NAME ENGL MATH COMPU AVERAGE ");
for(i=0;i<M;i++)
{
place(19,10+i);
printf("%4ld",stu[i].num);
place(27,10+i);
printf("%s",stu[i].name);
place(30,10+i);
printf("%4d",stu[i].english);
place(35,10+i);
printf("%4d",stu[i].math);
place(40,10+i);
printf("%4d",stu[i].computer);
place(47,10+i);
printf("%6.2f",stu[i].average);
}
getch();
}
void sort(struct student stu[])
{
int i,j;
for(j=0;j<M-1;j++)
for(i=0;i<M-1-j;i++)
if(stu[i].average>stu[i+1].average)
{
t=stu[i];stu[i]=stu[i+1];stu[i+1]=t;
}
for(i=0;i<M;i++)
{
setcolor(YELLOW);
setfillstyle(1,BLACK);
bar(1,31,379,239);
place(20,9);
printf("NUMBER NAME ENGL MATH COMPU AVERAGE ");
for(i=0,j=0;i<M;i++,j++)
{
place(19,10+j);
printf("%4ld",stu[i].num);
place(27,10+j);
printf("%s",stu[i].name);
place(30,10+j);
printf("%4d",stu[i].english);
place(35,10+j);
printf("%4d",stu[i].math);
place(40,10+j);
printf("%4d",stu[i].computer);
place(47,10+j);
printf("%6.2f",stu[i].average);
}
getch();
}
}
void search(struct student stu[],void *buff)
{
int i,j,low,high,mid;
long n;
char flag;
do{
{
for(j=0;j<M-1;j++)
for(i=0;i<M-1-j;i++)
if(stu[i].num>stu[i+1].num)
{
t=stu[i];
stu[i]=stu[i+1];
stu[i+1]=t;
}
}
cleardevice();
putimage(0,0,buff,COPY_PUT);
setfillstyle(1,BLACK);
bar(10,40,80,60);
rectangle(10,40,80,60);
/* for(j=0;j<80;j++)
{
place(53,j);
printf("%d",j);
for(j=0;j<80;j++)
{
place(j,18);
printf("%d",j);
}
}
*/
place(18,9);
printf("NO.:");
scanf("%ld",&n);
getchar();
low=0;high=M-1;
mid=(low+high)/2;
while(low<=high&&stu[mid].num!=n)
{
if(n<stu[mid].num)
high=mid-1;
else low=mid+1;
mid=(low+high)/2;
}
if(low<=high)
{
bar(0,70,380,250);
rectangle(0,70,380,250);
place(20,11);
printf("NUMBER NAME ENGL MATH COMPU AVERAGE ");
place(19,12);
printf("%4ld",stu[mid].num);
place(27,12);
printf("%s",stu[mid].name);
place(30,12);
printf("%4d",stu[mid].english);
place(35,12);
printf("%4d",stu[mid].math);
place(40,12);
printf("%4d",stu[mid].computer);
place(47,12);
printf("%6.2f",stu[mid].average);
}
else
{ bar(270,205,345,240);
rectangle(270,205,345,240);
textcolor(RED);
outtextxy(276,225,"NO FIND!");
}
bar(10,205,270,240);
rectangle(10,205,270,240);
place(18,20);
printf("Do you want to search NEXT ?y/n");
scanf("%c",&flag);getchar();
}
while(flag=='y');
}
insert(struct student stu[])
{
char z='y';int i,j;
for(i=M;i<N&&z=='y';i++)
{
setcolor(YELLOW);
setfillstyle(1,BLACK);
bar(50,40,150,60);
rectangle(50,40,150,60);
place(23,9);
printf("No:");
scanf("%ld",&stu[i].num);
bar(50,73,150,93);
rectangle(50,73,150,93);
place(23,11);
printf("NAME: ");
scanf("%s",stu[i].name);
bar(50,104,150,124);
rectangle(50,104,150,124);
place(23,13);
printf("English: ");
scanf("%d",&stu[i].english);
bar(50,138,150,158);
rectangle(50,138,150,158);
place(23,15);
printf("Math: ");
scanf("%d",&stu[i].math);
bar(50,170,150,190);
rectangle(50,170,150,190);
place(23,17);
printf("Computer: ");
scanf("%d",&stu[i].computer );
stu[i].average=(float)(stu[i].english+stu[i].math+stu[i].computer)/3;
getchar();
bar(50,215,150,236);
rectangle(50,215,150,236);
place(23,20);
printf("Next?y/n:");
scanf("%c",&z);
if(z!='y')
{
M=i+1;
sort(stu);
}
}
}
void clear(struct student stu[])
{
int i,j;
long n;char flag='y';
for(;M!=0&&flag=='y';)
{
j=1;
setfillstyle(1,BLACK);
bar(10,40,100,60);
rectangle(10,40,100,60);
place(18,9);
printf("Number:");
scanf("%ld",&n); getchar();
for(i=0;i<M&&j;i++)
if(stu[i].num==n) j=0;
if(j==1)
{
bar(270,205,345,230);
rectangle(270,205,345,230);
textcolor(RED);
outtextxy(276,225,"NO FIND!");
}
else
{
i=i-1;
for(;i<M;i++)
stu[i]=stu[i+1];
M--;
}
setcolor(YELLOW);
setfillstyle(1,BLUE);
setfillstyle(1,BLACK);
bar(1,31,379,239);
place(20,9);
printf("NUMBER NAME ENGL MATH COMPU AVERAGE ");
for(i=0;i<M;i++)
{
place(19,10+i);
printf("%4ld",stu[i].num);
place(27,10+i);
printf("%s",stu[i].name);
place(30,10+i);
printf("%4d",stu[i].english);
place(35,10+i);
printf("%4d",stu[i].math);
place(40,10+i);
printf("%4d",stu[i].computer);
place(47,10+i);
printf("%6.2f",stu[i].average);
}
/* for(i=0;i<M;i++)
{
printf("\tNUMBER\tNAME\tENGL\tMATH\tCOMPU\tAVERAGE\n\t");
printf("\n");
printf("\t=========================================================\n\t");
printf("\n\t");
printf("%4ld\t",stu[i].num);printf("%s\t",stu[i].name);
printf("%4d\t%4d\t%4d\t%6.2f\n\t",stu[i].english,stu[i].math,stu[i].computer,stu[i].average);
printf("\n");
printf("\t=========================================================\n\t");
}*/
if(stu[0].num!=0)
{
bar(50,205,309,237);
rectangle(50,205,309,237);
place(23,20);
printf("Do you want to clear NEXT?y/n:");
scanf("%c",&flag);
}
else flag='n';
}
}
void statistics(struct student stu[])
{
int i,a1=0,a2=0,a3=0,a4=0,a5=0,j;
for(i=0;i<M;i++)
{
j=stu[i].average/10;
switch(j)
{
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:a1++;break;
case 6:a2++;break;
case 7:a3++;break;
case 8:a4++;break;
case 9:
case 10:a5++;break;
}
}
/*printf("\t TONG JI JIE GUO \n\t");
printf("===========================================================\n\t");
printf("\n");
printf("\tfenshuduan 0-59 60-69 70-79 80-89 90-100 \n\t");
printf("\n");
printf("\trenshu %d %d %d %d %d \n\t",a1,a2,a3,a4,a5);
printf("\n");
printf("\t============================================================\n\t");*/
setfillstyle(1,BLACK);
bar(0,30,380,60);
rectangle(0,30,380,60);
bar(0,60,380,250);
rectangle(0,60,380,250);
place(19,9);
printf(" 0-59 60-69 70-79 80-89 90-100 ");
place(21,11);
printf("%d",a1);
place(28,11);
printf("%d",a2);
place(37,11);
printf("%d",a3);
place(45,11);
printf("%d",a4);
place(54,11);
printf("%d",a5);
getch();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -