首页 > 代码库 > 简易的学生社团管理(大二课设)
简易的学生社团管理(大二课设)
//STUDENT.h //STUDENT.h #ifndef STUDENT_H_INCLUDED #define STUDENT_H_INCLUDED #include<stdio.h> #include<stdlib.h> #include<string.h>//包含了对数组类操作的函数 #include<cstring> enum SEX{man,female,sex_null};//0-3 enum GRADE{freshman,sophomore,junior,senior,post_graduate1,post_graduate2,post_graduate3,grade_null};//0-7 enum POST{chairman,vice_chairman,secretary,member,post_null};//0-4 typedef struct Post { char corporation[100];//所任职的社团 POST post;//枚举类型表示职位 }Post; typedef struct Student { char studentNo[20];//学号 char name[50];//姓名 SEX sex;//性别(枚举类型) GRADE grade;//年级(枚举类型) char major[100];//专业 Post cp[20];//在什么社团任什么职位 char coporation[20][100];//所加入社团的名称 }STU; void initMember(STU *student); STU createStuMsg(char *studentNo, char *name, int sex,int grade,char *major, Post cp[],int num); void studentMsgToFile(STU student,int num);//将STU对象的信息存入文件 STU readFileMsg(char *name,char *studentNo); STU readFileMsgFromStr(char *xstr); void memberIntoCorporation(char *name, char *studentNo, char *coporation); void outCorporation(char *name, char *studentNo, char *coporation); void deleteStudentMsg(char *name, char *studentNo); void searchStudentMsgAndDisplay(char *name,char *studentNo); #endif // STUDENT_H_INCLUDED //STUEDNT.cpp #include"COPORATION.h" #include"STUDENT.h" void initCoporation(COP *coporation) { strcpy(coporation->coporationName,""); strcpy(coporation->timeYear,""); strcpy(coporation->timeMonth,""); strcpy(coporation->timeDay,""); coporation->capacity=20; coporation->FN=(FileName *)malloc(coporation->capacity*sizeof(FileName)); coporation->memberNum=0; for(int i=0;i<coporation->capacity;i++) { strcpy(coporation->FN[i].filename,""); } } void createCoporationMsg(char *coporationName, char *timeYear, char *timeMonth, char *timeDay,FileName *FN,int capacity, int memberNum) { COP coporation; int i; initCoporation(&coporation); fixcapacity(&coporation,capacity); coporation.capacity=capacity; strcpy(coporation.coporationName,coporationName); strcpy(coporation.timeYear,timeYear); strcpy(coporation.timeMonth,timeMonth); strcpy(coporation.timeDay,timeDay); coporation.memberNum=memberNum; for(i=0;i<coporation.memberNum;i++) strcpy(coporation.FN[i].filename,FN[i].filename); coporationMsgToFile(coporation); /* 注意:在主函数里进行操作的时候,一定要让(capacity>=memberNum)(最大容量和当前成员数量的关系)。 */ } void coporationMsgToFile(COP coporation) { FILE *fp; char fileName[100]; int i; sprintf(fileName,"coporationMsg\\file%s.txt",coporation.coporationName); fp=fopen(fileName,"wt"); if(fp==NULL) { printf("新建txt文本错误!!!"); exit(-1); } char ch=‘@‘,ch1=‘*‘,ch2=‘?‘,ch3=‘#‘; fputc(ch,fp); fputs(coporation.coporationName,fp); fputc(ch3,fp); fputs(coporation.timeYear,fp); fputc(ch3,fp); fputs(coporation.timeMonth,fp); fputc(ch3,fp); fputs(coporation.timeDay,fp); fputc(ch3,fp); fprintf(fp,"%d",coporation.capacity); fputc(ch3,fp); fprintf(fp,"%d",coporation.memberNum); fputc(ch2,fp); i=0; while(i<coporation.memberNum) { fprintf(fp,coporation.FN[i].filename); fputc(ch3,fp); i++; } fputc(ch1,fp); fclose(fp); } void fixcapacity(COP *coporation,int newCapacity) { //修改储存成员的空间大小,尽量不要改小,不能小于3个(至少有 会长、副会长、秘书的空缺) //此方法存在操作不当的风险 int ss=coporation->capacity; coporation->capacity=newCapacity; coporation->FN=(FileName *)realloc(coporation->FN,newCapacity*sizeof(FileName)); for(int i=ss;i<newCapacity;i++) { strcpy(coporation->FN[i].filename,""); } } COP readFileMsg(char *coporationName) { COP coporation; initCoporation(&coporation); FILE *fp; char fileName[100]; sprintf(fileName,"coporationMsg\\file%s.txt",coporationName); fp=fopen(fileName,"r"); if(fp==NULL) { printf("没有此社团,请检查您的输入是否有问题!!!"); exit(-1); } char str[100000]; fgets(str,100000,fp); int i=0,j=0; if(str[i]==‘@‘); else while(str[i]!=‘@‘) i++; i=i+1; while(str[i]!=‘#‘) { coporation.coporationName[j++]=str[i++]; } coporation.coporationName[j]=‘\0‘; i++; j=0; while(str[i]!=‘#‘) { coporation.timeYear[j++]=str[i++]; } coporation.timeYear[j]=‘\0‘; i++; j=0; while(str[i]!=‘#‘) { coporation.timeMonth[j++]=str[i++]; } coporation.timeMonth[j]=‘\0‘; i++; j=0; while(str[i]!=‘#‘) { coporation.timeDay[j++]=str[i++]; } coporation.timeDay[j]=‘\0‘; i++; j=0; char capacity[5],memebrNum[5]; while(str[i]!=‘#‘) { capacity[j++]=str[i++]; } capacity[j]=‘\0‘; i++; j=0; while(str[i]!=‘?‘) memebrNum[j++]=str[i++]; memebrNum[j]=‘\0‘; i++; j=0; int xcapacity=atoi(capacity); int xmember=atoi(memebrNum); coporation.capacity=xcapacity; coporation.memberNum=xmember; FileName *xFN; int k=0; xFN=(FileName *)malloc(xcapacity*sizeof(FileName)); while(str[i]!=‘*‘) { while(str[i]!=‘#‘) xFN[k].filename[j++]=str[i++]; xFN[k].filename[j]=‘\0‘; i++; j=0;k++; } for(j=0;j<k;j++) { coporation.FN[j]=xFN[j]; } fclose(fp); return coporation; } void disband(char *coporationName) { COP cop; STU stu; char fileName[100]; cop=readFileMsg(coporationName); for(int i=0;i<cop.memberNum;i++) { stu=readFileMsgFromStr(cop.FN[i].filename); outCorporation(stu.name,stu.studentNo,cop.coporationName); } sprintf(fileName,"coporationMsg\\file%s.txt",cop.coporationName); remove(fileName); printf("\n社团已经解散,社团信息已被删除,其相应学生信息已被修改\n"); } bool isInCoporation(char *studentName,char *studentNo,char *cop) { char str[100]; int i; sprintf(str,"%s%s",studentName,studentNo); COP coporation; coporation=readFileMsg(cop); for(i=0;i<coporation.memberNum;i++) { if(strcmp(str,coporation.FN[i].filename)==0) break; } if(i<coporation.memberNum) return true; else return false; } void searchCoporationMsgAndDisplay(char *coporationName) { COP cop; int i; cop=readFileMsg(coporationName); printf("***********************************************************\n"); printf("* \n"); printf("* \n"); printf("* 社团: %-s \n",cop.coporationName); printf("* \n"); printf("* 创建日期: %-s——%s——%s \n",cop.timeYear,cop.timeMonth,cop.timeDay); printf("* \n"); printf("* 会长(姓名+学号): %-s \n",cop.FN[0].filename); printf("* \n"); printf("* 副会长(姓名+学号): %-s \n",cop.FN[1].filename); printf("* \n"); printf("* 秘书(姓名+学号): %-s \n",cop.FN[2].filename); printf("* \n"); printf("* 最大人数: %-d \n",cop.capacity); printf("* \n"); printf("* 当前人数: %-d \n",cop.memberNum); printf("* \n"); printf("* 普通成员(姓名+学号):\n"); for(i=3;i<cop.memberNum;i++) { printf("* \n"); printf("* %s \n",cop.FN[i].filename); } printf("* \n"); printf("* \n"); printf("***********************************************************\n"); } //COPORATION.h #ifndef COPORATION_H_INCLUDED #define COPORATION_H_INCLUDED #include<stdio.h> #include<cstring> #include<string.h> #include<stdlib.h> typedef struct FileName { char filename[100]; }FileName; typedef struct COPORATION { char coporationName[100]; char timeYear[5]; char timeMonth[3]; char timeDay[3]; FileName *FN; int capacity; int memberNum; }COP; void initCoporation(COP *coporation); void createCoporationMsg(char *coporationName, char *timeYear, char *timeMonth, char *timeDay,FileName *FN ,int capacity, int memberNum); void coporationMsgToFile(COP copotation); COP readFileMsg(char *coporationName); void fixcapacity(COP *coporation,int newCapacity); void disband(char *coporationName); bool isInCoporation(char *studentName,char *studentNo,char *cop); void searchCoporationMsgAndDisplay(char *coporationName); #endif // COPORATION_H_INCLUDED //COPORATION.cpp #include"COPORATION.h" #include"STUDENT.h" void initCoporation(COP *coporation) { strcpy(coporation->coporationName,""); strcpy(coporation->timeYear,""); strcpy(coporation->timeMonth,""); strcpy(coporation->timeDay,""); coporation->capacity=20; coporation->FN=(FileName *)malloc(coporation->capacity*sizeof(FileName)); coporation->memberNum=0; for(int i=0;i<coporation->capacity;i++) { strcpy(coporation->FN[i].filename,""); } } void createCoporationMsg(char *coporationName, char *timeYear, char *timeMonth, char *timeDay,FileName *FN,int capacity, int memberNum) { COP coporation; int i; initCoporation(&coporation); fixcapacity(&coporation,capacity); coporation.capacity=capacity; strcpy(coporation.coporationName,coporationName); strcpy(coporation.timeYear,timeYear); strcpy(coporation.timeMonth,timeMonth); strcpy(coporation.timeDay,timeDay); coporation.memberNum=memberNum; for(i=0;i<coporation.memberNum;i++) strcpy(coporation.FN[i].filename,FN[i].filename); coporationMsgToFile(coporation); /* 注意:在主函数里进行操作的时候,一定要让(capacity>=memberNum)(最大容量和当前成员数量的关系)。 */ } void coporationMsgToFile(COP coporation) { FILE *fp; char fileName[100]; int i; sprintf(fileName,"coporationMsg\\file%s.txt",coporation.coporationName); fp=fopen(fileName,"wt"); if(fp==NULL) { printf("新建txt文本错误!!!"); exit(-1); } char ch=‘@‘,ch1=‘*‘,ch2=‘?‘,ch3=‘#‘; fputc(ch,fp); fputs(coporation.coporationName,fp); fputc(ch3,fp); fputs(coporation.timeYear,fp); fputc(ch3,fp); fputs(coporation.timeMonth,fp); fputc(ch3,fp); fputs(coporation.timeDay,fp); fputc(ch3,fp); fprintf(fp,"%d",coporation.capacity); fputc(ch3,fp); fprintf(fp,"%d",coporation.memberNum); fputc(ch2,fp); i=0; while(i<coporation.memberNum) { fprintf(fp,coporation.FN[i].filename); fputc(ch3,fp); i++; } fputc(ch1,fp); fclose(fp); } void fixcapacity(COP *coporation,int newCapacity) { //修改储存成员的空间大小,尽量不要改小,不能小于3个(至少有 会长、副会长、秘书的空缺) //此方法存在操作不当的风险 int ss=coporation->capacity; coporation->capacity=newCapacity; coporation->FN=(FileName *)realloc(coporation->FN,newCapacity*sizeof(FileName)); for(int i=ss;i<newCapacity;i++) { strcpy(coporation->FN[i].filename,""); } } COP readFileMsg(char *coporationName) { COP coporation; initCoporation(&coporation); FILE *fp; char fileName[100]; sprintf(fileName,"coporationMsg\\file%s.txt",coporationName); fp=fopen(fileName,"r"); if(fp==NULL) { printf("没有此社团,请检查您的输入是否有问题!!!"); exit(-1); } char str[100000]; fgets(str,100000,fp); int i=0,j=0; if(str[i]==‘@‘); else while(str[i]!=‘@‘) i++; i=i+1; while(str[i]!=‘#‘) { coporation.coporationName[j++]=str[i++]; } coporation.coporationName[j]=‘\0‘; i++; j=0; while(str[i]!=‘#‘) { coporation.timeYear[j++]=str[i++]; } coporation.timeYear[j]=‘\0‘; i++; j=0; while(str[i]!=‘#‘) { coporation.timeMonth[j++]=str[i++]; } coporation.timeMonth[j]=‘\0‘; i++; j=0; while(str[i]!=‘#‘) { coporation.timeDay[j++]=str[i++]; } coporation.timeDay[j]=‘\0‘; i++; j=0; char capacity[5],memebrNum[5]; while(str[i]!=‘#‘) { capacity[j++]=str[i++]; } capacity[j]=‘\0‘; i++; j=0; while(str[i]!=‘?‘) memebrNum[j++]=str[i++]; memebrNum[j]=‘\0‘; i++; j=0; int xcapacity=atoi(capacity); int xmember=atoi(memebrNum); coporation.capacity=xcapacity; coporation.memberNum=xmember; FileName *xFN; int k=0; xFN=(FileName *)malloc(xcapacity*sizeof(FileName)); while(str[i]!=‘*‘) { while(str[i]!=‘#‘) xFN[k].filename[j++]=str[i++]; xFN[k].filename[j]=‘\0‘; i++; j=0;k++; } for(j=0;j<k;j++) { coporation.FN[j]=xFN[j]; } fclose(fp); return coporation; } void disband(char *coporationName) { COP cop; STU stu; char fileName[100]; cop=readFileMsg(coporationName); for(int i=0;i<cop.memberNum;i++) { stu=readFileMsgFromStr(cop.FN[i].filename); outCorporation(stu.name,stu.studentNo,cop.coporationName); } sprintf(fileName,"coporationMsg\\file%s.txt",cop.coporationName); remove(fileName); printf("\n社团已经解散,社团信息已被删除,其相应学生信息已被修改\n"); } bool isInCoporation(char *studentName,char *studentNo,char *cop) { char str[100]; int i; sprintf(str,"%s%s",studentName,studentNo); COP coporation; coporation=readFileMsg(cop); for(i=0;i<coporation.memberNum;i++) { if(strcmp(str,coporation.FN[i].filename)==0) break; } if(i<coporation.memberNum) return true; else return false; } void searchCoporationMsgAndDisplay(char *coporationName) { COP cop; int i; cop=readFileMsg(coporationName); printf("***********************************************************\n"); printf("* \n"); printf("* \n"); printf("* 社团: %-s \n",cop.coporationName); printf("* \n"); printf("* 创建日期: %-s——%s——%s \n",cop.timeYear,cop.timeMonth,cop.timeDay); printf("* \n"); printf("* 会长(姓名+学号): %-s \n",cop.FN[0].filename); printf("* \n"); printf("* 副会长(姓名+学号): %-s \n",cop.FN[1].filename); printf("* \n"); printf("* 秘书(姓名+学号): %-s \n",cop.FN[2].filename); printf("* \n"); printf("* 最大人数: %-d \n",cop.capacity); printf("* \n"); printf("* 当前人数: %-d \n",cop.memberNum); printf("* \n"); printf("* 普通成员(姓名+学号):\n"); for(i=3;i<cop.memberNum;i++) { printf("* \n"); printf("* %s \n",cop.FN[i].filename); } printf("* \n"); printf("* \n"); printf("***********************************************************\n"); } //main.cpp #include <iostream> #include"STUDENT.h" #include"COPORATION.h" #include <windows.h> #include<process.h> #include<dir.h> #include<conio.h> using namespace std; void displayMenu(); void dipalyStar(); bool isOder(char str); bool dateIsLawful(int year,int month,int day); int main() { Sleep(500); dipalyStar(); mkdir("studentMsg"); mkdir("coporationMsg"); system("cls"); stepOOI:displayMenu(); char oder; fflush(stdin); printf("\n请您按照功能选框输入相应的操作命令符>> "); scanf("%c",&oder); while(!isOder(oder)) { printf("\n您输入的操作符没有定义,请核对后重新输入>> "); fflush(stdin); scanf("%c",&oder); } switch(oder) { case ‘Q‘: { //添加一个新的社团 printf("\n开始执行添加新社团…………\n"); char coporationName[100],timeYear[5],timeMonth[3],timeDay[3]; FileName *FN; int capacity,memberNum,ifYear,ifMonth,ifDay; memberNum=0; printf("\n请输入所创建社团的名称(输入过长,超过第49个字符后的信息无效)>> "); scanf("%s",coporationName); step1:fflush(stdin); printf("\n请输入社团创建年份>> "); scanf("%s",timeYear); ifYear=atoi(timeYear); if(ifYear>2017||ifYear<1912) {printf("\n您输入的年份非法,请重新输入!!!\n"); goto step1; } step2:fflush(stdin); printf("\n请输入社团创建月份>> "); scanf("%s",timeMonth); ifMonth=atoi(timeMonth); if(ifMonth<1||ifMonth>12){printf("\n您输入的月份是非法的,请重新输入!!!\n"); goto step2; } step3:fflush(stdin); printf("\n请输入社团创建日子>> "); scanf("%s",timeDay); ifDay=atoi(timeDay); if(!dateIsLawful(ifYear,ifMonth,ifDay)){printf("\n您输入的日子非法,请重新输入!!!\n"); goto step3;} step4:fflush(stdin); printf("\n请输入社团所容许的最大人数(最少3人)>> "); scanf("%d",&capacity); if(capacity<3){printf("\n您输入的信息存在风险,请重新输入!!!\n"); goto step4;} FN=(FileName *)malloc(capacity*sizeof(FileName)); printf("\n创建社团成员\n"); printf("\n您必需指定会长、副会长、秘书等职位的人选\n"); char sk=‘Y‘; int i; char name[50],studentNo[50]; char str[100],xstr[100]; FILE *fp; for(i=0;i<capacity&&sk==‘Y‘;i++) { step5:fflush(stdin); if(i==0){printf("\n请输入此社团会长的姓名>> ");} else if(i==1){{printf("\n请输入此社团副会长的姓名>> ");}} else if(i==2){{printf("\n请输入此社团秘书的姓名>> ");}} else printf("\n请输入普通成员的姓名>> "); scanf("%s",name); if(i==0){printf("\n请输入此社团会长的学号>> ");} else if(i==1){{printf("\n请输入此社团副会长的学号>> ");}} else if(i==2){{printf("\n请输入此社团秘书的学号>> ");}} else printf("\n请输入普通成员的学号>> "); scanf("%s",studentNo); sprintf(str,"%s%s",name,studentNo); sprintf(xstr,"studentMsg\\file%s%s.txt",name,studentNo); fp=fopen(xstr,"rt"); if(fp==NULL) { printf("\n查无此人,请检查您输入的信息是否有误或者不匹配,请重新输入(或按“Esc退出系统”)!!!\n"); goto step5; } else fclose(fp); STU stu; stu=readFileMsg(name,studentNo); int j=0; while(strcmp(stu.coporation[j],"")!=0) j++; if(j>=20){ printf("\n此学生已加入20个社团,不能再加入此社团,请见谅……\n"); goto step5; } strcpy(FN[i].filename,str); strcpy(stu.coporation[j],coporationName); strcpy(stu.cp[j].corporation,coporationName); if(i==0) stu.cp[j].post=chairman; else if(i==1) stu.cp[j].post=vice_chairman; else if(i==2) stu.cp[j].post=secretary; else stu.cp[j].post=member; studentMsgToFile(stu,j+1); memberNum++; fflush(stdin); if(i>=2){ printf("\n您是否要继续录入【是(Y)/否(任意字符)】>> "); scanf("%c",&sk); } } createCoporationMsg(coporationName,timeYear,timeMonth,timeDay,FN,capacity,memberNum); free(FN); FN=NULL; printf("\n社团创建完成:)\n"); } break; case ‘W‘: { //修改社团的信息 printf("\n开始执修改社团的信息……\n"); char xcoporation[50],filename[100]; char ch; s2:fflush(stdin); printf("\n请输入要被修改社团的名称>> "); scanf("%s",xcoporation); sprintf(filename,"coporationMsg\\file%s.txt",xcoporation); FILE *fp=NULL; fp=fopen(filename,"rt"); if(fp==NULL) { printf("\n该社团已经不存在或者请检查您的输入是否有问题……您是否要继续?【是(Y)/否(任意字符)】>> "); scanf("%c",&ch); if(ch==‘Y‘) goto s2; else goto s3; } else fclose(fp); COP cop=readFileMsg(xcoporation); s4:printf("-----------------------------------------------------\n"); printf("\n 1、修改社团的容量\n"); printf("\n 2、修改社团的创建日期\n"); printf("-----------------------------------------------------\n"); int sk; s1:fflush(stdin); printf("\n请输入相应的命令操作符>> "); scanf("%d",&sk); if(sk!=1&&sk!=2) {printf("\n您输入的操作符没有定义,请重新输入\n"); goto s1;} switch(sk) { case 1: { int newCapacity; xstep4:fflush(stdin); printf("\n请输入新的社团容量(最少3人)>> "); scanf("%d",&newCapacity); if(newCapacity<3){printf("\n您输入的信息存在风险,请重新输入!!!\n"); goto xstep4;} cop.capacity=newCapacity; coporationMsgToFile(cop); } break; case 2: { char timeYear[5],timeMonth[3],timeDay[3]; int ifYear,ifMonth,ifDay; xstep1:fflush(stdin); printf("\n请输入新的社团创建年份>> "); scanf("%s",timeYear); ifYear=atoi(timeYear); if(ifYear>2017||ifYear<1912) {printf("\n您输入的年份非法,请重新输入!!!\n"); goto xstep1; } xstep2:fflush(stdin); printf("\n请输入新的社团创建月份>> "); scanf("%s",timeMonth); ifMonth=atoi(timeMonth); if(ifMonth<1||ifMonth>12){printf("\n您输入的月份是非法的,请重新输入!!!\n"); goto xstep2; } xstep3:fflush(stdin); printf("\n请输入新的社团创建日子>> "); scanf("%s",timeDay); ifDay=atoi(timeDay); if(!dateIsLawful(ifYear,ifMonth,ifDay)){printf("\n您输入的日子非法,请重新输入!!!\n"); goto xstep3;} createCoporationMsg(cop.coporationName,timeYear,timeMonth,timeDay,cop.FN,cop.capacity,cop.memberNum); } break; default: ; } fflush(stdin); printf("\n您是否要依旧对此社团进行操作?【是(Y)/否(任意字符)】>>"); scanf("%c",&ch); if(ch==‘Y‘) {system("cls"); goto s4;} else{ fflush(stdin); printf("\n您是否要更换操作对象?【是(Y)/否(任意字符)】>>"); scanf("%c",&ch); if(ch==‘Y‘){system("cls"); goto s2;} else ; } } s3: ; break; case ‘E‘: { //删除社团 printf("\n开始执行删除社团…………\n"); char xcoporation[50],filename[100]; char ch; xxstep1:fflush(stdin); printf("\n请输入要被删除社团的名称>> "); scanf("%s",xcoporation); sprintf(filename,"coporationMsg\\file%s.txt",xcoporation); FILE *fp=NULL; fp=fopen(filename,"rt"); if(fp==NULL) { printf("\n该社团已经不存在或者请检查您的输入是否有问题……您是否要继续?【是(Y)/否(任意字符)】>> "); scanf("%c",&ch); if(ch==‘Y‘) goto xxstep1; else goto xxstep2; } else {fclose(fp); disband(xcoporation);} xxstep2: ; } break; case ‘R‘: { //添加一个新的学生 printf("\n开始执行添加新学生的操作……\n"); char name[50],studentNo[20],major[100]; int sex=-1,grade; Post cp[20]; STU student; initMember(&student); p3:fflush(stdin); printf("\n请输入学生姓名(50个字符之后无效)>> "); scanf("%s",name); printf("\n请输入学生学号>>(20个字符之后无效)>> "); scanf("%s",studentNo); p1:fflush(stdin); printf("\n请输入学生性别(0:男/1:女/2:此栏为空)>> "); scanf("%d",&sex); if(sex<0||sex>2) { printf("\n您所输入的信息不合规范,无法录入,请您重新输入\n"); goto p1; } p2:fflush(stdin); printf("\n请输入学生年级(0:大一/1:大二/2:大三/3:大四/4:研一/5:研二/6:研三)>> "); scanf("%d",&grade); if(grade<0||grade>6) { printf("\n您所输入的信息不合规范,无法录入,请您重新输入\n"); goto p2; } printf("\n请输入学生所在专业>> "); scanf("%s",major); for(int i=0;i<20;i++) { strcpy(cp[i].corporation,""); cp[i].post=post_null; } student=createStuMsg(name,studentNo,sex,grade,major,cp,20); char ch; fflush(stdin); printf("\n您是否是要继续进行新学生的添加【是(Y)/否(任意字符)】>> "); scanf("%c",&ch); if(ch==‘Y‘) goto p3; else ; } break; case ‘T‘: { //修改学生信息 printf("\n开始执行修改学生信息……\n"); char studentName[50],studentNo[20],filename[100]; aastep1:fflush(stdin); printf("\n请您输入将要被修改信息的学生的姓名>> "); scanf("%s",studentName); printf("\n请您输入将要被修改信息的学生的学号>> "); scanf("%s",studentNo); sprintf(filename,"studentMsg\\file%s%s.txt",studentName,studentNo); FILE *fp=fopen(filename,"rt"); char ch; if(fp==NULL) { printf("\n该学生已经不存在或请检查您的输入是否有误……是否要继续操作?【是(Y)/否(任意字符)】>> \n"); scanf("%c",&ch); if(ch==‘Y‘) goto aastep1; else goto aastep2; } fclose(fp); flag1:printf("@@@@@@@@@@@@@@@@@@@@@@@\n"); printf("@@@@@@@@@@@@@@@@@@@@@@@\n"); printf("@ @\n"); printf("@ 1、修改学生姓名 @\n"); printf("@ 2、修改学生学号 @\n"); printf("@ 3、修改学生性别 @\n"); printf("@ 4、修改学生专业 @\n"); printf("@ 5、修改学生年级 @\n"); printf("@ @\n"); printf("@@@@@@@@@@@@@@@@@@@@@@@\n"); int oder; printf("\n请按照选框输入相应的命令操作符>> "); scanf("%d",&oder); if(oder<1||oder>5) { printf("\n您所输入的操作符没有定义,请检查后重新输入\n"); system("cls"); goto flag1; } STU stu=readFileMsg(studentName,studentNo); switch(oder) { case 1: { printf("修改姓名相当于学籍的重置,该学生将会自动退出加入的所有社团\n"); char newName[50]; printf("\n请输入新的姓名(50个字符后为无效信息)>> "); scanf("%s",newName); strcpy(stu.name,newName); int num=0; while(strcmp(stu.coporation[num],"")!=0) num++; studentMsgToFile(stu,num); deleteStudentMsg(studentName,studentNo); printf("\n姓名修改完成……\n"); } break; case 2: { printf("修改学号相当于学籍的重置,该学生将会自动退出加入的所有社团\n"); char newNo[50]; printf("\n请输入新的学号(20个字符后为无效信息)>> "); scanf("%s",newNo); strcpy(stu.studentNo,newNo); int num=0; while(strcmp(stu.coporation[num],"")!=0) num++; studentMsgToFile(stu,num); deleteStudentMsg(studentName,studentNo); printf("\n学号修改完成……\n"); } break; case 3: { int sex; printf("\n性别重置为【0男/1女/任意数字为空栏】>> "); scanf("%d",&sex); if(sex==0) stu.sex=man; else if(sex==1) stu.sex=female; else stu.sex=sex_null; int num=0; while(strcmp(stu.coporation[num],"")!=0) num++; studentMsgToFile(stu,num); } break; case 4: { char newMajor[50]; printf("请输入新的专业名称>> "); scanf("%s",newMajor); strcpy(stu.major,newMajor); int num=0; while(strcmp(stu.coporation[num],"")!=0) num++; studentMsgToFile(stu,num); } break; case 5: { int grade; printf("\n年级重置为【0大一/1大二/2大三/3大四/4研一/5研二/6研三/任意数字为空栏】>> "); scanf("%d",&grade); if(grade==0) stu.grade=freshman; else if(grade==1) stu.grade=sophomore; else if(grade==2) stu.grade=junior; else if(grade==3) stu.grade=senior; else if(grade==4) stu.grade=post_graduate1; else if(grade==5) stu.grade=post_graduate2; else if(grade==6) stu.grade=post_graduate3; else stu.grade=grade_null; int num=0; while(strcmp(stu.coporation[num],"")!=0) num++; studentMsgToFile(stu,num); } break; default: ; } fflush(stdin); printf("\n您是否要依旧对此学生进行操作?【是(Y)/否(任意字符)】>>"); scanf("%c",&ch); if(ch==‘Y‘) {system("cls"); goto flag1;} else{ fflush(stdin); printf("\n您是否要更换操作对象?【是(Y)/否(任意字符)】>>"); scanf("%c",&ch); if(ch==‘Y‘){system("cls"); goto aastep1;} else ; } } aastep2: ; break; case ‘Y‘: { //删除学生 printf("\n开始执行删除学生的操作……\n"); char studentName[50]; char studentNo[20]; char filename[100]; ssstep1:fflush(stdin); printf("\n请您输入删除学生的姓名>> "); scanf("%s",studentName); printf("\n请您输入删除学生的学号>> "); scanf("%s",studentNo); sprintf(filename,"studentMsg\\file%s%s.txt",studentName,studentNo); FILE *fp=fopen(filename,"rt"); char ch; if(fp==NULL) { printf("\n该学生已经不存在或请检查您的输入是否有误……是否要继续操作?【是(Y)/否(任意字符)】>> \n"); scanf("%c",&ch); if(ch==‘Y‘) goto ssstep1; else goto ssstep2; } else {fclose(fp); deleteStudentMsg(studentName,studentNo);} } ssstep2:break; case ‘U‘: { //学生加入社团 printf("\n开始执行学生加入社团……\n"); char xcoporation[50],Filename[100]; yystep1:fflush(stdin); printf("\n请输入要加入的社团名称>> "); scanf("%s",xcoporation); sprintf(Filename,"coporationMsg\\file%s.txt",xcoporation); FILE *fp=fopen(Filename,"rt"); if(fp==NULL) { printf("\n该社团不存在或者请检查您的输入是否有问题……请重新输入\n"); goto yystep1; } fclose(fp); char studentName[50],studentNo[20],filename[100]; zzstep1:fflush(stdin); printf("\n请您输入加入该社团学生的姓名>> "); scanf("%s",studentName); printf("\n请您输入加入该社团学生的学号>> "); scanf("%s",studentNo); sprintf(filename,"studentMsg\\file%s%s.txt",studentName,studentNo); FILE *fp1=fopen(filename,"rt"); if(fp1==NULL) { printf("\n该学生已经不存在或请检查您的输入是否有误或者不匹配……请重新输入\n"); goto zzstep1; } fclose(fp1); memberIntoCorporation(studentName,studentNo,xcoporation); } break; case ‘I‘: { //修改学生在社团中的信息 printf("\n开始执行修改学生在社团中的信息……\n"); char studentName[50],studentNo[20],filename[100]; qqstep1:fflush(stdin); printf("\n请您输入将被修改学生的姓名>> "); scanf("%s",studentName); printf("\n请您输入将被修改学生的学号>> "); scanf("%s",studentNo); sprintf(filename,"studentMsg\\file%s%s.txt",studentName,studentNo); FILE *fp1=fopen(filename,"rt"); char ch; if(fp1==NULL) { printf("\n该学生已经不存在或请检查您的输入是否有误或者不匹配……\n"); printf("您是否要继续此操作?【是(Y)/否(任意字符)】>>"); scanf("%c",&ch); if(ch==‘Y‘) goto qqstep1; else goto qqstep2; } fclose(fp1); char xcoporation[50],Filename[100]; qqstep3:fflush(stdin); printf("\n请输入社团名称>> "); scanf("%s",xcoporation); sprintf(Filename,"coporationMsg\\file%s.txt",xcoporation); FILE *fp=fopen(Filename,"rt"); if(fp==NULL) { printf("\n该社团已经不存在或请检查您的输入是否有误或者不匹配……\n"); printf("\n您是否要继续此操作?【是(Y)/否(任意字符)】>>"); scanf("%c",&ch); if(ch==‘Y‘) goto qqstep3; else goto qqstep2; } fclose(fp); if(!isInCoporation(studentName,studentNo,xcoporation)) { printf("\n此学生不在该社团……\n"); printf("您是否要继续此操作?【是(Y)/否(任意字符)】>>"); scanf("%c",&ch); if(ch==‘Y‘) goto qqstep1; else goto qqstep2; } STU stu=readFileMsg(studentName,studentNo); COP cop=readFileMsg(xcoporation); char xstr[100]; sprintf(xstr,"%s%s",studentName,studentNo); int i,j,post; for(i=0;i<20&&strcmp(stu.cp[i].corporation,"")!=0;i++) { if(strcmp(stu.cp[i].corporation,xcoporation)==0) break; } for(j=0;j<cop.memberNum;j++) { if(strcmp(cop.FN[j].filename,xstr)==0) break; } FileName tempFN; if(stu.cp[i].post==chairman) { stepa:printf("\n该学生的职位是chairman,您将要改为【0不修改/1副社长/2秘书/3普通成员】>> "); scanf("%d",&post); if(post<0||post>3){printf("\n输入有误,请重新输入\n"); goto stepa;} switch(post) { case 0: break; case 1:stu.cp[i].post=vice_chairman; tempFN=cop.FN[0]; cop.FN[0]=cop.FN[1]; cop.FN[1]=tempFN; break; case 2:stu.cp[i].post=secretary; tempFN=cop.FN[0]; cop.FN[0]=cop.FN[2]; cop.FN[2]=tempFN; break; case 3:stu.cp[i].post=member; tempFN=cop.FN[0]; cop.FN[0]=cop.FN[cop.memberNum-1]; cop.FN[cop.memberNum-1]=tempFN; break; default: ; } printf("\npost修改完成……\n"); } else if(stu.cp[i].post==vice_chairman) { stepb:printf("\n该学生的职位是vice_chairman,您将要改为【0会长/1不修改/2秘书/3普通成员】>> "); scanf("%d",&post); if(post<0||post>3){printf("\n输入有误,请重新输入\n"); goto stepb;} switch(post) { case 0:stu.cp[i].post=chairman; tempFN=cop.FN[1]; cop.FN[1]=cop.FN[0]; cop.FN[0]=tempFN; break; case 1: break; case 2:stu.cp[i].post=secretary; tempFN=cop.FN[1]; cop.FN[1]=cop.FN[2]; cop.FN[2]=tempFN; break; case 3:stu.cp[i].post=member; tempFN=cop.FN[1]; cop.FN[1]=cop.FN[cop.memberNum-1]; cop.FN[cop.memberNum-1]=tempFN; break; default: ; } printf("\npost修改完成……\n"); } else if(stu.cp[i].post==secretary) { stepc:printf("\n该学生的职位是secretary,您将要改为【0会长/1副会长/2不修改/3普通成员】>> "); scanf("%d",&post); if(post<0||post>3){printf("\n输入有误,请重新输入\n"); goto stepc;} switch(post) { case 0:stu.cp[i].post=chairman; tempFN=cop.FN[2]; cop.FN[2]=cop.FN[0]; cop.FN[0]=tempFN; break; case 1:stu.cp[i].post=vice_chairman; tempFN=cop.FN[2]; cop.FN[2]=cop.FN[1]; cop.FN[1]=tempFN; break; case 2: break; case 3:stu.cp[i].post=member; tempFN=cop.FN[2]; cop.FN[2]=cop.FN[cop.memberNum-1]; cop.FN[cop.memberNum-1]=tempFN; break; default: ; } printf("\npost修改完成……\n"); } else if(stu.cp[i].post==member) { stepd:printf("\n该学生的职位是member,您将要改为【0会长/1副会长/2秘书/3不修改】>> "); scanf("%d",&post); if(post<0||post>3){printf("\n输入有误,请重新输入\n"); goto stepd;} switch(post) { case 0:stu.cp[i].post=chairman; tempFN=cop.FN[j]; cop.FN[j]=cop.FN[0]; cop.FN[0]=tempFN; break; case 1:stu.cp[i].post=vice_chairman; tempFN=cop.FN[j]; cop.FN[j]=cop.FN[1]; cop.FN[1]=tempFN; break; case 2:stu.cp[i].post=secretary; tempFN=cop.FN[j]; cop.FN[j]=cop.FN[2]; cop.FN[2]=tempFN; break; case 3: break; default: ; } printf("\npost修改完成……\n"); } else printf("\n此栏设置为空,修改无意义……\n"); j=0; while(strcmp(stu.cp[j].corporation,"")!=0) j++; studentMsgToFile(stu,j); coporationMsgToFile(cop); } qqstep2: ; break; case ‘O‘: { //学生退出社团 printf("\n开始执行学生退出社团……\n"); char xcoporation[50],Filename[100]; kkstep1:fflush(stdin); printf("\n请输入要退出的的社团名称>> "); scanf("%s",xcoporation); sprintf(Filename,"coporationMsg\\file%s.txt",xcoporation); FILE *fp=fopen(Filename,"rt"); if(fp==NULL) { printf("\n该社团不存在或者请检查您的输入是否有问题……请重新输入\n"); goto kkstep1; } fclose(fp); char studentName[50],studentNo[20],filename[100]; uustep1:fflush(stdin); printf("\n请您输入退出的学生的姓名>> "); scanf("%s",studentName); printf("\n请您输入退出的学生的学号>> "); scanf("%s",studentNo); sprintf(filename,"studentMsg\\file%s%s.txt",studentName,studentNo); FILE *fp1=fopen(filename,"rt"); if(fp1==NULL) { printf("\n该学生已经不存在或请检查您的输入是否有误或者不匹配……请重新输入\n"); goto uustep1; } fclose(fp1); outCorporation(studentName,studentNo,xcoporation); printf("\n%s已经退出%s:)\n",studentName,xcoporation); } break; case ‘P‘: { //查询社团信息 printf("\n开始执查询社团信息……\n"); char xcoporation[50],Filename[100]; ccstep1:fflush(stdin); printf("\n请输入要加入的社团名称>> "); scanf("%s",xcoporation); sprintf(Filename,"coporationMsg\\file%s.txt",xcoporation); FILE *fp=fopen(Filename,"rt"); if(fp==NULL) { printf("\n该社团不存在或者请检查您的输入是否有问题……请重新输入\n"); goto ccstep1; } fclose(fp); system("cls"); searchCoporationMsgAndDisplay(xcoporation); } break; case ‘G‘: { //查询学生信息 printf("\n开始执行查询学生信息……\n"); char studentName[50],studentNo[20],filename[100]; ppstep1:fflush(stdin); printf("\n请您输入所查询学生的姓名>> "); scanf("%s",studentName); printf("\n请您输入所查询学生的学号>> "); scanf("%s",studentNo); sprintf(filename,"studentMsg\\file%s%s.txt",studentName,studentNo); FILE *fp1=NULL; fp1=fopen(filename,"r"); if(fp1==NULL) { printf("\n该学生已经不存在或请检查您的输入是否有误或者不匹配……请重新输入\n"); goto ppstep1; } fclose(fp1); system("cls"); searchStudentMsgAndDisplay(studentName,studentNo); } break; default: printf("关于命令符的未知错误!!!\n"); exit(-101); } char ch; fflush(stdin); printf("\n你是否想继续进行操作【返回主界面】?(是(Y)/否(任意字符))>> "); scanf("%c",&ch); if(ch==‘Y‘){system("cls"); goto stepOOI;} else ; printf("\n请按任意键退出系统"); return 0; } void displayMenu() { printf("\n\t\t\t #################################################\n"); printf("\t\t\t/\\ 功能菜单 \\\n"); printf("\t\t\t/###################################################\n"); printf("\t\t\t!| |!\n"); printf("\t\t\t|! Q---->添加一个新的社团 !|\n"); printf("\t\t\t!| W---->修改社团信息 |!\n"); printf("\t\t\t|! E---->删除社团 !|\n"); printf("\t\t\t!| R---->添加一个新的学生 |!\n"); printf("\t\t\t|! T---->修改学生信息 !|\n"); printf("\t\t\t!| Y---->删除学生 |!\n"); printf("\t\t\t|! U---->学生加入社团 !|\n"); printf("\t\t\t|! I---->修改学生在社团中的信息 !|\n"); printf("\t\t\t!| O---->学生退出社团 |!\n"); printf("\t\t\t|! P---->查询社团信息 !|\n"); printf("\t\t\t!| G---->查询学生信息 |!\n"); printf("\t\t\t|! !|\n"); printf("\t\t\t!| Q、W、E、R、T、Y、U、I、O、P、G |!\n"); printf("\t\t\t|! 上述字母为相应的命令操作符,请选择输入>> !|\n"); printf("\t\t\t!| |!\n"); printf("\t\t\t|!/^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\\!\n"); printf("\t\t\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n"); printf("\n\t\t 警示: 请您至少先创建4个新学生的信息,否则无法创建一个新的社团……\n"); } void dipalyStar() { printf("\n\n\n\n\n\n\n \t\t\t\t老大,欢迎您进入学生管理系统…… \n"); Sleep(800); printf("\n \t\t\t\t您在此系统的权限非常之大…… \n"); Sleep(800); printf("\n \t\t\t\t您可以进行相应的增、删、查、改…… \n"); Sleep(800); printf("\n \t\t\t\t您可以设置系统最初的数据…… \n"); Sleep(800); printf("\n \t\t\t\t若是初次打开此系统…… \n"); Sleep(800); printf("\n \t\t\t\t请您先添加4个新学生的信息……否则有很多操作将会无效…… \n"); Sleep(800); printf("\n \t\t\t\t感谢您使用本系统…… \n"); Sleep(800); printf("\n \t\t\t\t您将进入到功能页面…… \n"); Sleep(1000); } bool isOder(char ch) { if(ch==‘Q‘) return true; else if(ch==‘W‘) return true; else if(ch==‘E‘) return true; else if(ch==‘R‘) return true; else if(ch==‘T‘) return true; else if(ch==‘Y‘) return true; else if(ch==‘U‘) return true; else if(ch==‘I‘) return true; else if(ch==‘O‘) return true; else if(ch==‘P‘) return true; else if(ch==‘G‘) return true; else return false; } bool dateIsLawful(int year,int month,int day) { if((year%4==0&&year%100!=0)||year%400==0) { if(month==2){if(day<0||day>29) return false; else return true;} else if(month==1||month==3||month==5||month==7||month==8||month==10||month==12) { if(day<0||day>31) return false; else return true; } else{ if(day<0||day>30) return false; else return true; } } else{ if(month==2){if(day<0||day>28) return false; else return true;} else if(month==1||month==3||month==5||month==7||month==8||month==10||month==12) { if(day<0||day>31) return false; else return true; } else{ if(day<0||day>30) return false; else return true; } } }
本文出自 “12671583” 博客,转载请与作者联系!
简易的学生社团管理(大二课设)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。