运行环境visual c++
#include "cstdlib"
#include
#include
#include
#define LEN sizeof(struct AddressBook)
int nosum=0;
struct AddressBook
{ char name[10];
char address[30];
char telephone[12];
char classed[10];
char number[10];
char sex[10];
char age[4];
int English;
int math;
int computer;
int network;
int chinese;
int sum;
int av;
int score[5];
struct AddressBook *next;
} ab[45];
struct AddressBook *creat( )
{int i,j;
int s;
struct AddressBook *p0,*p1,*p2,*head;
for (i=0;i<1;i++) //循环录入
{
p0=(struct AddressBook*)malloc(LEN);
printf("请输入学生信息:\n");
printf("学号:");
scanf("%s",p0->number);
printf("姓名:");
scanf("%s",p0->name);
printf("地址:");
scanf("%s",p0->address);
printf("电话:");
scanf("%s",p0->telephone);
printf("班级:");
scanf("%s",p0->classed);
printf("性别:");
scanf("%s",p0->sex);
printf("年龄:");
scanf("%s",&p0->age);
printf("英语:");
scanf("%d",&p0->English);
printf("数学:");
scanf("%d",&p0->math);
printf("机算机:");
scanf("%d",&p0->computer);
printf("网络:");
scanf("%d",&p0->network);
printf("语文:");
scanf("%d",&p0->chinese);
printf("请再输一次学生成绩\n");
s=0;
for(j=0;j<5;j++) //计算总分与平均分
{ scanf("%d",&p0->score[i]);
s+=p0->score[i]; }
p0->sum=s;
p0->av=s/5;
if(p0->av<60) nosum++;
if(i==0)
{head=p0;p0->next=NULL;}
else
{p1=p2=head;
while((p0->sum
{p2=p1;
p1=p1->next;} //p2保存p1指向的节点,p1后移一个节点
if(p0->sum>=p1->sum)
{
if(head==p1)
{head=p0;
p0->next=p1;}//插入到原第一个节点之前
else
{p2->next=p0;
p0->next=p1;
}
}
else
{p1->next=p0;
p0->next=NULL;} //插入到最后的节点之后
}
}
return head;
}
struct AddressBook *insert(struct AddressBook *head,struct AddressBook *add)
{ struct AddressBook *p0,*p1,*p2;
p1=head; //使p1指向第一个节点
p0=add; //p0指向要插入的节点
if(head==NULL)
{head=p0;p0->next=NULL;}
else
{
while ((p0->sum
{p2=p1;
p1=p1->next;
} //p2保存p1指向的节点,p1后移一个节点
if(p0->sum>=p1->sum)
{
if(head==p1)
{head=p0;
p0->next=p1;}//插入到原第一个节点之前
else
{ p2->next=p0;
p0->next=p1;
}
}
else
{p1->next=p0;
p0->next=NULL;
} //插入到最后的节点之后
return(head);
}
}
struct AddressBook *del(struct AddressBook *head,char number[])
{struct AddressBook *p1,*p2;
if(head==NULL)
{printf("\n 无此人信息\n");
return head;}
p1=head;
while(strcmp(number,p1->number)&&(p1->next!=NULL))
{ p2=p1;
p1=p1->next;} //没找到,继续向后找
if(!strcmp(number,p1->number))//找到了
{
if(head==p1)
head=p1->next; //若是第一个节点,则把第二个节点作为头节点
else
p2->next=p1->next; //否则将下一个节点地址前移
printf("已被删除:%s\n",number);
}
else
printf("无此人信息\n",number);
return(head);
}
void print(struct AddressBook *head)
{struct AddressBook *p=head;
printf("\n 学生信息\n");
while(p!=NULL) //打印输出
{
printf("学号:%s\t\t",p->number);
printf("姓名:%s\t\t",p->name);
printf("地址:%s\t\t",p->address);
printf("电话:%s\t\t",p->telephone);
printf("班级:%s\t\t",p->classed);
printf("性别:%s\t\t",p->sex);
printf("班级:%s\t\t",p->classed);
printf("年龄:%s\t\t",p->age);
printf("英语:%d\t\t",p->English);
printf("数学:%d\t\t",p->math);
printf("计算机:%d\t\t",p->computer);
printf("网络:%d\t\t",p->network);
printf("语文:%d\t\t",p->chinese);
printf("总分:%d\t\t",p->sum);
printf("平均分:%d\t\t\n",p->av);
p=p->next;
}
}
struct AddressBook *find(struct AddressBook *head,char num[])
{ struct AddressBook *p1,*p2;
if(head==NULL)
{printf("\n无数据!\n");
return head; }
p1=head;
while(strcmp(num,p1->number)&&(p1->next!=NULL))//若没找到,链表指向下一个节点
{p2=p1;p1=p1->next;}
if(strcmp(num,p1->number)==0) //若相等则找到了
{ printf("找到学生信息\n");
printf("学号:%s\n",p1->number);
printf("姓名:%s\n",p1->name);
printf("地址:%s\n",p1->address);
printf("电话:%s\n",p1->telephone);
printf("性别:%s\n",p1->sex);
printf("班级:%s\n",p1->classed);
printf("年龄:%s\n",p1->age);
printf("英语:%d\n",p1->English);
printf("语文:%d\n",p1->chinese);
printf("数学:%d\n",p1->math);
printf("机算机:%d\n",p1->computer);
printf("网络:%d\n",p1->network);
printf("总分:%d\n",p1->sum);
printf("平均分:%d\n",p1->av);
}
else
printf(" 无此学生信息!\n");
return(head);
}
struct AddressBook *rework(struct AddressBook *head,char num[])
{ struct AddressBook *p1,*p2;
int button,s1;
char English1,chinese1,math1,network1,computer1,sum1,av1;
char number1[10],name1[10],classed1[10],address1[10],telephone1[10],sex1[10],age1[10];
if(head==NULL)
{printf("\n无数据!\n");
return head; }
p1=head;
while(strcmp(num,p1->number)&&(p1->next!=NULL))
{p2=p1;p1=p1->next;}
if(strcmp(num,p1->number)==0) //寻找此学生的信息
{ printf("找到学生信息\n");
printf("1.学号:%s\n",p1->number);
printf("2.姓名:%s\n",p1->name);
printf("3.地址:%s\n",p1->address);
printf("4.电话:%s\n",p1->telephone);
printf("5.性别:%s\n",p1->sex);
printf("6.年龄:%s\n",p1->age);
printf("7.英语:%d\n",p1->English);
printf("8.语文:%d\n",p1->chinese);
printf("9.数学:%d\n",p1->math);
printf("10.机算机:%d\n",p1->computer);
printf("11.网络:%d\n",p1->network);
printf("12.班级:%s\n",p1->classed);
printf("13.总分:%d\n",p1->sum);
printf("14.平均分:%d\n",p1->av);
scanf("%d",&button);
switch(button) //此语句来选择要修改的内容
{ case 1:printf("\n学号\n");
scanf("%s",number1);
strcpy(p1->number,number1);break;
case 2:printf("\n姓名\n");
scanf("%s",name1);
strcpy(p1->name,name1);break;
case 3:printf("\n地址\n");
scanf("%s",address1);
strcpy(p1->address,address1);break;
case 4:printf("\n电话\n");
scanf("%s",telephone1);
strcpy(p1->telephone,telephone1);break;
case 5:printf("\n性别\n");
scanf("%s",sex1);
strcpy(p1->sex,sex1);break;
case 6:printf("\n年龄\n");
scanf("%s",age1);
strcpy(p1->age,age1);break;
case 7:printf("\n英语\n");
scanf("%d",&English1);
p1->English=English1;goto loop;
case 8:printf("\n语文\n");
scanf("%d",&chinese1);
p1->chinese=chinese1;goto loop;
case 9:printf("\n数学\n");
scanf("%d",&math1);
p1->math=math1;goto loop;
case 10:printf("\n计算机\n");
scanf("%d",&computer1);
p1->computer=computer1;goto loop;
case 11:printf("\n网络\n");
scanf("%d",&network1);
p1->network=network1;goto loop;
case 12:printf("\n班级\n");
scanf("%s",&classed1);
strcpy( p1->classed,classed1);goto loop;
case 13:printf("\n总分\n");
scanf("%d",&sum1);
p1->sum=sum1;break;
case 14:printf("\n平均分\n");
scanf("%d",&av1);
p1->av=av1;break; //再次计算总分与平均分
loop: s1=0; //跳转
s1=p1->English+p1->computer+p1->math+p1->network+p1->chinese;
p1->sum=s1;
p1->av=s1/5;
} }
else
printf(" 无此学生信息!\n");
return(head);
}
main()
{struct AddressBook *head,*add;
char del_name[10],num[10];
int pushbutton ,s,m,j;
add=(struct AddressBook *)malloc(LEN);
system("color 6A"); //调用dos改背景与前景色
system("title 学生管理系统");//改对话框的标题
printf("\n===============================@学生管理系统@===================================\n");
printf("********************************************************************************\n");
printf("* * 1.学生信息录入与总分排名 * *\n");
printf("* * * 2.学生信息增加 * * *\n");
printf("* * * 3.学生信息删除 * * *\n");
printf("* * * 4.学生信息修改 * * *\n");
printf("* * * 5.学生信息浏览 * * *\n");
printf("* * * 6.学生信息查询 * * *\n");
printf("* * * 7.退出学生管理系统 * * *\n");
printf("* * * 8.清屏 * * *\n");
loop:printf("* * * 请按1-8按钮进行选择 * * *\n");
printf("********************************************************************************\n");
scanf("%d",&pushbutton);
switch (pushbutton)
{case 1: head=creat() ; goto loop;//跳到主菜单
case 2:
for(j=0;j<1;j++)
{ printf("\n 请输入要插入的学生的信息:\n");
printf("姓名:");
scanf("%s",add->name);
printf("地址:");
scanf("%s",add->address);
printf("电话:");
scanf("%s",add->telephone);
printf("班级:");
scanf("%s",add->classed);
printf("学号:");
scanf("%s",add->number);
printf("性别:") ;
scanf("%s",add->sex);
printf("年龄:");
scanf("%s",add->age);
printf("英语:");
scanf("%d",&add->English);
printf("数学:");
scanf("%d",&add->math);
printf("计算机:");
scanf("%d",&add->computer);
printf("网络:");
scanf("%d",&add->network);
printf("语文:");
scanf("%d",&add->chinese);
printf("请再输入一次学习成绩:\n");
s=0;
for(m=0;m<5;m++)
{scanf("%d",&add->score[m]);
s+=add->score[m];}
add->sum=s;
add->av=s/5;
head=insert(head,add); }
goto loop;
case 3: printf("\n请输入要删除的纪录:\n");scanf("%s",del_name);head=del(head,del_name);goto loop; //函数调用
case 4: printf("\n请输入要修改的纪录:\n");scanf("%s",del_name);head=rework(head,del_name);goto loop; case 5: print(head) ;goto loop;
case 6: printf("\n请输入要查询的学号:\n");scanf("%s",num);head=find(head,num);goto loop;
case 7: system("exit");break;//调用dos清屏函数
case 8: system("cls");goto loop;
default: printf("\n非法操作!\n");goto loop;
}
}