C语言大型作业实践报告
计算机1001 制作者:李菁华 张兆丰 秦恒加
2011年6月
题目:选修课程管理系统
要求:假定有N门选修课,每门课有课程编号、名称、课程性质、总学时、授课学时、实验或上机学时、学分、开课学期等信息。学生可按要求(如总学分不能少于20学分)选课。
▪ 课程信息维护,如录入、修改、删除等,课程信息用文件保存。 ▪ 课程信息浏览—输出。 ▪ 学生选课功能。
▪ 查询功能包括:按学分、课程性质、学生等查询。 ▪ 统计功能。统计各门课程的选修人数。
▪ 本系统要有通用性、界面美观、操作方便。要考虑系统安全。 总体设计思路(流程图): 主程序 课程信息录入系统 ·选修课程信息录入 目录选择 密码对 ·选修课程信息保存 学生选课系统 密码系统 ·课程信息读入 ·密码验证系统 ·学生信息输入 ·权限限制系统 ·选课系统 ·数据保存 选修课数据维护系统 密码对 ·添加 ·修改 ·删除 ·以word格式输出 选修课程信息查找 ·按各种类型查找 密码错3次以上 退出程序
具体算法流程设计思路(流程图):
主程序 目录选择 1.学生选课系统;2.选修课程信息输出;3.选修课程信息查找;4.管理员选项; 5.退出系统。 1 2 3 学生选课系统 选修课程信息以word2003形式输出 学生信息输入 课程信息浏览 不选 少于 这门 20分 课 选课系统 选课成功 判断学分是否大于20分 大于20分结束选课 选课信息储存 选修课程信息从文件内读入 输入按什么查找 1.课程编号;2.课程名;3.课程种类;4.总课时;5.教学课时;6实验课时;7.学分;8.开课学期;9.已选人数。 输入查找的关键字 从文件内读入的课程信息与关键字逐一对比,完全匹配输出; 查找完毕 管理员选项 密码验证系统 读入系统时间,通过强制转换成unsigned long int型数据作为初始密码 用户输入密码(若是管理员会拥有密码钥匙,得出现在的密码,该密码每分钟都会变化) 密码正确进入管理员管理界面,密码不正确重新输入 密码输入错误3次以上 返回主菜单 选修课程信息查找 管理员模块 退出程序 管理员模块 3 目录选择 1.学生选课系统;2.选修课程信息管理系统;3.退出系统 1 2 5 学生 二级目录选择 选课1.新建选修课程信息;2.管理选修课程信息;3.统计每门课程选择系统 人数;4.选修课程信息输出;5.回到主菜单。 1 2 3 4 新建选修课程信息 管理选修课程信息 显示课程信息输入选修课程总数 输入需要添加或删除一门选每门以修改的数修课 按提示顺序输入每门课程word2003据类别和课程详细信息 已选格式输出 组数 人数 是否修改 输入新数输入新输入需数据保存 据 添加的要删除返回主菜单 课程信的组数 返回主菜单 息 完成删 完成修改,完成添保存新数加,保除,保存据 存新数新数据 据 返回主菜单 退出系统 程序源代码: #include x,xi,choice2,choice3,choice4,choice8,q=0,filein=0,limit=0,i,num,tonum,tcnum,ecnum,score,term,student,A,io=0,screen=0;/*-----变量定义区-----,x为现有选修课数量,目前不能超过10,后续与主程序合并时移动到定义区,xi为选修课信息录入循环变量*/ char choice1,choice5,choice6,choice7,name[10],kind[10]; int carenum[10]={0,0,0,0,0,0,0,0,0,0}; /*用于统计每门课程选修人数*/ int o,change=0,delatenum,e,u,stui=0,stuc=0; struct elective /*选修课程信息结构体*/ { int electivenum; /*选修课编号*/ char electivename[10]; /*选修课课名*/ char electivekind[10]; /*选修课性质,暂定考试考查之分*/ int totalclassnum; /*总课时*/ int techclassnum; /*授课课时*/ int expclassnum; /*实验课时*/ int credits; /*学分*/ int classterm; /*开课学期*/ int students; /*此门课选修人数*/ }; struct muticlass /*学生选择的课程信息结构体*/ { int stuchoice; int stuclassnum; char stuclassname; }; struct student /*学生信息结构体*/ { char stuname[10]; long stunum; int stucredits; struct muticlass mutichoice[20]; /*暂定每名学生最多选20门课*/ /*本结构体为嵌套结构体,完善功能时请注意嵌套结构*/ }; struct student studentcare[100]; /*暂定最多可以有100名学生选课*/ struct elective electivedata[10]; /*最多10门选修课*/ FILE *electivefp; /*选修课程信息文件指针*/ FILE *stufp; /*学生信息文件指针*/ FILE *outfp; /*课程信息输出文件指针*/ FILE *find; long now,midkey; /*now为密码算法中间变量,midkey为密码算法最终结果*/ int chancenum=0,m; /*chancenum为输入密码错我次数计数变量,m为主目录选择判断变量*/ unsigned long password,password2; struct tm *timenow; /*timenow为标准系统时间提取指针*/ textcolor(WHITE); system(\"cls\"); gotoxy(20,12); cprintf(\"Welcome to the Elective management system\"); /*一级主菜单*/ gotoxy(1,24); system(\"pause\"); t2:system(\"cls\"); gotoxy(24,11); cprintf(\"1.Students elective course system\"); gotoxy(24,12); cprintf(\"2.Elective information output\"); gotoxy(24,13); cprintf(\"3.Elective course information searching\"); gotoxy(24,14); cprintf(\"4.I'm the administrator!\"); gotoxy(24,15); cprintf(\"5.Exit the system\"); gotoxy(24,16); scanf(\"%d\ switch(choice8) { case 1: limit=0;goto students1; case 2: goto x11; case 3: goto x12; case 4: goto x7; case 5: goto x3; default: system(\"cls\");gotoxy(20,12);cprintf(\"wrong choice\");gotoxy(1,24);system(\"pause\");goto t2; } x7:textcolor(YELLOW); /*-----密码判断模块-----*/ time(&now); midkey=now; midkey=midkey/100; password=midkey; return2:system(\"cls\"); gotoxy(22,15); cprintf(\"Enter 1 to refresh the password.\"); gotoxy(25,12); cprintf(\"Please enter your password\\n\"); gotoxy(25,13); scanf(\"%ld\为用户输入的密码变量*/ if(chancenum<4) /*用户输入密码错误次数判断*/ { if(password2==password) {limit=1;goto x4;} else { if(password2==1) {goto x7;} else { system(\"cls\"); gotoxy(22,12); textcolor(RED); cprintf(\"password error\"); gotoxy(18,13); cprintf(\"please enter the right password\"); gotoxy(20,14); cprintf(\"You have only %d chances\ gotoxy(1,24); system(\"pause\"); if(chancenum==3) /*连续4次输入错误密码判断*/ {goto x6;} chancenum=chancenum+1; goto return2; } } } x6:system(\"cls\"); gotoxy(20,12); cprintf(\" Sorry,you have null chance.\"); gotoxy(1,24); goto x5; /*-----密码判断模块结束-----*/ x4: switch(limit) { case 0: textcolor(YELLOW);goto students1; case 1: textcolor(GREEN);goto t3; default: textcolor(RED);system(\"cls\");gotoxy(20,12);cprintf(\"None Limited\");gotoxy(1,24);system(\"pause\");textcolor(WHITE);goto t2; } t3:textcolor(GREEN); /*-----主程序开始-----*/ system(\"cls\"); gotoxy(20,12); cprintf(\"Welcome to the Elective management system\"); /*一级主菜单*/ gotoxy(1,24); system(\"pause\"); return1:system(\"cls\"); gotoxy(24,3); cprintf(\"Elective management system\"); /*选修课管理系统*/ gotoxy(24,11); cprintf(\"1.Students elective course system.\"); /*学生选课系统*/ gotoxy(24,12); cprintf(\"2.Elective course maintenance system.\"); /*课程信息维护系统*/ gotoxy(24,13); cprintf(\"3.Exit the system.\"); /*退出系统*/ gotoxy(24,14); scanf(\"%d\ switch(o) { case 1: goto students1; case 2: goto electivemans1; case 3: goto x3; default: system(\"cls\");gotoxy(12,12);cprintf(\"error choice,please make your choice again\\n\");gotoxy(1,24);system(\"pause\");goto return1; } electivemans1:system(\"cls\"); change=0; gotoxy(24,3); cprintf(\"Elective management system\"); /*二级主菜单*/ gotoxy(24,11); cprintf(\"1.New elective database\"); /*新建选修课程信息*/ gotoxy(24,12); cprintf(\"2.Maintain elective database\"); /*修改选修课程信息*/ gotoxy(24,13); cprintf(\"3.Show the number of statistical electives\"); /*统计每门课程选修人数*/ gotoxy(24,14); cprintf(\"4.Elective information output\"); /*课程信息输出*/ gotoxy(24,15); cprintf(\"5.Return to the main menu\"); /*返回主菜单*/ gotoxy(24,16); scanf(\"%d\ switch(m) /*主目录跳转判断*/ { case 1: goto x1; case 2: goto x2; case 3: goto x8; case 4: goto x11; case 5: goto return1; default: system(\"cls\");gotoxy(12,12);cprintf(\"error choice,please make your choice again\\n\");gotoxy(1,24);system(\"pause\");goto electivemans1; } x3:system(\"cls\");gotoxy(25,12);cprintf(\"Thanks for using this system\");gotoxy(1,24);goto x5; x1:electivefp=fopen(\"elective.dat\选修课程信息新建模块-----*/ if((electivefp=fopen(\"elective.dat\ { gotoxy(12,12); cprintf(\"connot open this file\"); gotoxy(11,13); cprintf(\"Please debug this program\"); gotoxy(12,17); system(\"pause\"); goto z1; } system(\"cls\"); gotoxy(12,12); cprintf(\"Please according to clew input elective course information\"); gotoxy(1,24); system(\"pause\"); a1:system(\"cls\"); gotoxy(12,12); cprintf(\"Please input the elective quantity,Up to 10.\"); /*输入此次录入选修课程门数*/ gotoxy(14,13); scanf(\"%d\输入选修课总课程数*/ if(x>10) /*总课程数小于10判断*/ { system(\"cls\"); gotoxy(12,12); cprintf(\"Up to 10\"); gotoxy(1,24); system(\"pause\"); goto a1; } for(xi=0;xi gotoxy(12,6); cprintf(\"1.elective course numbers\"); gotoxy(12,7); cprintf(\"2.name of elective course class\"); gotoxy(12,8); cprintf(\"3.elective properties\"); gotoxy(12,9); cprintf(\"4.elective total class number\"); gotoxy(12,10); cprintf(\"5.elective lecture class number\"); gotoxy(12,11); cprintf(\"6.elective experiment class number\"); gotoxy(12,12); cprintf(\"7.elective credits\"); gotoxy(12,13); cprintf(\"8.elective course semesters\"); gotoxy(12,14); cprintf(\"9.Add a elective course lesson.\"); gotoxy(12,15); cprintf(\"10.Delate a elective course lesson.\"); gotoxy(12,16); scanf(\"%d\错误项目定位*/ system(\"cls\"); if(choice2==9) {goto r9;} else if(choice2==10) {goto r10;} else {goto z6;} z6:system(\"cls\"); gotoxy(12,12); cprintf(\"Which group of curriculum information need to modify?\"); gotoxy(12,13); scanf(\"%d\错误组别定位*/ if(choice3 goto z6; } z7:xi=choice3-1; switch(choice2) /*错误信息修改*/ { case 1: q=1;goto r1; case 2: q=1;goto r2; case 3: q=1;goto r3; case 4: q=1;goto r4; case 5: q=1;goto r5; case 6: q=1;goto r6; case 7: q=1;goto r7; case 8: q=1;goto r8; case 9: q=1;goto r9; case 10: q=1;goto r10; default: system(\"cls\");gotoxy(12,12);cprintf(\"Wrong choice.Please make it again.\");gotoxy(1,24);system(\"pause\");goto z3; } } z2:if(change==0) {goto write1;} else { remove(\"elective.dat\"); electivefp=fopen(\"elective.dat\ goto write1; } write1:fprintf(electivefp,\"%d \\n\ for(xi=0;xi cprintf(\"Please enter the No.%d elective the experiment class number\gotoxy(12,12); scanf(\"%d\system(\"cls\"); gotoxy(12,11); cprintf(\"Please enter the No.%d elective credits\gotoxy(12,12); scanf(\"%d\system(\"cls\"); gotoxy(12,11); cprintf(\"Please enter the No.%d elective course semesters\gotoxy(12,12); scanf(\"%d\goto z4; r10:system(\"cls\"); gotoxy(12,12); cprintf(\"Which group of elective do you want to delate?\"); gotoxy(12,13); scanf(\"%d\ if(delatenum>0||delatenum fscanf(electivefp,\"%d %s %s %d %d %d %d %d %d\\n\&electivedata[xi].electivename,&electivedata[xi].electivekind,&electivedata[xi].totalclassnum,&electivedata[xi].techclassnum,&electivedata[xi].expclassnum,&electivedata[xi].credits,&electivedata[xi].classterm,&electivedata[xi].students); } stufp=fopen(\"stu.dat\ return4:system(\"cls\"); gotoxy(12,12); cprintf(\"Please enter your name\"); gotoxy(12,13); scanf(\"%s\ system(\"cls\"); gotoxy(12,12); cprintf(\"Please enter your student ID\"); gotoxy(12,13); scanf(\"%ld\ care2:system(\"cls\"); gotoxy(3,2); cprintf(\"Existing elective\"); for(u=0;u gotoxy(4,9); cprintf(\"Exp class:%d\ gotoxy(4,10); cprintf(\"Credits:%d\ gotoxy(4,11); cprintf(\"Class term:%d\ gotoxy(4,14); cprintf(\"Sure to choose this course? enter \\\"y\\\" for yes,\\\"n\\\" for no\"); gotoxy(4,15); scanf(\"%c\ switch(choice5) { case 121: goto care1; case 110: goto care2; default: system(\"cls\");gotoxy(12,12);cprintf(\"wrong choice\");goto return3; } care1:if(stuc>0) { for(xi=0;xi studentcare[stui].mutichoice[stuc].stuclassname=electivedata[choice4-1].electivename; x10:system(\"cls\"); gotoxy(12,12); cprintf(\"Course whether end? enter \\\"y\\\" for yes,\\\"n\\\" for no\"); gotoxy(12,13); scanf(\"%c\ switch(choice6) { case 121: goto x9; case 110: stuc++;goto care2; default: system(\"cls\");gotoxy(12,12);cprintf(\"wrong choice\");gotoxy(1,24);system(\"pause\");goto x10; } x9:if(studentcare[stui].stucredits<20) { system(\"cls\"); gotoxy(12,12); cprintf(\"Attention!Total credits less than 20!\"); gotoxy(1,24); system(\"pause\"); goto x10; } else { remove(\"stu.dat\"); stufp=fopen(\"stu.dat\ fprintf(stufp,\"%d \\n\ system(\"cls\"); gotoxy(12,12); cprintf(\"Elective success!\"); gotoxy(1,24); system(\"pause\"); return6:system(\"cls\"); gotoxy(12,12); cprintf(\"If others need courses? enter \\\"y\\\" for yes,\\\"n\\\" for no\"); gotoxy(12,13); scanf(\"%c\ switch(choice7) { case 121: stui++;goto return4; case 110: goto return5; default: system(\"cls\");gotoxy(12,12);cprintf(\"wrong choice\");gotoxy(1,24);system(\"pause\");goto return6; } return5: for(u=0;u electivefp=fopen(\"elective.dat\ fprintf(electivefp,\"%d \\n\ for(xi=0;xi system(\"cls\"); gotoxy(3,4); cprintf(\"Elective toll\"); for(u=0;u xx:io=0; system(\"cls\"); gotoxy(7,3); printf(\"a:search by electivenum;\\n b:search by electivename;\\n c:search by electivekind;\\n d:search by totalclassnum;\\n e:search by techclassnum;\\n f:search by expclassnum;\\n g:search by credits;\\n h:search by classterm;\\n i:search by students\\n\"); gotoxy(7,12); cprintf(\"j:Return to the main menu\"); gotoxy(7,13); scanf(\"%c\ switch(A) { case 97: goto a; case 98: goto b; case 99: goto c; case 100: goto d; case 101: goto e; case 102: goto f; case 103: goto g; case 104: goto h; case 105: goto i; case 106: goto t2; default: system(\"cls\");gotoxy(24,12);cprintf(\"wrong choice\\n\");system(\"pause\");goto xx; } a:screen=0; {system(\"cls\");gotoxy(24,12); cprintf(\"Please write down the electivenum\\n\"); gotoxy(24,13); scanf(\"%d\ for(i=0; i {system(\"pause\");system(\"cls\");} cprintf(\"Here is the information you want:\\n\"); cprintf(\"num:%d\\n\ cprintf(\"name:%s\\n\ cprintf(\"kind:%s\\n\ cprintf(\"class:%d\\n\ cprintf(\"techclass:%d\\n\ cprintf(\"expclass:%d\\n\ cprintf(\"credits:%d\\n\ cprintf(\"term:%d\\n\ cprintf(\"students:%d\\n\ io=1;screen=screen+1; } } if(io==0) { system(\"cls\"); cprintf(\"wrong number\"); gotoxy(1,24); system(\"pause\"); goto xx; } system(\"pause\"); goto xx;} b:screen=0; {system(\"cls\");gotoxy(24,12); cprintf(\"Please write down the electivename\\n\");gotoxy(24,13); scanf(\"%s\ for(i=0; i } } if(io==0) { system(\"cls\"); cprintf(\"wrong number\"); gotoxy(1,24); system(\"pause\"); goto xx; } system(\"pause\"); goto xx;} c:screen=0; {system(\"cls\");gotoxy(24,12); cprintf(\"Please write down the electivenkind\\n\");gotoxy(24,13); scanf(\"%s\ for(i=0; i d:screen=0; {system(\"cls\");gotoxy(24,12); cprintf(\"Please write down the totalclassnum\\n\");gotoxy(24,13); scanf(\"%d\ for(i=0; i cprintf(\"name:%s\\n\ cprintf(\"kind:%s\\n\ cprintf(\"class:%d\\n\ cprintf(\"techclass:%d\\n\ cprintf(\"expclass:%d\\n\ cprintf(\"credits:%d\\n\ cprintf(\"term:%d\\n\ cprintf(\"students:%d\\n\ io=1; screen=screen+1; } } if(io==0) { system(\"cls\"); cprintf(\"wrong number\"); gotoxy(1,24); system(\"pause\"); goto xx; } system(\"pause\"); goto xx;} f:screen=0; {system(\"cls\");gotoxy(24,12); cprintf(\"Please write down the expclassnum\\n\");gotoxy(24,13); scanf(\"%d\ for(i=0; i system(\"cls\"); cprintf(\"wrong number\"); gotoxy(1,24); system(\"pause\"); goto xx; } system(\"pause\"); goto xx;} g:screen=0; {system(\"cls\");gotoxy(24,12); cprintf(\"Please write down the credits\\n\");gotoxy(24,13); scanf(\"%d\ for(i=0; i system(\"cls\"); for(i=0; i cprintf(\"techclass:%d\\n\ cprintf(\"expclass:%d\\n\ cprintf(\"credits:%d\\n\ cprintf(\"term:%d\\n\ cprintf(\"students:%d\\n\ io=1;screen=screen+1; } } if(io==0) { system(\"cls\"); cprintf(\"wrong number\"); gotoxy(1,24); system(\"pause\"); goto xx; } system(\"pause\"); } goto t2; } x5:system(\"pause\"); } 密码钥匙程序源代码: #include long now,midkey; unsigned long password; char R=82; char a; struct tm *timenow; q1:system(\"cls\"); time(&now); midkey=now; midkey=midkey/100; password=midkey; gotoxy(20,12); printf(\"Now,the key is %ld\",password); gotoxy(2,15); printf(\"Enter R to refresh the key\\n\\n\\n\\n\\n\\n\\n\\n\"); scanf(\"%c\",&a); if(a==R) {goto q1;} } system(\"pause\"); 因篇幅问题不能全部显示,请点此查看更多更全内容