# include
# include "stdlib.h"
# include "string.h"
#include
struct student *Read();
void save(struct student *head);
void sinput(struct student *p);
struct student *input();
void paixu_num(struct student *head);
struct student *insert();
struct student *alter();
struct student *del();
void find_num(struct student *phead);
void find_name(struct student *phead);
void output();
void min_student(struct student *phead);
void max_student(struct student *phead);
void ave_student(struct student *phead);
void every_student(struct student *phead);
void score_paixu(struct student *head);
void help();
void tj_menu(struct student *head);
void find_menu(struct student *head);
void menu();
struct student{//定义学生信息结构数组,用于学生信息输入 char number[13];
char name[13];
char sex[4];
char adds[15];
char phone[14];
char qq[14];
float chinese,math,english,txhp,pinde,teacher;
int zcmc,ksmc;
double ave,zc;
struct student *next;
};
#define Len sizeof(struct student)
int len; //链表长度
int a=0,b=0,c=0,d=0,e=0;//用来存放成绩各阶的人数
char stu[10];
struct student *Read() {//读取数据文件保存到链表中,返回指向此链表头指针struct student *head=NULL;
struct student *p1, *p2;
FILE *fp;
cout<<"请输入你要打开的文件(.dat)"< cin>>stu; if((fp=fopen(stu,"rb+"))==NULL) { cout<<"打开文件出错!"< exit(0); } while(!feof(fp)) { if( (p1=(struct student*)malloc(Len))==NULL ) { cout<<"内存申请出错"< fclose(fp); exit(0); } if(fread(p1,Len,1,fp)!=1) { free(p1); break; } if(head==NULL) head=p2=p1; else { p2->next=p1; p2=p1; } } fclose(fp); return head; } void save(struct student *head){//数据存盘 FILE *fp; struct student *p; p=head; cout<<"请输入你要存进去的文件(.dat)"< cin>>stu; if((fp = fopen(stu, "wb"))==NULL) { cout<<"无法打开文件!"< system("pause"); menu(); } while(p) { if(fwrite(p,Len,1,fp)!=1) { cout<<"写入数据出错"< fclose(fp); return; } else p=p->next; } cout<<"数据存入成功!请按任意键继续!"< getchar(); fclose(fp); } //单次输入 void sinput(struct student *p) { cout<<"请输入学号:"< cin>>p->number; cout<<"请输入姓名: "< cin>>p->name; cout<<"请输入性别: "< cin>>p->sex; cout<<"请输入家庭住址: "< cin>>p->adds; cout<<"请输入联系电话: "< cin>>p->phone; cout<<"请输入qq: "< cin>>p->qq; cout<<"请输入语文成绩:"< cin>>p->chinese; if(p->chinese>100||p->chinese<0) { cout<<"成绩输入不符合规定,请重新输入:"< cin>>p->chinese; } cout<<"请输入数学成绩:"< cin>>p->math; if(p->math>100||p->math<0) { cout<<"成绩输入不符合规定,请重新输入:"< cin>>p->math; } cout<<"请输入英语成绩:"< cin>>p->english; if(p->english>100||p->english<0) { cout<<"成绩输入不符合规定,请重新输入:"< cin>>p->english; } cout<<"请输入同学互评分:"< cin>>p->txhp; if(p->txhp>100||p->txhp<0) { cout<<"成绩输入不符合规定,请重新输入:"< cin>>p->txhp; } cout<<"请输入品德成绩:"< cin>>p->pinde; if(p->pinde>100||p->pinde<0) { cout<<"成绩输入不符合规定,请重新输入:"< cin>>p->pinde; } cout<<"请输入任课教师评分:"< cin>>p->teacher; if(p->teacher>100||p->teacher<0) { cout<<"成绩输入不符合规定,请重新输入:"< cin>>p->teacher; } p->ave=(p->chinese+p->math+p->english)/3.0; p->zc=(p->ave*0.6+p->txhp*0.1+p->pinde*0.2+p->teacher*0.1); cout< cout<<"☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆"< cout<<"\t\t学号:"< cout<<"\t\t姓名:"< cout<<"\t\t性别:"< cout<<"\t\t家庭住址:"< cout<<"\t\t联系电话:"< cout<<"\t\tQQ号:"< cout<<"\t\t语文成绩:"< cout<<"\t\t数学成绩:"< cout<<"\t\t英语成绩:"< cout<<"\t\t品德成绩:"< cout<<"\t\t教师评分:"< cout<<"☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆"< return; } //学生成绩录入函数 struct student *input() { struct student *head=NULL,*p1,*p2;//输入p1,p2链表最后节点 char ch='y'; len=1; p2=p1=(struct student *)malloc(sizeof(struct student)); cout<<"请输入第"< sinput(p1); cout< cout<<"按n退出或按任意键继续"< cin>>ch; while(1) { if(len==1)//作为头结点 head=p1; else p2->next=p1; p2=p1; if(ch=='N'||ch=='n') break; p1=(struct student *)malloc(sizeof(struct student)); system("cls"); len++; cout<<"请输入第"< sinput(p1); cout< cout<<"按n退出或按任意键继续"< cin>>ch; } p2->next=NULL; paixu_num(head); cout<<"输入学生信息完成!请按任意键返回主菜单!"< getchar(); return head; } //学号排序 void paixu_num(struct student *head) { struct student t,*r,*p,*q;//t交换p、q,r头结点 r=head; if(r==NULL) { cout<<"学生信息不存在,请先输入学生信息!"< return; } while(r) { p=r; q=r->next; while(q) { if(strcmp(q->number,p->number)<0) //q { strcpy(t.number,q->number); strcpy(https://www.doczj.com/doc/871506311.html,,q->name); strcpy(t.sex,q->sex); strcpy(t.adds,q->adds); strcpy(t.phone,q->phone); strcpy(t.qq,q->qq); t.chinese=q->chinese; t.math=q->math; t.english=q->english; t.txhp=q->txhp; t.pinde=q->pinde; t.teacher=q->teacher; strcpy(q->number,p->number); strcpy(q->name,p->name); strcpy(q->sex,p->sex); strcpy(q->adds,p->adds); strcpy(q->phone,p->phone); strcpy(q->qq,p->qq); q->chinese=p->chinese; q->math=p->math; q->english=p->english; q->txhp=p->txhp; q->pinde=p->pinde; q->teacher=p->teacher; strcpy(p->number,t.number); strcpy(p->name,https://www.doczj.com/doc/871506311.html,); strcpy(p->sex,t.sex); strcpy(p->adds,t.adds); strcpy(p->phone,t.phone); strcpy(p->qq,t.qq); p->chinese=t.chinese; p->math=t.math; p->english=t.english; p->txhp=t.txhp; p->pinde=t.pinde; p->teacher=t.teacher; } q=q->next; } r=r->next; } } //插入函数 struct student *insert(){ struct student *p,*p1,*head; head=Read(); p1=head; p=(struct student *)malloc(sizeof(struct student)); char num[14],ch; cout<<"请输入你要插入的前一个学生的学号:"< cin>>num; while(p1){ if(!strcmp(p1->number,num)){ sinput(p); p->next=p1->next; p1->next=p; len++; } else p1=p1->next; cout<<"按n退出或按任意键继续"< cin>>ch; if(ch=='N'||ch=='n') break; } cout<<"学生信息插入成功!请按任意键返回!"< getchar(); return head; } //修改学生信息 struct student *alter() { char temp[13]; struct student *p,*head; head=Read(); p=head; cout<<"请输入要修改学生的学号:"; cin>>temp; while(p) { if(!strcmp(p->number,temp)) { sinput(p); } p=p->next; } cout< cout<<"学生信息修改成功!请按任意键返回!"< system("pause"); return head; } //删除学生信息 struct student *del() { char temp[13]; int m=0; struct student *p1,*p,*head;//p1删除 head=Read(); p1=p=head; cout<<"请输入你要删除学生的学号:"< cin>>temp; while(p){ if(strcmp(p1->number,temp)==0) { if(p1==head)//删除的头结点 head=p1->next; else p->next=p1->next; len--; m=1; cout<<"学生信息删除成功!请按任意键返回主菜单......."< getchar(); return head; } else p=p->next; } if(!m) cout<<"查找不到这个信息!"< return head; } void find_num(struct student *head)//按学号查找 { struct student *p=head; char temp[9]; int m = 0; cout<<"请输入要查找的学生的学号"< cin>>temp; while(p!=NULL) { if(strcmp(p->number,temp) == 0) cout<<"该学生的具体信息为:"< cout<<"☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆"< cout<<"\t\t学号:"< cout<<"\t\t姓名:"< cout<<"\t\t性别:"< cout<<"\t\t家庭住址:"< cout<<"\t\t联系电话:"< cout<<"\t\tQQ号:"< cout<<"\t\t语文成绩:"< cout<<"\t\t数学成绩"< cout<<"\t\t英语成绩"< cout<<"\t\t平均成绩"< cout<<"\t\t品德成绩"< cout<<"\t\t老师评分"< cout<<"\t\t综合成绩"< score_paixu(head); cout<<"\t\t考试名次"< cout<<"\t\t综测名次"< cout<<"☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆"< } p= p->next;//继续向下寻找 } if(!m) cout<<"查找不到这个学号的信息!"< cout<<"按任意键返回主菜单……"< getchar(); return ; } void find_name(struct student *head)//按姓名查找 { struct student *p= head; char temp[9]; int m = 0; cout<<"请输入要查找的学生的姓名"< cin>>temp; while(p) { if(strcmp(p->name,temp) == 0) cout<<"该学生的具体信息为:"< cout<<"☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆"< cout<<"学号:"< cout<<"\t\t姓名:"< cout<<"\t\t性别:"< cout<<"\t\t家庭住址:"< cout<<"\t\t联系电话:"< cout<<"\t\tQQ号:"< cout<<"\t\t语文成绩:"< cout<<"\t\t数学成绩"< cout<<"\t\t英语成绩"< cout<<"\t\t平均成绩"< cout<<"\t\t品德成绩"< cout<<"\t\t老师评分"< cout<<"\t\t综合成绩"< score_paixu(head); cout<<"\t\t考试名次"< cout<<"\t\t综测名次"< cout<<"☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆"< } p=p->next; } if(!m) cout<<"查找不到这个学号的信息!"< cout<<"按任意键返回主菜单……"< getchar(); return ; } void output() { struct student *p,*head; head=Read(); p=head; int i=1; while(p) { cout<<"☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆"< cout<<"\t\t学号:"< cout<<"\t\t姓名:"< cout<<"\t\t性别:"< cout<<"\t\t家庭住址:"< cout<<"\t\t联系电话:"< cout<<"\t\tQQ号:"<