当前位置:文档之家› 学生成绩管理系统(C语言版 链表实现)

学生成绩管理系统(C语言版 链表实现)


#include
#include
#include
#include
#include
#include
#include

enum Dep{Diazi,Jikexi,Soft,Shengh};
struct stu
{
char num[6];
char name[5];
enum Dep dep;
int score[3];
int sum;
float average;
int order;
struct stu *next;
};
int all;

int menu();
struct stu *create();
int print(struct stu *head);
void search(struct stu *head);
struct stu *shanchu(struct stu *head);
struct stu *paixu(struct stu *head);
struct stu *tianjia(struct stu *head,struct stu *new);
void save(struct stu *head);
struct stu *duqu();
struct stu *change(struct stu *head);
void devise(struct stu *head);
void zuigao(struct stu *head);
struct stu *tongji(struct stu *head);
void bujige(struct stu *head);
void pingjun(struct stu *head);
void prswit(struct stu *head,int i);

main()
{
int n;
struct stu *head,new;
head=NULL;
for(;;)
{
switch(menu())
{
case 0:exit(0); break;
case 1:head = create();break;
case 2:all = print(head);break;
case 3:search(head);break;
case 4:head = shanchu(head);break;
case 5:head = paixu(head);break;
case 6:head = tianjia(head,&new);break;
case 7:head = change(head);break;
case 8:save(head);break;
case 9:head = duqu(); break;
case 10:head = tongji(head); break;
}
}
}


menu()
{
int n;
struct date d;
getdate(&d);
printf(" \npress any key to enter the menu......");
getch();
system("cls");
printf("|-------------------------------------MENU-------------------------------------|\n");
printf("| 0---------------------------Quit |\n");
printf("| 1---------------Enter the record |\n");
printf("| 2---------------Print the record |\n");
printf("| 3------------------Search record |\n");
printf("| 4---------------shanchu a record |\n");
printf("| 5--------------------------paixu |\n");
printf("| 6------------------------tianjia |\n");
printf("| 7-------------------------xiugai |\n");
printf("| 8------------------Save the file |\n");
printf("| 9------------------duqu the file |\n");
printf("| 10------------------tongji fenxi |\n");
printf("|------------------------------------------------------------------------------|");
do{
printf("\n\t\t\tEnter your choice(0~10):");
scanf("%d",&n);
}while(n<0||n>10);
return(n);
}



struct stu *create()
{
int i,s,w;
struct stu *head=NULL,*p;
system("cls");
printf("\n+--------------------------------------------------------------------+\n");
printf("|The system warning: |\n");
printf("\n|You must choose the department,when you entering this system!

|\n");
printf("\n|And when you input information,you can't to change the department |\n");
printf("\n|If you want to deal with infoemation in different department |\n");
printf("\n|please input 0 ,and enter this agrin! |\n");
printf("\n+--------------------------------------------------------------------+");
printf("\n| 1-Dianzi 2-Jikexi 3-Soft 4-Shengh |");
printf("\n+-----------------------------------------------------------------+\n");
do
{
printf("\nInput Dep with the num(To choose dep):");
scanf("%d",&w);
if(w<1|| w>4)
printf(" Data error,please enter again.\n");
}while(w<1 || w>4);
for(;;)
{
p=(struct stu *)malloc(sizeof(struct stu));
printf("Enter the student num(0:list end):");
scanf("%s",p->num);
if(p->num[0]=='0') break;
printf("Enter the name:");
scanf("%s",p->name);

if(w==1) p->dep="Diazi";
else if(w==2) p->dep="Jikxi";
else if(w==3) p->dep="Soft";
else if(w==4) p->dep="Shenh";



printf("score1-Math,score2-Engl,score3-Clgue");
printf("Please enter the %d scores\n",3);
s=0;
for(i=0;i<3;i++)
{
do{
printf("score%d:",i+1);
scanf("%d",&p->score[i]);
if(p->score[i]<0 || p->score[i]>100)
printf(" Data error,please enter again.\n");
}while(p->score[i]<0 || p->score[i]>100);
s=s+p->score[i];
}
p->sum=s;
p->average=(float)s/3;
p->order=0;
p->next=head;
head=p;
system("cls");
}
return(head);
}


int print(struct stu *head)
{
int m=0;
struct stu *p;
system("cls");
p=head;
printf("\n************************************STUDENT************************************\n");
printf("-------------------------------------------------------------------------------\n");
printf("|xuhao| Num | Name | Dep | Math | Engl | Clgue | Sum | Ave | Order |\n");
printf("-------------------------------------------------------------------------------\n");
while(p!=NULL)
{
m++;
printf("| %3d | %s | %4s | %5s | %3d | %3d | %3d | %3d | %4.2f | %-5d|\n",
m, p->num,p->name,p->dep,p->score[0],p->score[1],p->score[2],p->sum,p->average,p->order);
p=p->next;
}
printf("-------------------------------------------------------------------------------\n");
printf("**************************************END**************************************\n");
return(m);
}


void search(struct stu *head)
{
struct stu *p;
char s[5];
system("cls");
printf(" Please enter name for searching.\n");
scanf("%s",s);
p=head;
while(strcmp(p->name,s) && p != NULL)
p=p->next;
if(p!=NULL)
{
printf("\n*************************************FOUND************************************\n");
printf("-------------------------------------------------------------------------------\n");
printf("| Num | Name | Dep | Math | Engl | Clgue | Sum | Ave | Order |\n");
printf("--------------------------------

-----------------------------------------------\n");
printf("| %4s | %4s | %5s | %3d | %3d | %3d | %3d | %4.2f | %-5d|\n",
p->num,p->name,p->dep,p->score[0],p->score[1],p->score[2],p->sum,p->average,p->order);
printf("-------------------------------------------------------------------------------\n");
printf("***************************************END**************************************\n");
}
else
printf("\nThere is no name %s student on the list.\n",p->name);
}




struct stu *shanchu(struct stu *head)
{
int n=0;
struct stu *p1,*p2;
char c,s[6];
system("cls");
printf("Please enter the deleted student name: ");
scanf("%s",s);
p1=p2=head;
while(strcmp(p1->name,s) && p1 != NULL)
{
p2=p1;
p1=p1->next;
}
if(strcmp(p1->name,s)==0)
{
printf("**************************************FOUND************************************\n");
printf("-------------------------------------------------------------------------------\n");
printf("| Num | Name | Dep | Math | Engl | Clgue | Sum | Ave | Order |\n");
printf("-------------------------------------------------------------------------------\n");
printf("| %4s | %4s | %5s | %3d | %3d | %3d | %3d | %4.2f | %-5d|\n",
p1->num,p1->name,p1->dep,p1->score[0],p1->score[1],p1->score[2],p1->sum,p1->average,p1->order);
printf("-------------------------------------------------------------------------------\n");
printf("***************************************END**************************************\n");
printf("\nAre you sure to delete the student Y/N ?");
for(;;)
{
scanf("%c",&c);
if(c=='n'||c=='N') break;
if(c=='y'||c=='Y')
{
if(p1==head)
head=p1->next;
else
p2->next=p1->next;
n=n-1;
printf("(student have been deleted.)\n",s);
printf(" Don't forget to save.\n");break;
}
}
}
else
printf("\nThere is no num %s student on the list.\n",p1->num);
return(head);
}



struct stu *paixu(struct stu *head)
{
int i=0;
struct stu *p1,*p2,*t,*temp;
temp=head->next;

head->next=NULL;
while(temp!=NULL)
{
t=temp;
temp=temp->next;

p1=head;
p2=head;
while(t->averageaverage&&p1!=NULL)
{
p2=p1;
p1=p1->next;
}
if(p1==p2)
{
t->next=p1;
head=t;
}
else
{
t->next=p1;
p2->next=t;
}
}
p1=head;
while(p1!=NULL)
{
i++;
p1->order=i;
p1=p1->next;
}
printf("Sorting is sucessful.\n");
return (head);
}



struct stu *tianjia(struct stu *head,struct stu *new)
{
struct stu *p0,*p1,*p2;
int n=0,sum1,i;
p1=head;
p0=new;
system("cls");
printf("\nPlease enter a new record.\n");
printf("Enter the num:");
scanf("%s",new->num);
printf("Enter the name:");
scanf("%s",new->name);
printf("Please enter the %d scores.\n",3);
sum1=0;
for(i=0;i<3;i++)
{
do{
printf("score%d:",i+1);
scanf("%d",&new->score[i]);
if(new->score[i]>100||ne

w->score[i]<0)
printf("Data error,please enter again.\n");
}while(new->score[i]>100||new->score[i]<0);
sum1=sum1+new->score[i];
}
new->sum=sum1;
new->average=(float)sum1/3;
new->order=0;
if(head==NULL)
{
head=p0;p0->next=NULL;
}
else
{
while((p0->averageaverage)&&(p1->next!=NULL))
{
p2=p1;
p1=p1->next;
}
if(p0->average>=p1->average)
{
if(head==p1)head=p0;
else p2->next=p0;
p0->next=p1;
}
else
{
p1->next=p0;p0->next=NULL;}
}
n=n+1;
head=paixu(head);
printf("\nStudent %s have been inserted.\n",new->name);
printf("Don't forget to save the new file.\n");
return(head);
}




void save(struct stu *head)
{
FILE *fp;
struct stu *p;
char outfile[10];
system("cls");
printf("Enter outfile name,for example c:\\score\n");
scanf("%s",outfile);
if((fp=fopen(outfile,"w"))==NULL)
{
printf("Cannot open the file\n");
return;
}
printf("\n...Saving the file......\n");
p=head;
while(p!=NULL)
{
fwrite(p,sizeof(struct stu),1,fp);
p=p->next;
}
fclose(fp);
printf("....Save the file successfully!\n");
}




struct stu *duqu()
{
struct stu *p1,*p2,*head=NULL;
FILE *fp;
char infile[10];
system("cls");
printf(" Enter infile name,for example c:\\score\n");
scanf("%s",infile);
if((fp=fopen(infile,"r"))==NULL)
{
printf("Can not open the file.\n");
return(head);
}
printf("\n...Loading the file!\n");
p1=(struct stu *)malloc(sizeof(struct stu));
head=p1;
while(!feof(fp))
{
if(fread(p1,sizeof(struct stu),1,fp)!=1) break;
p1->next=(struct stu *)malloc(sizeof(struct stu));
if(!p1->next)
{
printf("Out of memory!\n");
return (head);
}
p2=p1;
p1=p1->next;
}
p2->next=NULL;
fclose(fp);
printf("\nYou have success to read data from the file!\n");
return (head);
}





struct stu *change(struct stu *head)
{
int n;
struct stu *p1;
char c,s[6];
system("cls");
printf("Please enter the change name: ");
scanf("%s",s);
p1=head;
if(head == NULL)
{
printf("The link is empty!\n");
return;
}
while(strcmp(p1->name,s) && p1 != NULL)
{
p1=p1->next;
}
if(strcmp(p1->name,s)==0)
{
system("cls");
printf("------------------------------------FOUND-------------------------------------------\n");
printf("| Num | Name | Dep | Math | Engl | Clgu | Sum | Ave | Order |\n");
printf("-------------------------------------------------------------------------------\n");
printf("| %4s | %4s | %5s | %3d | %3d | %3d | %3d | %4.2f | %-5d|\n",
p1->num,p1->name,p1->dep,p1->score[0],p1->score[1],p1->score[2],p1->sum,p1->average,p1->order);
printf("-------------------------------------------------------------------------------\n");
devise(p1);
}

else printf("The name is NULL!\n");
printf("Don't forget to save the new file.\n");
return(head);


}




void devise(struct stu *head)
{
int choice;
choice = -1;
do
{
printf(" \npress any key to enter the next......");
getchar();
printf("please input a choice:\n");
printf("\n+---------------------------------------------------------+\n");
printf("\n| 0------Exit 1-------num 2--------name |\n");
printf("\n| 3----score1 4----score2 5------score3 |\n");
printf("\n+---------------------------------------------------------+\n");
printf("please choice a num:");
scanf("%d", &choice);
switch(choice)
{
case 0: return;
case 1: printf("input new number:");getchar(); ; break;
case 2: printf("input new name:");getchar(); scanf("%S", head->name); break;
case 3: printf("input new score1:"); scanf("%d",head->score[0]); break;
case 4: printf("input new score2:"); scanf("%d",&head->score[1]); break;
case 5: printf("input new score3:"); scanf("%d",&head->score[2]); break;
default: printf("Error!\n"); break;
}
} while(choice != 0);
}




struct stu *tongji(struct stu *head)
{

int x;
system("cls");
printf("\n+-------------------------------------+\n");
printf("\n| 0------------------------Exit |\n");
printf("\n| 1--------------------pingjiun |\n");
printf("\n| 2-------------zuigao he zuidi |\n");
printf("\n| 3----------------------bujige |\n");
printf("\n+------------------------------------+\n");
printf("please choice a num:");
scanf("%d",&x);
getchar();
switch(x)
{
case 0: return;
case 1: pingjun(head);break;
case 2: zuigao(head); break;
case 3: bujige(head); break;
}
}





void pingjun(struct stu *head)
{
int y=0;
float sum1=0,sum2=0,sum3=0,ave1=0,ave2=0,ave3=0;
struct stu *p;
p=head;
if(p == NULL)
{
printf("\nThe link is empty!\n");
}

while(p != NULL)
{
sum1=sum1+p->score[0];
sum2=sum2+p->score[1];
sum3=sum3+p->score[2];/*计算总分*/
y=y+1;
ave1=sum1/y;
ave2=sum2/y;
ave3=sum3/y;
p=p->next;/*使p指向下一个结点*/
}
printf("\nMath avg is%.1f\n",ave1);
printf("\nEngl avg is%.1f\n",ave2);
printf("\nClgue avg is%.1f\n",ave3);
}




void zuigao(struct stu *head)
{

struct stu *pe,*pc,*pt,*pa,*p,*p1,*p3,*p4,*p5; /* 用于指向分数最高的接点 */
p=head;
if(p == NULL)
{
printf("\n=====>The link is empty!\n");
return ;
}
pe=pc=pt=pa=p1=p3=p4=p5=p;
while(p!=NULL)
{
if(p->sum>=pc->sum)
pc=p;
if(p->score[0]>=pe->score[0])
pe=p;
if(p->score[1]>=pt->score[1])
pt=p;
if(p->score[2]>=pa->score[2])
pa=p;
if(p->sum<=p1->sum)
p1=p;
if(p->score[0]<=p3->score[0])
p3=p;
if(p->score[1]<=p4->score[1])
p4=p;
if(p->score[2]<=p5->score[2])
p5=p;
p=p->next;

system("cls");
printf("\n+------+-----------tong ji jie guo------------+\n");
printf("\n| | Name | Max |***| Name | Min |\n");
printf("\n| Sum | %s | %d |***| %s | %d |\n",pc->name,pc->sum,p1->name,p1->sum);
printf("\n| Math | %s | %d |***| %s | %d |\n",pe->name,pe->score[0],p3->name,p3->score[0]);
printf("\n| Engl | %s | %d |***| %s | %d |\n",pt->name,pt->score[1],p4->name,p4->score[1]);
printf("\n| Clgu | %s | %d |***| %s | %d |\n",pa->name,pa->score[2],p5->name,p5->score[2]);
printf(" +------+--------------------------------------+\n");

}

}




void bujige(struct stu *head)
{
int i,m=0,countc=0,countm=0,counte=0;
struct stu *p;
p=head;
do
{
if(p->score[0]<60) countc++;
if(p->score[1]<60) countm++;
if(p->score[2]<60) counte++;
p=p->next;
}while(p!=NULL);

printf("\n|-------------- TongJi--------------------+\n");
printf("| Math<60: %d |\n",countc);
printf("| Engl<60: %d |\n",countm);
printf("| Clgu<60: %d |\n",counte);
printf("+-------------------------------------------+\n");

while(p!=NULL)
{
i=0;
if(p->score[0]<60) i+=1;
else if(p->score[1]<60) i+=3;
else if(p->score[2]<60) i+=5;
prswit(head,i);
p=p->next;

}

}




void prswit(struct stu *head,int i)
{
int s;
struct stu *p;
p=head;
s=i;
switch(s)
{
case 1:/*仅数学不及格*/
{
system("cls");
printf("|************tong ji********|\n");
printf("|---------------------------|\n");
printf("| Num | Name | Dep | Math |\n");
printf("|---------------------------|\n");
printf("| %4s | %4s | %5s | %3d |\n",p->num,p->name,p->dep,p->score[0]);
printf("|---------------------------|\n");
printf("|***************************|\n");
break;
}
case 3:/*仅英语不及格*/
{
system("cls");
printf("|************tong ji********|\n");
printf("|---------------------------|\n");
printf("| Num | Name | Dep | Math |\n");
printf("|---------------------------|\n");
printf("| %4s | %4s | %5s | %3d |\n",p->num,p->name,p->dep,p->score[1]);
printf("|---------------------------|\n");
printf("|***************************|\n");
break;
}
case 5:/*仅C语言不及格*/
{
system("cls");
printf("|************tong ji********|\n");
printf("|---------------------------|\n");
printf("| Num | Name | Dep |Clgue |\n");
printf("|---------------------------|\n");
printf("| %4s | %4s | %5s | %3d |\n",p->num,p->name,p->dep,p->score[2]);
printf("|---------------------------|\n");
printf("|***************************|\n");
break;
}
case 4:/*仅数学和英语不及格*/
{
system("cls");
printf("*

**************tong ji**************|\n");
printf("|-----------------------------------|\n");
printf("| Num | Name | Dep | Math | Engl |\n");
printf("|-----------------------------------|\n");
printf("| %4s | %4s | %5s | %3d | %3d |\n",p->num,p->name,p->dep,p->score[0],p->score[1]);
printf("|-----------------------------------|\n");
printf("|***********************************|\n");
break;
}
case 6:/*仅数学和C语言不及格*/
{
system("cls");
printf("***************tong ji**************|\n");
printf("|-----------------------------------|\n");
printf("| Num | Name | Dep | Math |Clgue |\n");
printf("|-----------------------------------|\n");
printf("| %4s | %4s | %5s | %3d | %3d |\n",p->num,p->name,p->dep,p->score[0],p->score[1]);
printf("|-----------------------------------|\n");
printf("|***********************************|\n");
break;
}
case 8:/*仅英语和C语言不及格*/
{
system("cls");
printf("***************tong ji**************|\n");
printf("|-----------------------------------|\n");
printf("| Num | Name | Dep | Engl |Clgue |\n");
printf("|-----------------------------------|\n");
printf("| %4s | %4s | %5s | %3d | %3d |\n",p->num,p->name,p->dep,p->score[0],p->score[1]);
printf("|-----------------------------------|\n");
printf("|***********************************|\n");
break;
}
case 9:/*三门功课都不及格*/
{
system("cls");
printf("****************tong ji********************|\n");
printf("-------------------------------------------|\n");
printf("| Num | Name | Dep | Math | Engl | Clgue |\n");
printf("-------------------------------------------|\n");
printf("| %4s | %4s | %5s | %3d | %3d | %3d |\n",
p->num,p->name,p->dep,p->score[0],p->score[1],p->score[2]);
printf("-------------------------------------------|\n");
printf("*******************************************|\n");
break;
}

}
}











相关主题
文本预览
相关文档 最新文档