Cè¯è¨ç¨åºï¼
#include <
stdio.h>
#include <
string.h>
typedef struct student
{
char name[20]; /* å§å */
int code; /*
å¦å· */
int kor, eng, math; /* 3é¨è¯¾ç¨çæ绩 */
}STUDENT;
/* è¿åè¾å
¥æ°æ® */
STUDENT Input();
/* è¾åºææè¾å
¥çæ°æ® */
void Output(STUDENT info[], int cnt);
/* å°è¾å
¥åæ°è½¬æ¢ä¸ºA-F */
char grade(int score);
int main()
{
STUDENT S[10];
int cnt = 0, select;
int i, j;
int code;
while(1)
{
printf("\tå¦çä¿¡æ¯ç®¡çç³»ç»\n\n");
printf("\t\t1\tæ·»å \n");
printf("\t\t2\tå é¤\n");
printf("\t\t3\tæ¥è¯¢\n");
printf("\t\t0\tç»æ\n");
printf("\t\tæ¨çéæ©[0-3]ï¼");
scanf("%d", &select);
if(select < 0 || select > 3)
continue;
if(select == 0)
{
printf("éåºç³»ç»!\n");
break;
}
if(select == 1) /* æ·»å */
{
S[cnt++] = Input();
}
else if(select == 2) /* å é¤ */
{
printf("\t\tå¾
å é¤å¦ççå¦å·ï¼");
scanf("%d", &code);
for(i=0; i<cnt; i++)
if(S[i].code == code)
break;
if(i >= cnt)
{
printf("å¦å·ä¸åå¨ï¼å é¤å¤±è´¥ï¼\n");
}
else {
for(j=i+1; j<cnt; j++)
{
strcpy(S[j-1].name, S[j].name);
S[j-1].code = S[j].code;
S[j-1].kor = S[j].kor;
S[j-1].eng = S[j].eng;
S[j-1].math = S[j].math;
}
cnt--;
printf("å é¤æåï¼\n");
}
}
else /* æ¥è¯¢ */
{
printf("\t\tå¾
æ¥æ¾å¦ççå¦å·ï¼");
scanf("%d", &code);
for(i=0; i<cnt; i++)
if(S[i].code == code)
break;
if(i >= cnt)
{
printf("å¦å·ä¸åå¨ï¼æ¥æ¾å¤±è´¥ï¼\n");
}
else
{
printf("\tæ¥è¯¢ç»æï¼\n");
Output(S, i);
}
}
}
return 0;
}
/* è¿åè¾å
¥æ°æ® */
STUDENT Input()
{
STUDENT stu;
printf("\t\tæ°å¦çä¿¡æ¯\n");
printf("\t\tå¦å·ï¼");
scanf("%d", &stu.code);
printf("\t\tå§åï¼");
getchar();
gets(stu.name);
printf("\t\t3é¨è¯¾ç¨æ绩(ä»¥ç©ºæ ¼åé)ï¼");
scanf("%d%d%d", &stu.kor, &stu.eng, &stu.math);
return stu;
}
/* è¾åºææè¾å
¥çæ°æ® */
void Output(STUDENT info[], int cnt)
{
printf("å¦å·ï¼%d\n",info[cnt].code);
printf("å§åï¼");
puts(info[cnt].name);
printf("æ绩ï¼%c %c %c\n", grade(info[cnt].kor), grade(info[cnt].eng), grade(info[cnt].math));
}
/* å°è¾å
¥åæ°è½¬æ¢ä¸ºA-F */
char grade(int score)
{
if(score < 0 || score > 100)
return 'F';
if(score >= 90)
return 'A';
if(score >= 80)
return 'B';
if(score >= 70)
return 'C';
if(score >=60)
return 'D';
else
return 'E';
}
è¿è¡æµè¯ï¼