您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 管理学资料 > C语言班级管理系统程序
#includestdio.h#includestring.h#includeconio.h#defineN100structstudent{charXUEHAO[10];charBANJI[6];charXINGMING[6];charXINGBIE[2];charSHENGRI[8];charJIGUAN[10];charXUEYUAN[10];charTIANHUA[10];};voidCAIDAN();voidLURU();voidSHAXUN();voidsch_XUEHAO(FILE*fp);voidsch_XINGMING(FILE*fp);voidSHANCHU();voiddel_XUEHAO(FILE*fp);voiddel_XINGMING(FILE*fp);voidTIANJIA();voidXIUGAI();voidXIANZHI();voidTONGJI();main(){charchoose,yes_no;do{CAIDAN();printf(\n请输入序号:(1~8));choose=getch();switch(choose){case'1':printf(%c,choose);LURU();break;case'2':printf(%c,choose);SHAXUN();break;case'3':printf(%c,choose);SHANCHU();break;case'4':printf(%c,choose);TIANJIA();break;case'5':printf(%c,choose);XIUGAI();break;case'6':printf(%c,choose);XIANZHI();break;case'7':printf(%c,choose);TONGJI();break;case'8':break;default:printf(\n%c序号不对!\n,choose);}if(choose=='8')break;printf(\n要继续选择吗?(Y/N)\n);do{yes_no=getch();printf(%c,yes_no);}while(yes_no!='Y'&&yes_no!='y'&&yes_no!='N'&&yes_no!='n');}while(yes_no=='Y'||yes_no=='y');}voidCAIDAN(){printf(\n\n\n);printf(****************************************\n);printf(*请输入序号:(1~8)*\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);printf(****************************************\n);}/*定义录入学生信息的函数*/voidLURU(){inti=1;structstudenttemp;FILE*fp;fp=fopen(123.dat,w);if(fp==NULL){printf(\n打开文件失败!\n);return;}printf(\n请输入第1个学生信息:\n);printf(学号(用#结束输入):);do{gets(temp.XUEHAO);}while(strcmp(temp.XUEHAO,)==0);printf(班级(用#结束输入):);gets(temp.BANJI);printf(姓名(用#结束输入):);gets(temp.XINGMING);printf(性别(用#结束输入):);gets(temp.XINGBIE);printf(生日(用#结束输入):);gets(temp.SHENGRI);printf(籍贯(用#结束输入):);gets(temp.JIGUAN);printf(学院(用#结束输入):);gets(temp.XUEYUAN);printf(电话(用#结束输入):);gets(temp.TIANHUA);while(temp.XUEHAO[0]!='#'&&temp.BANJI[0]!='#'&&temp.XINGMING[0]!='#'&&temp.XINGBIE[0]!='#'&&temp.SHENGRI[0]!='#'&&temp.JIGUAN[0]!='#'&&temp.XUEYUAN[0]!='#'&&temp.TIANHUA[0]!='#'){fprintf(fp,%5s%10s%10s%10s%10s%10s%10s%10s\n,temp.XUEHAO,temp.BANJI,temp.XINGMING,temp.XINGBIE,temp.SHENGRI,temp.JIGUAN,temp.XUEYUAN,temp.TIANHUA);i++;printf(\n请输入第%d个学生信息:\n,i);printf(学号(用#结束输入):);do{gets(temp.XUEHAO);}while(strcmp(temp.XUEHAO,)==0);printf(班级(用#结束输入):);gets(temp.BANJI);printf(姓名(用#结束输入):);gets(temp.XINGMING);printf(性别(用#结束输入):);gets(temp.XINGBIE);printf(生日(用#结束输入):);gets(temp.SHENGRI);printf(籍贯(用#结束输入):);gets(temp.JIGUAN);printf(学院(用#结束输入):);gets(temp.XUEYUAN);printf(电话(用#结束输入):);gets(temp.TIANHUA);}fclose(fp);}/*定义查询学生信息的函数*/voidSHAXUN(){charc;FILE*fp;fp=fopen(123.dat,r);if(fp==NULL){printf(\n打开文件失败!\n);return;}printf(\n按学号查询(1),还是按姓名查询(2)?);c=getch();putch(c);if(c=='1')sch_XUEHAO(fp);elseif(c=='2')sch_XINGMING(fp);elseprintf(\n非法字符!\n);fclose(fp);}/*定义按学号查询学生信息的函数*/voidsch_XUEHAO(FILE*fp){intflag=0,n=0;chartempXUEHAO[10];structstudenttemp;printf(\n请输入要查询学生信息的学号:);gets(tempXUEHAO);while(feof(fp)==0){fscanf(fp,%5s%10s%10s%10s%10s%10s%10s%10s\n,&temp.XUEHAO,&temp.BANJI,&temp.XINGMING,&temp.XINGBIE,&temp.SHENGRI,&temp.JIGUAN,&temp.XUEYUAN,&temp.TIANHUA);if(strcmp(tempXUEHAO,temp.XUEHAO)==0){if(flag==0)printf(学号班级姓名性别生日籍贯学院电话\n);printf(%5s%10s%10s%10s%10s%10s%10s%10s\n,temp.XUEHAO,temp.BANJI,temp.XINGMING,temp.XINGBIE,temp.SHENGRI,temp.JIGUAN,temp.XUEYUAN,temp.TIANHUA);flag=1;}n++;}if(n==0)printf(\n文件中无此信息!\n);elseif(flag==0)printf(\n文件中无此人!\n);}/*定义按姓名查询学生信息的函数*/voidsch_XINGMING(FILE*fp){intflag=0,n=0;chartempXINGMING[6];structstudenttemp;printf(\n请输入要查询学生信息的姓名:);gets(tempXINGMING);while(feof(fp)==0){fscanf(fp,%5s%10s%10s%10s%10s%10s%10s%10s\n,&temp.XUEHAO,&temp.BANJI,&temp.XINGMING,&temp.XINGBIE,&temp.SHENGRI,&temp.JIGUAN,&temp.XUEYUAN,&temp.TIANHUA);if(strcmp(tempXINGMING,temp.XINGMING)==0){if(flag==0)printf(学号班级姓名性别生日籍贯学院电话\n);printf(%5s%10s%10s%10s%10s%10s%10s%10s\n,temp.XUEHAO,temp.BANJI,temp.XINGMING,temp.XINGBIE,temp.SHENGRI,temp.JIGUAN,temp.XUEYUAN,temp.TIANHUA);flag=1;}n++;}if(n==0)printf(\n文件中无此信息!\n);elseif(flag==0)printf(\n文件中无此人!\n);}/*定义删除学生信息的函数*/voidSHANCHU(){charc;FILE*fp;fp=fopen(123.dat,r);if(fp==NULL){printf(\n文件打开失败!\n);return;}printf(\n按学号删除(1),还是按姓名删除(2)?);c=getch();putch(c);if(c=='1')del_XUEHAO(fp);elseif(c=='2')del_XINGMING(fp);elseprintf(\n非法字符!\n);fclose(fp);}/*定义按学号删除学生信息的函数*/voiddel_XUEHAO(FILE*fp){chartempXUEHAO[10];intn=0,i=0,k;structstudentstu[N];while(feof(fp)==0){fscanf(fp,%5s%10s%10s%10s%10s%10s%10s%10s\n,stu[i].XUEHAO,stu[i].BANJI,stu[i].XINGMING,stu[i].XINGBIE,stu[i].SHENGRI,stu[i].JIGUAN,stu[i].XUEYUAN,stu[i].TIANHUA);i++;n++;}fclose(fp);printf(\n请输入要删除的学生信息的学号:);scanf(%s,tempXUEHAO);for(i=0;in;i++)if(strcmp(tempXUEHAO,stu[i].XUEHAO)==0)break;if(in)for(k=i;kn;k++)stu[k]=stu[k+1];elseprintf(\n无此人!\n);fp=fopen(123.dat,w);if(fp==NULL){printf(\n文件打开失败!\n);return;}for(i=0;in-1;i++)fprintf(fp,%5s%10s%10s%10s%10s%10s%10s%10s\n,stu[i].XUEHAO,stu[i].BANJI,stu[i].XINGMING,stu[i].XINGBIE,stu[i].SHENGRI,stu[i].JIGUAN,stu[i].XUEYUAN,stu[i].TIANHUA);}/*定义按姓名删除学生信息的
本文标题:C语言班级管理系统程序
链接地址:https://www.777doc.com/doc-2398118 .html