学生成绩管理系统

实现学生成绩的输入,输出,查询,排序,插入,修改。

#include

#include
#include


int count=0;
struct student
{
char name[10];
int id;
int math;
int china;
};
typedef struct student STU;


void show()
{
system("clear");
printf("************************************\n\n");
printf("*****WELCOME TO TEACHER SYSTEM******\n\n");
printf("************************************\n\n");
sleep(2);
system("clear");
}


void PrintInfo()
{
printf("*************************************\n\n");
printf("**1.InserInfo          2.SearchInfo**\n");
printf("**3.SortInfo           4.ChangeInfo**\n");
printf("**5.quit               6.ShowInfo  **\n");
printf("*************************************\n\n");
printf("Please input your choice :\n");
}


void InsertInfo(STU *s[])
{
int i = 0;


printf("Please Input Information :\n");
while(1)
{
s[i] = (STU *)malloc(sizeof(STU));
if (NULL == s[i])
{
return;
}
scanf("%s", s[i]->name);
if (strcmp(s[i]->name, "end") == 0)
{
break;
}
scanf("%d%d%d", &s[i]->id, &s[i]->math, &s[i]->china);
i++;
count++;

}


}

void SearchInfo(STU *s[])
{
int i = 0;
char target[10] = {0};


printf("Please input name you will find :\n");
scanf("%s", target);


while(s[i] != NULL)
{
if(strcmp(s[i]->name, target) == 0)
{
printf("**************\n");
printf("name : %s\n", s[i]->name);
printf("id   : %d\n", s[i]->id);
printf("math : %d\n", s[i]->math);
printf("china: %d\n", s[i]->china);
printf("**************\n");
return;
}
i++;
}
printf("**************\n");
printf("Not Fount!!\n");
printf("**************\n");

}


void SortInfo(STU *s[])
{
int i,j,tmp,k,y;
char n[10]={0};
char m[10]={0};




for(i=0;i

{
for(j=0;j {
if(s[j+1]->math>=s[j]->math)
{
tmp=s[j]->math;
s[j]->math=s[j+1]->math;
s[j+1]->math=tmp;
strcpy(n,s[j]->name);
strcpy(s[j]->name,s[j+1]->name);
strcpy(s[j+1]->name,n);
k=s[j]->id;
s[j]->id=s[j+1]->id;
s[j+1]->id=k;
y=s[j]->china;
s[j]->china=s[j+1]->china;
s[j+1]->china=y;
}
}
}

for(i=0;i<=count;i++)
{
if(strcmp(s[i]->name,"end")!=0)
{
printf("math: name:%s id:%d score:%d\n",s[i]->name,s[i]->id,s[i]->math);
}
}
for(i=0;i
{
for(j=0;j {
if(s[j+1]->china>=s[j]->china)
{
tmp=s[j]->china;
s[j]->china=s[j+1]->china;
s[j+1]->china=tmp;
strcpy(m,s[j]->name);
strcpy(s[j]->name,s[j+1]->name);
strcpy(s[j+1]->name,m);
k=s[j]->id;
s[j]->id=s[j+1]->id;
s[j+1]->id=k;
}
}
}
for(i=0;i<=count;i++)
{
if(strcmp(s[i]->name,"end")!=0)
{
printf("china: name:%s id:%d score:%d\n",s[i]->name,s[i]->id,s[i]->china);
}
}
return;
}


void ChangeInfo(STU *s[])
{
char target[10] = {0};
int i= 0;


printf("Please Input The Name You Want Change :\n");
scanf("%s", target);


printf("Input New Infor :\n");



while(s[i] != NULL)
{
if(strcmp(s[i]->name, target) == 0)
{
scanf("%s", s[i]->name);
scanf("%d", &s[i]->id);
scanf("%d", &s[i]->math);
scanf("%d", &s[i]->china);
printf("Change Success!\n");
return;
}
i++;
}




}


void ShowInfo(STU *s[])
{
int i;
for (i=0;i {
printf("name:%s id:%d math:%d china:%d\n",s[i]->name,s[i]->id,s[i]->math,s[i]->china);
}


}


int main()
{
STU *stu[100] = {0};
char choice[10] = {0};


show();


while (1)
{
PrintInfo();
scanf("%s", choice);


switch (atoi(&choice[0]))
{
case 1:
InsertInfo(stu);
break;
case 2:
SearchInfo(stu);
break;
case 3:
SortInfo(stu);
break;
case 4:
ChangeInfo(stu);
break;
case 5:
exit(1);
break;
case 6:
ShowInfo(stu);
break;
default:
printf("Unkown Input!\n");
break;
}
}
return 0;
}

你可能感兴趣的:(学生成绩管理系统)