#include
#include
#include
#include
enum studentcategory { UNDERGRADUATE,POSTGRADUATE };
struct node * create_link_table(enum studentcategory category);
typedef struct node{
int ID;//学号:主键,唯一
char name[10]; //姓名
char sex[3]; //性别:男或女
char specialty[20]; //专业
int classes; //班级
enum studentcategory category; //枚举型学生类别;本科生、研究生
int math;//高数
int english; //英语
int clanguage; //C语言
int comprehensive; //课程综合
int thesis; //毕业论文
int totalscore; //总成绩
int classrank; //班级排名
int schoolrank; //校级排名
struct node * next;
}Student;
//声明全局变量
Student * myhead=NulL;
int schoolCount[2];
char tmp;
file * fp=NulL;
char boy[]="男";
char girl[]="女";
//函数声明
voID input(voID);
voID query_all(); //查询所有学生成绩信息
voID inquire(voID); //查询界面
voID insert_node0(); //获取用户要插入的学生成绩信息
voID insert_node(Student *student); //插入学生信息到链表中
voID edit_node(); //修改学生成绩信息
Student * query_node(int cate,int ID); //根据学生种类和学生学号查询
voID delete_node(); //删除链表中的节点
voID updaterank(); //更新链表中所有学生的排名
voID queryByClassAndcategory(); //根据班级和学生种类查询学生成绩信息
voID queryFailByClassAndcategory(); //查询不及格的学生成绩信息
voID queryByname(); //根据姓名查询学生成绩信息
voID count_analysis(); //统计模块
voID queryByID(); //根据ID查询学生成绩信息
file * openfile(char * openmode);
voID saveData(); //将链表中的数据保存到本地
voID initData(); //插入节点
int isCateAndIDViable(int cate,int ID); //查询插入的学生学号和学生种类是否已经被保存
Student * findPre(Student *student); //查找某节点的前一个学生信息
voID updateSchoolCount(); //更新学校排名
voID release(); //退出系统的时候释放链表所占的内存空间
voID stampscore(); //打印报表
//主函数
voID main()
{
char ch;
initData(); //插入节点
while(1)
{
system("cls");//清屏
//系统主页显示好看的布局
printf("n");
printf(" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *");
printf("n * *");
printf("n * 学生成绩管理系统V1.0 *");
printf("n * *n");
printf(" * 【功能菜单】 *n");
printf(" * [1].录入信息 [2].修改信息 *n");
printf(" * *n");
printf(" * [3].删除信息 [4].查询成绩 *n");
printf(" * *n");
printf(" * [5].打印信息 [6].统计信息 *n");
printf(" * *n");
printf(" * [esc].退出 *n");
printf(" * *n");
printf(" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *n");
printf(" 请输入 *** 作编号(1~5):");
sta:
ch=getch();//获取用户输入的指令
//判断用户输入的指令
switch(ch)
{
case '1': insert_node0(); break;
case '2': edit_node(); break;
case '3': delete_node(); break;
case '4': inquire(); break;
case '5': stampscore(); break;
case '6': count_analysis(); break;
case 27:
//系统退出的时候,保存数据,释放链表的内存空间,然后清屏
saveData(); //将链表中的数据保存到本地
release(); //退出系统的时候释放链表所占的内存空间
system("cls");
exit(0);
}
}
}
//插入节点
voID initData(){
long data_size=sizeof(Student);
Student *p1=NulL;
if((p1=(Student *)malloc(sizeof(Student)))==NulL){
printf("不能成功分配存储块");
exit(0);
}
fp=openfile("ab+");
fseek(fp,0L,SEEK_SET);
fread(p1,data_size,1,fp);
while(!feof(fp)){
insert_node(p1);
if((p1=(Student *)malloc(sizeof(Student)))==NulL){
printf("不能成功分配存储块");
exit(0);
}
if(fread(p1,fp)==EOF){
break;
}
}
if(fclose(fp)){
printf("未能正常关闭文件!");
}
}
//将链表中的数据保存到本地
voID saveData(){
Student * p1=myhead;
Student data;
if(myhead==NulL){
return;
}
fp=openfile("wb");
rewind(fp);
while(p1!=NulL){
fwrite(p1,sizeof(Student),fp); //将p1这个指针所指向的内容输出到fp这个文件中,每次输出的数据单元占sizeof(Student)个字节,总共输出1次
p1=p1->next;
}
if(fclose(fp)){
printf("未能正常关闭文件!");
}
}
//打开文件,返回文件指针
file *openfile(char * openmode){
file *f1=NulL;
if((f1=fopen("student.txt",openmode))==NulL){
printf("无法打开student.txt文件!n");
exit(0);
}
return(f1);
}
//统计模块
voID count_analysis(){
int res[6]={0,0};
float ave=0.0;
int count=0;
int sum=0;
int min=0;
int max=0;
Student * p1=myhead;
int cate=-1;
int score=0;
int clazz=-1;
int course=0;
system("cls");
if(p1==NulL)
{
printf("没有学生记录,任意键继续...n");
getch();
return;
}else{
printf("请输入类型(0:本科生,1:研究生):");
scanf("%d",&cate);
while ((tmp = getchar()) != EOF && tmp != 'n');//EOF是个宏,在stdil.h中定义,值为-1,也称结束标志
while(cate<0||cate>1){
printf("输入有误,请重新输入:");
scanf("%d",&cate);
while ((tmp = getchar()) != EOF && tmp != 'n');//当输入 ctrl+z 或 ctrl+c等组合键,getchar返回结束标志
}
printf("请输入班级:");
scanf("%d",&clazz);
while ((tmp = getchar()) != EOF && tmp != 'n');//当程序从键盘获得了字符并且字符不是回车符的话,执行循环里的 *** 作。
while(clazz<=0){
printf("输入有误,请重新输入:");
scanf("%d",&clazz);
while ((tmp = getchar()) != EOF && tmp != 'n');//n回车(剔除了回车字符)
}
switch(cate){
case UNDERGRADUATE: //本科生
printf("1.c语言 2.高数 3.英语n");
printf("请输入课程编号:");
scanf("%d",&course);
while ((tmp = getchar()) != EOF && tmp != 'n');
while(course>3||course<1){
printf("输入有误,请重新输入:");
scanf("%d",&course);
while ((tmp = getchar()) != EOF && tmp != 'n');
}
break;
case POSTGRADUATE: //研究生
printf("1.课程综合 2.论文n");
printf("请输入编号:");
scanf("%d",&course);
while ((tmp = getchar()) != EOF && tmp != 'n');
while(course>2||course<1){
printf("输入有误,请重新输入:");
scanf("%d",&course);
while ((tmp = getchar()) != EOF && tmp != 'n');
}
break;
}
while(p1!=NulL){ //循环,遍历链表里所有数据
if((p1->category==cate)&&(p1->classes==clazz)){
switch(cate){
case UNDERGRADUATE: //本科生
switch(course){ //课程
case 1:
score=p1->clanguage;
break;
case 2:
score=p1->math;
break;
case 3:
score=p1->english;
break;
}
break;
case POSTGRADUATE: //研究生
switch(course){ //课程
case 1:
score=p1->comprehensive;
break;
case 2:
score=p1->thesis;
break;
}
break;
}
if(score<=100&&score>=0){
count++;
sum+=score; //确定所要统计的班级的科目的总成绩
if(count==1){
max=score;
}
min=score;
if(score<60){
res[0]++; //统计不及格人数
}else{
res[score/10-5]++; //90~100为优;80~90为良;70~80为中;60~70为及格
}
}
}
p1=p1->next; //跟踪链表增长
}
if(count!=0){
ave=sum*1.0/count;
}
else{
ave=0.0;
}
printf("n-----------------------------------------n");
printf("平均分:%.2ftt",ave);
printf("最高分:%dn",max);
printf("最低分:%dn",min);
printf("优:%d人tt",res[5]+res[4]);
printf("良:%d人n",res[3]);
printf("中:%d人tt",res[2]);
printf("及格:%d人n",res[1]);
printf("不及格:%d人n",res[0]);
printf("n*****************************************n");
printf("超过平均分的学生名单:n");
printf("t姓名tt学号n");
p1=myhead;
while(p1!=NulL){
if(p1->category==cate&&p1->classes==clazz){
switch(cate){
case UNDERGRADUATE:
switch(course){
case 1:
score=p1->clanguage;
break;
case 2:
score=p1->math;
break;
case 3:
score=p1->english;
break;
}
break;
case POSTGRADUATE:
switch(course){
case 1:
score=p1->comprehensive;
break;
case 2:
score=p1->thesis;
break;
}
break;
}
if(score>=ave){
printf("t%stt%dn",p1->name,p1->ID);
}
}
p1=p1->next;
}
printf("n*****************************************n");
printf("不及格的学生名单:n"); //打印不及格学生名单
printf("t姓名tt学号n");
p1=myhead;
while(p1!=NulL){
if(p1->category==cate&&p1->classes==clazz){
switch(cate){
case UNDERGRADUATE:
switch(course){
case 1:
score=p1->clanguage;
break;
case 2:
score=p1->math;
break;
case 3:
score=p1->english;
break;
}
break;
case POSTGRADUATE:
switch(course){
case 1:
score=p1->comprehensive;
break;
case 2:
score=p1->thesis;
break;
}
break;
}
if(score<60&&score>=0){
printf("t%stt%dn",p1->ID);
}
}
p1=p1->next;
}
printf("n*****************************************n");
printf("n查询结束,任意键继续...");
getch();
}
}
//删除链表中的节点
voID delete_node(){
Student * p1=myhead,* p2=myhead;
int cate=-1;
int ID=-1;
system("cls");
if(myhead==NulL){
printf("没有学生记录,无法进行删除 *** 作!任意键继续...n");
getch();
return;
}
printf("请输入类型(0:本科生,1:研究生):");
scanf("%d",&cate);
while ((tmp = getchar()) != EOF && tmp != 'n');
while(cate<0||cate>1){
printf("输入有误,请重新输入:");
scanf("%d",&cate);
while ((tmp = getchar()) != EOF && tmp != 'n');
}
printf("请输入学号:");
scanf("%d",&ID);
while ((tmp = getchar()) != EOF && tmp != 'n');
while(ID<0){
printf("输入有误,请重新输入:");
scanf("%d",&ID);
while ((tmp = getchar()) != EOF && tmp != 'n');
}
while(((p1->category!=cate)||(p1->ID!=ID))&&(p1->next!=NulL)){
p2=p1;
p1=p1->next;
}
if((p1->category==cate)&&(p1->ID==ID)){
if(p1==myhead){
myhead=p1->next;
}else{
p2->next=p1->next;
}
free(p1);//释放储存空间
updaterank(); //更新链表中的排名
printf("删除成功,任意键继续...");
getch();
}else{
printf("删除失败,任意键继续...");
getch();
}
}
//查询界面
voID inquire(voID)
{
char ch;
while(1)
{
system("cls");
printf("n");
printf(" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *");
printf("n * *");
printf("n * 查询学生成绩 *");
printf("n * *n");
printf(" * 【功能菜单】 *n");
printf(" * [1].查询全部 [2].查询班级 *n");
printf(" * *n");
printf(" * [3].姓名查询 [4].学号查询 *n");
printf(" * *n");
printf(" * [5].查询不及格 [esc].返回首页 *n");
printf(" * *n");
printf(" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *n");
printf(" 请输入 *** 作编号(1~5):");
ch=getch();
switch(ch){
case '1':
query_all();
break;
case '2':
queryByClassAndcategory();
break;
case '3':
queryByname();
break;
case '4':
queryByID();
break;
case '5':
queryFailByClassAndcategory();
break;
case 27:
return;
}
}
}
//查询不及格的学生成绩信息
voID queryFailByClassAndcategory(){
Student * p1=myhead;
int cate=-1;
int score=0;
int clazz=-1;
int course=0;
system("cls");
if(p1==NulL){
printf("没有学生记录,&cate);
while ((tmp = getchar()) != EOF && tmp != 'n');
}
printf("请输入班级:");
scanf("%d",&clazz);
while ((tmp = getchar()) != EOF && tmp != 'n');
while(clazz<=0){
printf("输入有误,请重新输入:");
scanf("%d",&clazz);
while ((tmp = getchar()) != EOF && tmp != 'n');
}
switch(cate){
case UNDERGRADUATE: //本科生
printf("1.c语言 2.高数 3.英语n");
printf("请输入课程编号:");
scanf("%d",&course);
while ((tmp = getchar()) != EOF && tmp != 'n');
while(course<1||course>3){
printf("输入有误,请重新输入:");
scanf("%d",&course);
while ((tmp = getchar()) != EOF && tmp != 'n');
}
break;
case POSTGRADUATE: //研究生
printf("1.课程综合 2.论文n");
printf("请输入课程编号:");
scanf("%d",&course);
while ((tmp = getchar()) != EOF && tmp != 'n');
while(course<1||course>2){
printf("输入有误,请重新输入:");
scanf("%d",&course);
while ((tmp = getchar()) != EOF && tmp != 'n');
}
break;
}
while(p1!=NulL){
if(p1->category==cate&&p1->classes==clazz){
switch(cate){
case UNDERGRADUATE:
switch(course){
case 1:
score=p1->clanguage;
break;
case 2:
score=p1->math;
break;
case 3:
score=p1->english;
break;
}
break;
case POSTGRADUATE:
switch(course){
case 1:
score=p1->comprehensive;
break;
case 2:
score=p1->thesis;
break;
}
break;
}
if(score<60&&score>=0){
printf("****************************************n");
printf("学号:%dtt",p1->ID);
printf("姓名:%sn",p1->name);
printf("性别:%stt",p1->sex);
printf("班级:%dn",p1->classes);
printf("专业:%sn",p1->specialty);
switch(p1->category){
case UNDERGRADUATE:
printf("类型:本科生n");
printf("高数成绩:%dtt",p1->math);
printf("英语成绩:%dn",p1->english);
printf("c语言成绩:%dn",p1->clanguage);
break;
case POSTGRADUATE :
printf("类型:研究生n");
printf("课程论文成绩:%dtt",p1->comprehensive);
printf("毕业论文成绩:%dn",p1->thesis);
break;
}
printf("总成绩:%dn",p1->totalscore);
printf("班级排名:%dtt",p1->classrank);
printf("年级排名:%dn",p1->schoolrank);
printf("****************************************n");
}
break;
}
p1=p1->next;
}
printf("****************************************n");
printf("查询结束,任意键继续...");
getch();
}
}
//根据ID查询学生成绩信息
voID queryByID(){
Student * p1=myhead;
int ID=-1;
system("cls");
if(p1==NulL){
printf("没有学生记录,任意键继续...n");
getch();
return;
}else{
printf("请输入学号:");
scanf("%d",&ID);
while ((tmp = getchar()) != EOF && tmp != 'n');
}
printf("****************************************n");
while(p1!=NulL){
if(ID==p1->ID){
printf("学号:%dtt",p1->schoolrank);
printf("****************************************n");
break;
}
p1=p1->next;
}
printf("查询结束,任意键继续...");
getch();
}
}
//根据姓名查询学生成绩信息
voID queryByname(){
Student * p1=myhead;
char name[10];
system("cls");
if(p1==NulL){
printf("没有学生记录,任意键继续...n");
getch();
return;
}else{
printf("请输入名字:");
gets(name);
printf("****************************************n");
while(p1!=NulL){
if(strcmp(name,p1->name)==0){
printf("学号:%dtt",p1->schoolrank);
printf("****************************************n");
}
p1=p1->next;
}
}
printf("查询结束,任意键继续...");
getch();
}
//根据班级和学生种类查询学生成绩信息
voID queryByClassAndcategory(){
Student * p1=myhead;
int cate=-1;
int clazz=-1;
system("cls");
if(p1==NulL){
printf("没有学生记录,&clazz);
while ((tmp = getchar()) != EOF && tmp != 'n');
}
while(p1!=NulL){
if(p1->category==cate&&p1->classes==clazz){
printf("****************************************n");
printf("学号:%dtt",p1->schoolrank);
}
p1=p1->next;
}
printf("****************************************n");
printf("查询结束,任意键继续...");
getch();
}
}
//查询所有学生成绩信息
voID query_all(){
char c1;
int count=0;
int tmp=0;
Student * p1=myhead;
system("cls");
if(p1==NulL){
printf("没有学生记录,任意键继续...n");
getch();
return;
}else{
while(1){
while(p1!=NulL){
count++;
printf("学号:%dtt",p1->schoolrank);
printf("****************************************n");
p1=p1->next;
if(count%10==0&&p1!=NulL){
if(count==10){
printf("[n]下一页 [e]尾页 [esc]退出");
getch4: c1=getch();
if(c1==27){
return;
}else if(c1=='e'){
system("cls");
updateSchoolCount(); //更新学校排名
tmp=(schoolCount[0]+schoolCount[1])/10*10;
for(;count p1=p1->next; } }else if(c1=='n'){ system("cls"); } else{ goto getch4; } }else{ printf("[f]首页 [l]上一页 [n]下一页 [e]尾页 [esc]退出"); getch3: c1=getch(); if(c1==27){ return; }else if(c1=='e'){ system("cls"); updateSchoolCount(); tmp=(schoolCount[0]+schoolCount[1])/10*10; for(;count p1=p1->next; } }else if(c1=='f'){ system("cls"); count=0; p1=myhead; }else if(c1=='l'){ system("cls"); count=(count-1)/10*10-10;; p1=myhead; for(tmp=0;tmp p1=p1->next; } }else if(c1=='n'){ system("cls"); } else{ goto getch3; } } } } printf("没有更多的数据录了!n"); if(count>10){ printf("[f]首页 [l]上一页 [esc]退出"); getch2: c1=getch(); if(c1=='f'){ system("cls"); count=0; p1=myhead; }else if(c1=='l'){ system("cls"); count=(count-1)/10*10-10;; p1=myhead; for(tmp=0;tmp p1=p1->next; } }else if(c1==27){ return; } else{ goto getch2; } }else{ printf("[esc]退出"); getch1: c1=getch(); if(c1==27){ return; }else { goto getch1; } } } } } //修改学生成绩信息 voID edit_node(){ Student * p1=myhead; Student * pre=NulL; int cate=-1; int ID=-1; int sum=0; system("cls"); if(p1==NulL){ printf("没有学生信息,无法修改...n"); getch(); return; } printf("请输入类型(0:本科生,1:研究生):"); scanf("%d",&cate); while ((tmp = getchar()) != EOF && tmp != 'n'); while(cate>1||cate<0){ printf("输入有误,请重新输入:"); scanf("%d",&ID); while ((tmp = getchar()) != EOF && tmp != 'n'); } p1=query_node(cate,ID);//根据学生种类和学生学号查询 if(p1==NulL){ printf("无该学生记录!任意键继续...n"); getch(); } else{ printf("请输入该生的新数据n"); printf("姓名:"); scanf("%s",&p1->name); while ((tmp = getchar()) != EOF && tmp != 'n'); printf("性别:"); scanf("%s",p1->sex); while ((tmp = getchar()) != EOF && tmp != 'n'); while(strcmp(p1->sex,boy)!=0&&strcmp(p1->sex,girl)!=0){ printf("输入有误,请重新输入:"); scanf("%s",p1->sex); while ((tmp = getchar()) != EOF && tmp != 'n'); } printf("班级:"); scanf("%d",&p1->classes); while ((tmp = getchar()) != EOF && tmp != 'n'); while(p1->classes<=0){ printf("输入有误,请重新输入:"); scanf("%d",&p1->classes); while ((tmp = getchar()) != EOF && tmp != 'n'); } printf("专业:"); gets(p1->specialty); switch(p1->category){ case UNDERGRADUATE: printf("高数成绩:"); scanf("%d",&p1->math); while ((tmp = getchar()) != EOF && tmp != 'n'); while(p1->math<-1||p1->math>100){ printf("输入有误,请重新输入:"); scanf("%d",&p1->math); while ((tmp = getchar()) != EOF && tmp != 'n'); } if(p1->math!=-1) sum+=p1->math; printf("英语成绩:"); scanf("%d",&p1->english); while ((tmp = getchar()) != EOF && tmp != 'n'); while(p1->english<-1||p1->english>100){ printf("输入有误,请重新输入:"); scanf("%d",&p1->english); while ((tmp = getchar()) != EOF && tmp != 'n'); } if(p1->english!=-1) sum+=p1->english; printf("c语言成绩:"); scanf("%d",&p1->clanguage); while ((tmp = getchar()) != EOF && tmp != 'n'); while(p1->clanguage<-1||p1->clanguage>100){ printf("输入有误,请重新输入:"); scanf("%d",&p1->clanguage); while ((tmp = getchar()) != EOF && tmp != 'n'); } if(p1->clanguage!=-1) sum+=p1->clanguage; break; case POSTGRADUATE : printf("课程论文成绩:"); scanf("%d",&p1->comprehensive); while ((tmp = getchar()) != EOF && tmp != 'n'); while(p1->comprehensive<-1||p1->comprehensive>100){ printf("输入有误,请重新输入:"); scanf("%d",&p1->comprehensive); while ((tmp = getchar()) != EOF && tmp != 'n'); } if(p1->comprehensive!=-1) sum+=p1->comprehensive; printf("毕业论文成绩:"); scanf("%d",&p1->thesis); while ((tmp = getchar()) != EOF && tmp != 'n'); while(p1->thesis<-1||p1->thesis>100){ printf("输入有误,请重新输入:"); scanf("%d",&p1->thesis); while ((tmp = getchar()) != EOF && tmp != 'n'); } if(p1->thesis!=-1) sum+=p1->thesis; break; } p1->totalscore=sum; pre=findPre(p1);//查找节点的前一个学生信息 if(pre==NulL){ myhead=p1->next; }else{ pre->next=p1->next; } p1->next=NulL; insert_node(p1);//插入学生信息到链表中 updaterank();//更新链表中学生排名 printf("****************************************n"); printf("修改完成!任意键继续...n"); getch(); } } //查找某节点的前一个学生信息 Student * findPre(Student *student){ Student * p=myhead; Student * pre=NulL; if(p==NulL){ return NulL; } if(student==NulL||student==p){ return NulL; } while(p!=student){ pre=p; p=p->next; } return pre; } //根据学生种类和学生学号查询 Student * query_node(int cate,int ID){ Student * p=myhead; if(p==NulL){ return NulL; } while(((p->ID!=ID)||(p->category!=cate))&&(p->next!=NulL)) p=p->next; if((p->ID!=ID)||(p->category!=cate)) p=NulL; return p; } //插入学生信息到链表中 voID insert_node(Student *student){ Student *p0=NulL,*p1=NulL,*p2=NulL; p1=myhead; p0=student; if(myhead==NulL){ myhead=p0; p0->next=NulL; }else{ while((p0->totalscore p2=p1; p1=p1->next; } if(p0->totalscore>=myhead->totalscore){ p0->next=myhead; myhead=p0; } else if(p0->totalscore p1->next=p0; p0->next=NulL; } else{ p2->next=p0; p0->next=p1; } } } //更新链表中所有学生的排名 voID updaterank(){ int i=0; int j=0; int schoolRank[2]; //校级排名 int schoolLastscore[2]; //最后一个人的成绩 int classCount[2][100]; //总人数 int classLastscore[2][100]; //最后成绩 int classRank[2][100]; //班级排名 int cate=-1; Student * p=myhead; //初始化数组 for(i=0;i<2;i++){ for(j=0;j<100;j++){ classLastscore[i][j]=-1; classRank[i][j]=0; classCount[i][j]=0; } } schoolRank[0]=0; schoolRank[1]=0; schoolCount[0]=0; //两种学生类型总人数 schoolCount[1]=0; schoolLastscore[0]=-1; schoolLastscore[1]=-1; if(myhead==NulL){ return; } while(p!=NulL){ cate=p->category; classCount[cate][(p->classes)]++; schoolCount[cate]++; if(schoolLastscore[cate]!=p->totalscore){ schoolLastscore[cate]=p->totalscore; schoolRank[cate]=schoolCount[cate]; } p->schoolrank=schoolRank[cate]; //校级排名 if(classLastscore[cate][(p->classes)]!=p->totalscore){ classLastscore[cate][(p->classes)]=p->totalscore; classRank[cate][(p->classes)]=classCount[cate][(p->classes)]; } p->classrank=classRank[cate][(p->classes)]; //班级排名 p=p->next; } } //获取用户要插入的学生成绩信息 voID insert_node0(){ int i=0; int num=0; int cate=-1; int totalscore=0; Student *p1=NulL; system("cls"); printf("请输入录入数量:"); scanf("%d",&num); while ((tmp = getchar()) != EOF && tmp != 'n'); while(num<0) { printf("输入有误,请重新输入:"); scanf("%d",&num); while ((tmp = getchar()) != EOF && tmp != 'n'); } for(i=1;i<=num;i++) { totalscore=0; if((p1=(Student *)malloc(sizeof(Student)))==NulL) //新节点 { printf("不能成功分配存储块"); exit(0); } //p1->next=NulL; //新节点指向空 repeinsert: printf("请输入第%d个学生的学号:",i); scanf("%d",&p1->ID); //新节点指向ID while ((tmp = getchar()) != EOF && tmp != 'n'); while(p1->ID<0) { printf("输入有误,请重新输入:"); scanf("%d",&p1->ID); while ((tmp = getchar()) != EOF && tmp != 'n'); } printf("请输入第%d个学生的类型(0:本科生,1:研究生):",&p1->category); //新节点指向category while ((tmp = getchar()) != EOF && tmp != 'n'); while(p1->category<0||p1->category>1) { printf("输入有误,请重新输入:"); scanf("%d",&p1->category); while ((tmp = getchar()) != EOF && tmp != 'n'); } if(!isCateAndIDViable(p1->category,p1->ID)){ //查询插入的学生学号和学生种类是否已经被保存,函数返回为0,已存在 printf("所输入类型的学号已经存在,请重新输入,任意键继续...n"); getch(); system("cls"); goto repeinsert; } printf("请输入第%d个学生的姓名:",i); scanf("%s",&p1->name); while ((tmp = getchar()) != EOF && tmp != 'n'); printf("请输入第%d个学生的性别(男、女):",boy)!=0 && strcmp(p1->sex,girl)!=0) //对两个字符串自左至右逐个字符相比(按ASCII码值大小比较),=时返回0 { printf("输入有误,请重新输入:"); scanf("%s",p1->sex); while ((tmp = getchar()) != EOF && tmp != 'n'); } printf("请输入第%d个学生的班级:",&p1->classes); while ((tmp = getchar()) != EOF && tmp != 'n'); while(p1->classes<=0) { printf("输入有误,请重新输入:"); scanf("%d",&p1->classes); while ((tmp = getchar()) != EOF && tmp != 'n'); } printf("请输入第%d个学生的专业:",i); gets(p1->specialty); switch(p1->category){ case UNDERGRADUATE: //本科生 printf("请输入第%d个学生的高数成绩:",&p1->math); while ((tmp = getchar()) != EOF && tmp != 'n'); while(p1->math<-1||p1->math>100) { printf("输入有误,请重新输入:"); scanf("%d",&p1->math); while ((tmp = getchar()) != EOF && tmp != 'n'); } if(p1->math!=-1) totalscore+=p1->math; //总成绩里加高数成绩 printf("请输入第%d个学生的英语成绩:",&p1->english); while ((tmp = getchar()) != EOF && tmp != 'n'); } if(p1->english!=-1) totalscore+=p1->english; //总成绩里加英语成绩 printf("请输入第%d个学生的c语言成绩:",&p1->clanguage); while ((tmp = getchar()) != EOF && tmp != 'n'); } if(p1->clanguage!=-1) totalscore+=p1->clanguage; //总成绩里加c语言成绩 break; case POSTGRADUATE : //研究生 printf("请输入第%d个学生的课程论文成绩:",&p1->comprehensive); while ((tmp = getchar()) != EOF && tmp != 'n'); } if(p1->comprehensive!=-1) totalscore+=p1->comprehensive; printf("请输入第%d个学生的毕业论文成绩:",&p1->thesis); while ((tmp = getchar()) != EOF && tmp != 'n'); } if(p1->thesis!=-1) totalscore+=p1->thesis; break; } p1->totalscore=totalscore; insert_node(p1); //插入学生信息到链表中 updaterank(); //更新链表中学生的排名 printf("****************************************n"); } printf("录入成功,任意键继续..."); getch(); return; } //查询插入的学生学号和学生种类是否已经被保存 int isCateAndIDViable(int cate,int ID) { Student *p1=myhead; if(p1==NulL) return 1; while(p1!=NulL){ if(p1->category==cate&&p1->ID==ID){ return 0; } p1=p1->next; //跟踪链表增长 } return 1; } //更新学校排名 voID updateSchoolCount() { Student * student=myhead; if(myhead==NulL){ schoolCount[0]=0; schoolCount[1]=0; return; } schoolCount[0]=0; schoolCount[1]=0; while(student!=NulL){ schoolCount[student->category]++; student=student->next; } } //退出系统的时候释放链表所占的内存空间 voID release(){ Student * p=myhead; Student * p1=NulL; while(p!=NulL){ p1=p->next; free(p); p=p1; } myhead=NulL; } //打印报表 voID stampscore(){ Student * p1=myhead; int cate=-1; system("cls"); if(p1==NulL){ printf("没有学生记录,&cate); while ((tmp = getchar()) != EOF && tmp != 'n'); } system("cls"); if (cate==0){ printf("*******************************本科生成绩报表**********************************n"); printf("学号t姓名t性别t班级t专业t高数t英语tc语言t总成绩t校级排名n"); } else{ printf("*******************************研究生成绩报表**********************************"); printf("学号t姓名t性别t班级t专业t课程论文 毕业论文 总成绩 校级排名n"); } while(p1!=NulL){ if(p1->category==cate){ switch(cate){ case UNDERGRADUATE: printf("%dt%st%st%dt%st%dt%dt%dt%dt%dn", p1->ID,p1->sex,p1->classes,p1->specialty,p1->math,p1->english,p1->clanguage,p1->totalscore,p1->schoolrank); break; case POSTGRADUATE : printf("%dt%st%st%dt%st%dt%5dt%8dt%dn",p1->comprehensive,p1->thesis,p1->schoolrank); break; } } p1=p1->next; } printf("*******************************************************************************n"); } printf("查询结束,任意键继续..."); getch(); } 以上是内存溢出为你收集整理的c语言-学生信息管理系统全部内容,希望文章能够帮你解决c语言-学生信息管理系统所遇到的程序开发问题。 如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。 欢迎分享,转载请注明来源:内存溢出
评论列表(0条)