C语言实现新生入学登记系统_第1页
C语言实现新生入学登记系统_第2页
C语言实现新生入学登记系统_第3页
C语言实现新生入学登记系统_第4页
C语言实现新生入学登记系统_第5页
已阅读5页,还剩10页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

第C语言实现新生入学登记系统printf("\n\n\n\n\n");

printf("\t|---------------欢迎进入----------------|\n");

printf("\t|

新生入学登记系统

|\n");

printf("\t|

主菜单

|\n");

printf("\t|

1.录入学生信息

|\n");

printf("\t|

2.浏览学生信息

|\n");

printf("\t|

3.查找学生信息

|\n");

printf("\t|

4.删除学生信息

|\n");

printf("\t|

5.修改学生信息

|\n");

printf("\t|

6.新生入学排名

|\n");

printf("\t|

0.退出系统

|\n");

printf("\t|-----------------------------------------|\n");

printf("\n");

printf("\t\t请选择(0-6):");

}

(4)BeginingAndEnding.h

#ifndefBEGININGANDENDING_H_INCLUDED

#defineBEGININGANDENDING_H_INCLUDED

//关于启动函数和结束函数

voidBegining();

voidEnding();

#endif//BEGININGANDENDING_H_INCLUDED

(5)BeginingAndEnding.c

#includestdio.h

#includeconio.h

//getc函数使用的头文件

#include"system.h"

#include"AboutFiles.h"

#include"BeginingAndEnding.h"

#include"MyList.h"

voidBegining()

readInfoFromFile("studentList.txt");

voidEnding()

writeInfoToFile("studentList.txt");

}

(6)MyList.h

#ifndefMYLIST_H_INCLUDED

#defineMYLIST_H_INCLUDED

//关于链表的函数声明

//创建节点

structNode*createNode(structstudentdata);

//插入节点

voidinsertNodeByHead(structstudentdata);

//指定位置删除节点

voiddeleteAppointNode(char*studentId);

//查找功能

structNode*searchInfoByData(char*studentId);

//打印链表

voidprintList();

#endif//MYLIST_H_INCLUDED

(7)MyList.c

#includestdio.h

#includeconio.h

//getc函数使用的头文件

#includewindows.h//Sleep函数使用的头文件

#includestring.h//strcmp函数使用的头文

#include"system.h"

#include"MyList.h"

structNode*studentList=NULL;

//链表的头指针

//创建节点

structNode*createNode(structstudentstudentData)

structNode*newNode=(structNode*)malloc(sizeof(structNode));

if(newNode!=NULL)

{

newNode-studentData=studentData;

newNode-next=NULL;

}

returnnewNode;

//插入节点

voidinsertNodeByHead(structstudentdata)

structNode*newNode=createNode(data);

//表头法插入,每次插入都将数据插入到头节点的下一个,先判断头节点是否为空,为空则新节点就是头节点,不为空,则插入在头节点的下一个位置

if(studentList==NULL)

{

studentList=newNode;

}

else//不改变头节点

{

newNode-next=studentList-next;

studentList-next=newNode;

}

//指定位置删除节点(知道这个节点的前驱和后续,然后进行删除)

voiddeleteAppointNode(char*studentId)

//将链表头部设为指定位置,先判断头节点是否为空,为空则链表没有数据,无法删除

//如果头节点不为空,则设头结点为指定位置,如果头结点是所找的节点,则删除,如果不是,设头结点的下一个为指定节点,头结点为指定节点的前驱节点,一直向下查询

//指定位置

structNode*posNode=studentList;

//指定位置的前面

structNode*posFrontNode=NULL;

//查找指定节点

if(posNode==NULL)

{

printf("数据为空无法删除!\n");

return;

}

else

{

//姓名是字符串,不能直接比较,strcmp(),相等返回值为0,相同返回值为负数或者正数

if(strcmp(posNode-studentData.studentId,studentId)==0)

{

studentList=studentList-next;

free(posNode);

return;

}

else

{

posFrontNode=posNode;

posNode=posNode-next;

//posFrontNode=posNode;//!!

while(strcmp(posNode-studentData.studentId,studentId))

{

//继续向下一个节点移动

posFrontNode=posNode;

posNode=posFrontNode-next;

if(posNode==NULL)//找到了链表尾部,没有找到数据

{

printf("未找到指定位置,无法删除!");

return;

}

}

//查到到对应数据后,进行删除,将该节点架空,然后释放该节点的存储单元

posFrontNode-next=posNode-next;

free(posNode);

return;

}

}

//查找功能

structNode*searchInfoByData(char*studentId)

structNode*pMove;

pMove=studentList;

if(pMove==NULL)//头节点为空,链表为空

{

//printf("学生链表为空!\n");

returnpMove;

}

else

{

//查找到或者查找到链表最后,则结束循环,返回查询结果,结果为空,有两种可能,一种是链表中没有数据,另一种是没有查询到

while(pMove!=NULL)

{

if(strcmp(pMove-studentData.studentId,studentId)==0)//找见

{

//printf("已查找到!\n");

returnpMove;

}

else

{

pMove=pMove-next;

}

}

//printf("未找到!\n");

returnpMove;

}

//打印链表

voidprintList()

structNode*pMove=studentList;

//涉及到展示数据

//表头

if(pMove==NULL)

{

printf("Nostudentrecord!Pleaseadd.\n");

return;

}

else

{

printf("\t-------------------------------------------------------------------------------------\n");

printf("\t|%-10s|%-7s|%-4s|%-4s|%-12s|%-12s|%-12s|%-5s|\n","学号","姓名","性别","年龄","班级","专业","电话","入学成绩");

printf("\t-------------------------------------------------------------------------------------\n");

while(pMove)

printf("\t|%-10s|%-7s|%-4s|%-4d|%-12s|%-12s|%-12s|%-8d|\n",STUDENT_DATA);

printf("\t-------------------------------------------------------------------------------------\n");

pMove=pMove-next;

}

}

printf("\n");

}

(8)AddStudent.h

#ifndefADDSTUDENT_H_INCLUDED

#defineADDSTUDENT_H_INCLUDED

voidAddStudent();

//录入学生信息

#endif//ADDSTUDENT_H_INCLUDED

(9)AddStudent.c

#includestdio.h

#includeconio.h

//getc函数使用的头文件

#includewindows.h//Sleep函数使用的头文件

#includestring.h//strcmp函数使用的头文

#include"AddStudent.h"

#include"system.h"

#include

"MyList.h"

//录入学生信息

voidAddStudent()

structstudentstudentData;

structNode*isNull=NULL;

//接收查询的返回值

intiFlagExist;

//保证不重复输入

charcFlag;

intret;

//用来接收scanf的返回值,判断输入数据是否正确

system("cls");

printf("=================================================================\n");

printf("\t请输入需要删除的学生的学号:");

gets(studentData.studentId);

pMove=searchInfoByData(studentData.studentId);

if(pMove)

//该学生存在,进行删除

{

//先对学生信息进行展示

printf("\t-------------------------------------------------------------------------------------\n");

printf("\t|%-10s|%-7s|%-4s|%-4s|%-12s|%-12s|%-12s|%-5s|\n","学号","姓名","性别","年龄","班级","专业","电话","入学成绩");

printf("\t-------------------------------------------------------------------------------------\n");

printf("\t|%-10s|%-7s|%-4s|%-4d|%-12s|%-12s|%-12s|%-8d|\n",STUDENT_DATA);

printf("\t-------------------------------------------------------------------------------------\n");

printf("\t已查找到该学生信息,是否删除?(y/n)");

cFlag=getchar();

getchar();//吃掉缓冲区的空格

while(cFlag!='n'cFlag!='y')

{

printf("输入有误,请输入‘y'或者‘n'!");

printf("\n请选择是否输入学生信息(y/n):");

cFlag=getchar();

getchar();

}

if(cFlag=='n')

return;

elseif(cFlag=='y')

{

deleteAppointNode(studentData.studentId);

printf("\t已删除该学生信息!\n");

printf("\t删除操作执行结束!\n");

}

}

else//找到了链表的末尾,或者链表为空

{

printf("\t该学生不存在!无法执行删除操作\n");

}

}

(16)ModifyStudent.h

#ifndefMODIFYSTUDENT_H_INCLUDED

#defineMODIFYSTUDENT_H_INCLUDED

#include"system.h"

voidModifyStudent();//修改学生信息

voidShowModifyMenu();//展示修改选项菜单

voiddealSelection(structstudentstudentData,intselection,structNode*pMove);//处理用户选择的修改项

#endif//MODIFYSTUDENT_H_INCLUDED

(17)ModifyStudent.c

#includestdio.h

#includeconio.h

//getc函数使用的头文件

#includewindows.h//Sleep函数使用的头文件

#includestring.h//strcmp函数使用的头文

#include"ModifyStudent.h"

#include"system.h"

#include"MyList.h"

//修改学生信息

voidModifyStudent()

structstudentstudentData;

structNode*pMove=NULL;//对学生信息查询结果进行保存

intselection;

//保存选择信息

charisContinue='n';

//是否继续进行修改

system("cls");

printf("\n");

printf("\t================================================================\n");

if(studentList==NULL)

{

printf("学生登记为空,无法进行成绩排名\n");

return;

}

else//学生链表头指针不为空,代表学生链表中存有学生信息

{

pMove=studentList;

//pMove指向链表的头

//通过遍历得到链表有多少个存储单元

for(i=0;pMove!=NULL;i++)

{

pMove=pMove-next;

}

length=i;

printf("现有学生总人数为%d\n",length);

//动态数组

stuRanking=(structstudentRanking*)malloc(length*sizeof(structstudentRanking));

if(stuRanking==NULL)

return;

//将需要输出的学生信息复制到结构体数组当中

pMove=studentList;

for(j=0;jlength;j++)

{

strcpy(stuRanking[j].studentId,pMove-studentData.studentId);

strcpy(stuRanking[j].name,pMove-studentD);

strcpy(stuRanking[j].className,pMove-studentData.className);

stuRanking[j].score=pMove-studentData.score;

pMove=pMove-next;

}

//复制完成后,根据成绩对学生进行排序

sortByScore(stuRanking,length);

//根据排序结果,为每名同学添加排名信息

Ranking(stuRanking,length);

//展示排名

printf("排名结果如下:\n");

printf("\t-------------------------------------------------------\n");

printf("\t|%-10s|%-7s|%-12s|%-5s|%-5s|\n","学号","姓名","班级","入学成绩","全级排名");

printf("\t-------------------------------------------------------\n");

for(j=0;jlength;j++)

{

printf("\t|%-10s|%-7s|%-12s|%-8d|%-8d|\n",STUDENT_RANKING);

printf("\t-------------------------------------------------------\n");

}

}

printf("输出排名信息完毕!\n");

system("pause");

//通过成绩对链表中的数据进行排序

voidsortByScore(structstudentRanking*stuRanking,intlength)

//进行冒泡排序,从大到小排序

inti,j;

structstudentRankingtemp;

for(i=0;ilength-1;i++)

{

for(j=0;j(length-i-1);j++)

{

if(stuRanking[j].scorestuRanking[j+1].score)//后一项比前一项大,则交换两个存储单元中的数据,一轮排序下来,最小项就位,在列表的最末尾

{

temp=*(stuRanking+j);

*(stuRanking+j)=*(stuRanking+j+1);

*(stuRanking+j+1)=temp;

}

}

}

voidRanking(structstudentRanking*stuRanking,intlength)

inti;

for(i=1;i=l

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论