[u]#include <stdio.h>
#include <malloc.h>
#include <string.h>
#include <stdlib.h>
#define NULL 0
#define ok 1
#define err 0
typedef struct student
{
char name[15];
int
mathscore;
int
englishscore;
int
pcscore;
int
totalscore;
}StuInfo;
StuInfo *pStudent;
int stunum;
int inputStuInfo(void)
{
int i;
char name[15];
int
mathscore;
int
englishscore;
int
pcscore;
printf("please input the students num\n");
scanf("%d",&stunum);
pStudent=(StuInfo *)calloc(stunum,sizeof(StuInfo));
if(pStudent==NULL)
{
printf("get memory err!\n");
return err;
}
for(i = 0;i < stunum;i++)
{
printf("please input student name\n");
scanf("%s",name);
strcpy(pStudent[i].name,name);
printf("please input student mathscore\n");
scanf("%d",&mathscore);
pStudent[i].mathscore = mathscore;
printf("please input student englishscore\n");
scanf("%d",&englishscore);
pStudent[i].englishscore = englishscore;
printf("please input student pcscore\n");
scanf("%d",&pcscore);
pStudent[i].pcscore = pcscore;
pStudent[i].totalscore = mathscore + englishscore + pcscore;
}
printf("student information input over!\n");
return ok;
}
void findStuInfo(void)
{
char name[15];
int i;
printf("please input students name!");
scanf("%s",name);
for(i = 0;i < stunum;i++)
{
if(strcmp(pStudent[i].name,name)==0)
{
printf("this students mathscore is %d\n",pStudent[i].mathscore);
printf("this students englishscore is %d\n",pStudent[i].englishscore);
printf("this students pcscore is %d\n",pStudent[i].pcscore);
break;
}
}
if(i == stunum)
{
printf("can not find this student");
}
}
void findHighStu(void)
{
int major;
int i;
int maxvalue;
printf("do you want to find which major?\n");
printf("1:mathscore!\n");
printf("2:englishscore!\n");
printf("3:pcscore!\n");
printf("please input the major code\n");
scanf("%d",&major);
maxvalue = 0;
for(i = 0;i < stunum;i++)
{
if(major==1)
{
if(pStudent[i].mathscore > pStudent[maxvalue].mathscore )
{
maxvalue = i;
}
}
else if(major==2)
{
if(pStudent[i].englishscore > pStudent[maxvalue].englishscore )
{
maxvalue = i;
}
}
else if (major==3)
{
if(pStudent[i].pcscore > pStudent[maxvalue].pcscore )
{
maxvalue = i;
}
}
else
{
printf("major code is not right\n");
}
}
int aver;
aver = (pStudent[maxvalue].mathscore+ pStudent[maxvalue].englishscore+ pStudent[maxvalue].pcscore)/3;
printf("this students name is %s\n",pStudent[maxvalue].name);
printf("this students mathscore is %d\n",pStudent[maxvalue].mathscore);
printf("this students englishscore is %d\n",pStudent[maxvalue].englishscore);
printf("this students pcscore is %d\n",pStudent[maxvalue].pcscore);
printf("this students averscore is %d\n",aver);
}
void recordStuScore(void)
{
int i,j;
StuInfo t;
for(i = 0;i < stunum;i++)
{
for(j=i+1;j<stunum;j++)
{
if(pStudent[i].totalscore<pStudent[j].totalscore)
{
t=pStudent[i];
pStudent[i]=pStudent[j];
pStudent[j]=t;
}
}
}
for(i = 0;i < stunum;i++)
{
printf("num %d :",i+1);
printf("name is %s,",pStudent[i].name);
printf("mathscore is %d,",pStudent[i].mathscore);
printf("englishscore is %d,",pStudent[i].englishscore);
printf("pcscore is %d,",pStudent[i].pcscore);
printf("ave is %d\n",pStudent[i].totalscore/3);
}
}
void dispMenu(void)
{
printf("*********************************************************************\n");
printf("welcome to score manage system\n");
printf("*********************************************************************\n");
printf("1: input students information\n");
printf("2: find students information\n");
printf("3: find the students who have the highest score in which major \n");
printf("4: record students information from high to low \n");
printf("*********************************************************************\n");
}
int main(void)
{
int opercode;
static char okflag=0;
dispMenu();
printf("please input the operator code!\n");
while(1)
{
scanf("%d",&opercode);
switch(opercode)
{
case 1 : inputStuInfo();
okflag=1;
opercode= -1;
dispMenu();
break;
case 2 : if(okflag == 1)
{
findStuInfo();
opercode= -1;
dispMenu();
}
break;
case 3 : if(okflag == 1)
{
findHighStu();
opercode= -1;
dispMenu();
}
break;
case 4 : if(okflag == 1)
{
recordStuScore();
opercode= -1;
dispMenu();
}
break;
default: break;
}
}
}