发布网友 发布时间:2022-04-22 06:02
共1个回答
热心网友 时间:2023-08-04 11:27
#include<stdio.h>
#include<string.h>
enum Scores{
ENGLISH = 0,
NETWORK = 1,
CLANGUAGE = 2,
TOTALCOURSE = 3,
AVERAGECOURSE = 4,
};
enum tableSteps{
CHECKIN = 1,
INQUAIRY = 2,
SCOREDEAL = 3,
SCORESTAT = 4,
SCORESORT = 5,
QUIT = 6,
};
typedef struct Students{
char name[20];
int score[5];
int rank;
}Students;
typedef struct Courses{
int ave;
int total;
};
void PrintTable(void)
{
printf("********************************\n");
printf(" 1 成绩数据输入 \n");
printf(" 2 学生成绩查询 \n");
printf(" 3 成绩处理 \n");
printf(" 4 成绩统计 \n");
printf(" 5 成绩排名 \n");
printf(" 6 退出 \n");
printf("********************************\n");
}
void GetStudentInfo(char *name,int *score)
{
int i;
printf("name:");
name = fgets(name,20,stdin);
printf("English NetWork Cprogram score:" );
for(i=0;i<3;i++)
{
scanf("%d",&score[i]);
}
score[3] = 0;
score[4] = 0;
}
void GetName(char* name)
{
printf("name:");
name = fgets(name,20,stdin);
}
void CheckIn(Students* p,char *name,int *score,int rank)
{
int i;
for(i=0;i<20;i++)
{
(*p).name[i] = name[i];
}
for(i=0;i<5;i++)
{
(*p).score[i] = score[i];
}
(*p).rank = rank;
}
int InquireInfo(char *name,Students p[],int num)
{
int i;
for(i=0;i<num;i++)
{
if(strcmp(p[i].name,name)==0)
{
break;
}
}
if(i>=num)
return -1;
else
return i;
}
void showInfo(Students p)
{
int i;
printf("%s",p.name);
printf("English:%d",p.score[0]);
printf("Network:%d",p.score[1]);
printf("Cprogram:%d",p.score[2]);
printf("\n");
}
void ScoreDeal(Students p[],int num)
{
int i,j;
int temp_score=0;
for(i=0;i<num;i++)
{
for(j=ENGLISH;j<TOTALCOURSE;j++)
{
temp_score += p[i].score[j];
}
p[i].score[TOTALCOURSE] = temp_score;
p[i].score[AVERAGECOURSE] = temp_score/TOTALCOURSE;
}
}
void ScoreStat(Courses p[],int num,Students s[])
{
int i,j;
int score = 0;
for(j=ENGLISH;j<TOTALCOURSE;j++)
{
for(i=0;i<num;i++)
{
score += s[i].score[j];
}
p[j].total = score;
p[j].ave = score/num;
}
}
int Quit(void)
{
return 1;
}
int main(void)
{
int i;
int table_loop = 0;
int step = 0;
int num =0;
Students studentInfo[100];
char name[20];
int score[5];
PrintTable();
while(table_loop==0)
{
printf("请选择(1-6):\n");
fflush(stdin);
step = getchar()-'0';
switch(step)
{
case CHECKIN:
fflush(stdin);
GetStudentInfo(name,score);
CheckIn(&studentInfo[num],name,score,0);
num++;
break;
case INQUAIRY:
fflush(stdin);
GetName(name);
if((i=InquireInfo(name,studentInfo,num))>=0)
{
showInfo(studentInfo[i]);
}
else
{
printf("can't find name\n");
}
break;
case SCOREDEAL:
break;
case SCORESTAT:
break;
case SCORESORT:
break;
case QUIT:
table_loop = Quit();
break;
default:
break;
}
}
}
剩下的函数自己写吧追问写完嘛,不会啊,我是C预言的白痴啊,谢谢
追答你现在还要吗