学生管理系统(附设计要求)

来源:互联网 发布:unix 时间 java 编辑:程序博客网 时间:2024/05/18 03:30

课程设计要求:

⑴一律使用 STUDENT 定义学生结构体的变量,一律使用 PSTUDENT 定义指向学生结构体的指针变量

⑵程序运行过程中要有菜单提示,菜单如下:

***************************************************************

*    1.Insert a student                                                *

*    2.Delete a student                                               *

* 3.Display the link list *

*    4.Display excellent students                                *

*    5.Search a student by the name                          *

*    6.Display the average score of three courses     *

*    0.Exit the program                                               *

***************************************************************

⑶“Insert a student”:插入一个学生记录,要求按平均分从高到低插入

⑷“Delete a student”:删除指定学号的学生

⑸“Display the link list”:输出链表中所有学生的信息

⑹“Display excellent students”:输出链表中三门功课平均成绩高于85分(含85分)的学生

⑺“Search a student by the name”:根据输入的姓名,输出链表中相应学生的信息

⑻“Display the average score of three courses”:输出链表中所有学生的数学平均分、物理平均分以及化学平均分

⑼“Exit the program”:销毁链表,结束程序运行


⑽要求程序首先自动插入5个学生记录到链表中

 

#include<stdio.h>

#include<stdlib.h>

#include<string.h>

#define max 33

enum gender {male, female};

typedef struct s

{

long num;

char name[10];

enum gender sex;

int age;

int score[3];

int avg;

char addr[20];

struct s *next;

}STUDENT, *PSTUDENT;

PSTUDENT   InitList()

{

 PSTUDENT  head;

 head=new  s;

 head->next=NULL;

 return head;

}

PSTUDENT InsertList(PSTUDENT s)//插入学生信息

{

printf("请输入学生的信息\n");

PSTUDENT p,r,q;

q=(PSTUDENT)malloc(sizeof(STUDENT));

printf("学号:");

scanf("%d",&(q->num));

printf("姓名");

scanf("%s",q->name);

printf("性别");

scanf("%d",&(q->sex));

printf("年龄");

scanf("%d",&(q->age));

printf("高数");

scanf("%d",&(q->score[0]));

printf("物理");

scanf("%d",&(q->score[1]));

printf("化学");

scanf("%d",&(q->score[2]));

printf("平均分");

scanf("%d",&(q->avg));

printf("地址");

scanf("%s",q->addr);

p=s->next;

while(p)//依次搜索到尾节点

{

r=p;

p=p->next;

}

r->next=q;

r=q;

r->next=NULL;

return s;

}

void DeleteList(PSTUDENT s)//按学生姓名来删除信息

{

char name2[10];

printf("输入要删除的学生姓名:");

scanf("%s",&name2);

PSTUDENT p,q;

q=p=s;

p=p->next;

while(p)

{

if(strcmp(p->name,name2)==0)//比较姓名是否一样

{

q->next=p->next;

delete p;

break;

}

else 

{

q=p;

p=p->next;

}

}

}

void DisplayList(PSTUDENT s)//输出学生信息

{

int i,j=0,k;

STUDENT r[max];

STUDENT l;

printf("学号   姓名 性别 高数  物理    化学    平均分     地址\n");

PSTUDENT p;

p=s->next;

while(p)//将每一个学生信息保存到结构体数组中

{

r[j++]=*p;

p=p->next;

k=j;

}

for(i=0;i<k;i++)

for(j=i+1;j<k;j++)

{

if(r[i].avg<r[j].avg)

{

l=r[i];

r[i]=r[j];

r[j]=l;

}

}

for(i=0;i<k;i++)

{

printf("%d  ",r[i].num);

printf("%s  ",r[i].name);

printf("%d",r[i].sex);

for(j=0;j<3;j++)

printf("\t %d",r[i].score[j]);

printf("\t%d",r[i].avg);

printf("\t%s",r[i].addr);

printf("\n");

}

printf("\n");

}

void DisplayEList(PSTUDENT s)//查找优秀学生信息

{

int i;

printf("优秀学生信息:\n");

printf("学号   姓名 性别 高数  物理    化学    平均分     地址\n");

while(s)

{

if(s->avg>85||s->avg==85)

{

printf("%d  ",s->num);

printf("%s  ",s->name);

printf("%d",s->sex);

for(i=0;i<3;i++)

printf("\t %d",s->score[i]);

printf("\t%d",s->avg);

printf("\t%s",s->addr);

printf("\n");

}

s=s->next;

}

}

void SearchNList(PSTUDENT s)//按学生姓名来查找信息

{

int i,k=0;

char name2[10];

PSTUDENT t;

t=s->next;

printf("按姓名查找的学生信息:\n");

scanf("%s",name2);

while(t)

{

if(strcmp(t->name,name2)==0)

{

k++;//查找成功,k=1

printf("学号   姓名 性别 高数  物理    化学    平均分     地址\n");

printf("%d  ",t->num);

printf("%s  ",t->name);

printf("%d",t->sex);

for(i=0;i<3;i++)

printf("\t %d",t->score[i]);

printf("\t%d",t->avg);

printf("\t%s",t->addr);

printf("\n");

}

t=t->next;

}

if(k==0) printf("该系统中不存在该学生的信息!");

}

void DisplayAList(PSTUDENT s)//该班每门学科的平均分

{

int s1=0,s2=0,s3=0;

PSTUDENT p;

p=s->next;

while(p)

{

s1=s1+p->score[0];

s2=s2+p->score[1];

s3=s3+p->score[2];

p=p->next;

}

printf("该班级学生的数学平均分:%.2f\n",s1/5.0);

printf("该班级学生的物理平均分:%.2f\n",s2/5.0);

printf("该班级学生的化学平均分:%.2f\n",s3/5.0);

}

void main()

{

system("color F0");

printf("***************************************************************\n");

printf("*    1.Insert a student                                      *\n");

printf("*    2.Delete a student                                      *\n");

printf("*    3.Display the link list                                 *\n");

printf("*    4.Display excellent students                            *\n");

printf("*    5.Search a student by the name                          *\n");

printf("*    6.Display the average score of three courses            *\n");

printf("*    0.Exit the program                                      *\n");

printf("***************************************************************\n");

PSTUDENT s,h,m;

m=h=InitList();

int select,i;

STUDENT stu[5]=

{

{99101, "Mary", female, 18, {70, 80, 90}, 80, "WuHan"},

{99102, "John", male, 17, {75,85, 95}, 85, "BeiJing"},

{99103, "Kite", female, 18, {88, 72, 92}, 84, "ShangHai"},

{99104, "Tom", male, 17, {90, 90, 90}, 90, "GuangZhou"},

{99105, "Mike", male, 18, {74, 75, 76}, 75, "ShenZhen"}

};

for(i=0; i < 5; i++)

{

s=(PSTUDENT)malloc(sizeof(STUDENT));

*s=stu[i];

h->next=s;

h=s;

}

h->next=NULL;

printf("\n输入您想要进行的操作选项键(0-6):");

scanf("%d",&select);

while(select!=-1)

{

if(select==1) InsertList(m);

else if(select==2) DeleteList(m);

else if(select==3) DisplayList(m);

else if(select==4) DisplayEList(m);

else if(select==5) SearchNList(m);

else if(select==6) DisplayAList(m); 

else if(select==0) exit(0);

printf("***************************************************************\n");

printf("*    1.Insert a student                                      *\n");

printf("*    2.Delete a student                                      *\n");

printf("*    3.Display the link list                                 *\n");

printf("*    4.Display excellent students                            *\n");

printf("*    5.Search a student by the name                          *\n");

printf("*    6.Display the average score of three courses            *\n");

printf("*    0.Exit the program                                      *\n");

printf("***************************************************************\n");

printf("\n输入您想要进行的操作选项键(0-6):");

scanf("%d",&select);

}

}

 

原创粉丝点击