当前位置:   article > 正文

学生选修课程系统设计(大一课设纯c语言)_c语言课程设计学生选修课系统

c语言课程设计学生选修课系统

学生选修课程系统

1. 课程信息录入

2. 课程信息浏览

3. 课程信息查询

4. 课程信息修改

5. 学生选修课程

0. 退出

程序的主界面

    1. 设计要求:

试设计一选修课程系统,使之能提供以下功能:

系统以菜单方式工作

课程信息录入功能--输入

课程信息浏览功能--输出

课程信息查询功能--算法

查询方式

按学分查询

按课程性质查询

学生选修课程(可选项)

  1. 设计提示:

假定有n门课程,每门课程有:课程编号,课程名称,课程性质(公共课、必修课、选修课),总学时,授课学时,实验或上机学时,学分,开课学期等信息,学生可按要求(如总学分不得少于60)自由选课。

题目七:

  1. #include <stdio.h>
  2. #include<string.h>
  3. #include<stdlib.h>
  4. #define N 100
  5. struct lesson {
  6. int id;
  7. char name[100];
  8. char quality[100];
  9. int Total_credit_hours;
  10. int Computer_based_hours;
  11. int Credits;
  12. char Commencement_ofemesters[100];
  13. int least_Credits;
  14. };
  15. struct student{
  16. int id;
  17. char name[100];
  18. int choose_num;
  19. struct lesson le[1000];
  20. };
  21. struct lesson lesson_1[1000]; int num = 0;
  22. struct student stu[1000];
  23. int j=0;
  24. int chose() {
  25. int a;
  26. printf("\t\t\t\t\t请输入您的操作(输入数字 例如 输入1 代表数字1后操作):\n\f");
  27. printf("\t\t\t\t\t\t\t\t");
  28. scanf("%d", &a);
  29. return a;
  30. }
  31. void in_put() {
  32. int i = num; char s[100];
  33. do {
  34. printf("\n\t\t\t\t\t请输入课程id\t");
  35. scanf("%d", &lesson_1[i].id);
  36. printf("\t\t\t\t\t请输入课程name\t");
  37. scanf("%s",lesson_1[i].name);
  38. printf("\t\t\t\t\t请输入课程quality(特性)\t");
  39. scanf("%s", lesson_1[i].quality);
  40. printf("\t\t\t\t\t请输入课程Total_credit_hours(总学时)\t");
  41. scanf("%d", &lesson_1[i].Total_credit_hours);
  42. printf("\t\t\t\t\t请输入课程Computer_based_hours(上机学时,若没有为0)\t");
  43. scanf("%d", &lesson_1[i].Computer_based_hours);
  44. printf("\t\t\t\t\t请输入课程 Credits(学分)\t");
  45. scanf("%d",& lesson_1[i].Credits);
  46. printf("\t\t\t\t\t请输入课程Commencement_ofemesters(开课学期)\t");
  47. scanf("%s", lesson_1[i].Commencement_ofemesters);
  48. printf("\t\t\t\t\t是否继续录入\n\t\t\t\t\t1.是\n\t\t\t\t\t0.否,返回主菜单\n");
  49. i++; num++;
  50. } while (chose() == 1);
  51. }
  52. void read() {
  53. FILE*fp1,*fp2;int i=0,j=0;
  54. //fp1=fopen("lesson_data","a+");
  55. //fp2=fopen("stu_data","a+");
  56. //if((fp1=fopen("lesson_data.txt","r"))==NULL||(fp2=fopen("stu_data.txt","r"))==NULL){
  57. // printf("\t\t\t\t\t打开文件失败\n");
  58. // exit(0);
  59. //}
  60. //
  61. // /*fprintf(fp1,"序号 %d 名字 %s 特性 %s 总学时 %d 上机学时%d 学分%d 学期 %s",lesson_1[i].id,lesson_1[i].name,lesson_1[i].quality,lesson_1[i].Total_credit_hours,lesson_1[i].Computer_based_hours,lesson_1[i].Credits,lesson_1[i].Commencement_ofemesters);
  62. // fprintf(fp2,"学号 %d 姓名 %s 选课数量 %d 选择课程信息 序号 %d 名字 %s 特性 %s 总学时 %d 上机学时%d 学分%d 学期 %s",stu[i].id,stu)
  63. // */
  64. //for(i=0;i<N;i++){fscanf(fp1,"序号:%d \n名字:%s\n 性质:%s\n总学时:%d\n 上机学时:%d \n学分:%d\n开学日期: %s",&lesson_1[i].id,lesson_1[i].name,lesson_1[1].quality,&lesson_1[i].Total_credit_hours,&lesson_1[i].Computer_based_hours,&lesson_1[i].Credits,lesson_1[i].Commencement_ofemesters);if(lesson_1[i].id!=0)num++; }
  65. //for(i=0;i<N;i++)fscanf(fp2,"%d %s %d",&stu[i].id,stu[i].name,&stu[i].choose_num);
  66. //for(i=0;i<N;i++){
  67. // for(j=0;j<N;j++){
  68. // fscanf(fp2,"%d %s %s %d %d %d %s",&stu[i].le[j].id,stu[i].le[j].name,stu[i].le[j].quality,&stu[i].le[j].Total_credit_hours,&stu[i].le[j].Computer_based_hours,&stu[i].le[j].Credits,stu[i].le[j].Commencement_ofemesters);
  69. // }
  70. //}
  71. printf("%s",lesson_1[0].name);
  72. //printf("\t\t\t\t\t\t\t文件系统加载成功\n");
  73. //fclose(fp1);
  74. //fclose(fp2);
  75. for (i = 0; i < num; i++)
  76. {
  77. printf("\t\t\t\t\t第%d门课程id\t",i+1);
  78. printf("%d\n", lesson_1[i].id);
  79. printf("\t\t\t\t\t第%d门课程name\t",i+1);
  80. printf("%s\n", lesson_1[i].name);
  81. printf("\t\t\t\t\t第%d门课程quality(特性)\t",i+1);
  82. printf("%s\n", lesson_1[i].quality);
  83. printf("\t\t\t\t\t第%d门课程Total_credit_hours(总学时)\t",i+1);
  84. printf("%d\n", lesson_1[i].Total_credit_hours);
  85. printf("\t\t\t\t\t第%d门课程Computer_based_hours(上机学时,若没有为0)\t",i+1);
  86. printf("%d\n", lesson_1[i].Computer_based_hours);
  87. printf("\t\t\t\t\t第%d门课程 Credits(学分)\t",i+1);
  88. printf("%d\n", lesson_1[i].Credits);
  89. printf("\t\t\t\t\t第%d门课程Commencement_ofemesters(开课学期)\t",i+1);
  90. printf("%s\n", lesson_1[i].Commencement_ofemesters);
  91. }
  92. }
  93. void inquire(){
  94. int k =0,t=0;int i=0;char c[100];
  95. // printf("\t\t\t\t\t查询方式\n");
  96. // printf("\t\t\t\t\t1.按学分查询\n");
  97. // printf("\t\t\t\t\t2按课程性质查询\n.");
  98. do{
  99. printf("\t\t\t\t\t查询方式\n");
  100. printf("\t\t\t\t\t1.按学分查询\n");
  101. printf("\t\t\t\t\t2按课程性质查询\n.");
  102. k=chose();
  103. if(k==1)
  104. {
  105. printf("\t\t\t\t\t请输入该课程的学分\t");
  106. scanf("%d",&t);
  107. for (i = 0; i < num; i++)
  108. {
  109. if(lesson_1[i].Credits==t){
  110. printf("\t\t\t\t\t课程id\t");
  111. printf("%d\n", lesson_1[i].id);
  112. printf("\t\t\t\t\t课程name\t");
  113. printf("%s\n", lesson_1[i].name);
  114. printf("\t\t\t\t\t课程quality(特性)\t");
  115. printf("%s\n", lesson_1[i].quality);
  116. printf("\t\t\t\t\t课程Total_credit_hours(总学时)\t");
  117. printf("%d\n", lesson_1[i].Total_credit_hours);
  118. printf("\t\t\t\t\t课程Computer_based_hours(上机学时,若没有为0)\t");
  119. printf("%d\n", lesson_1[i].Computer_based_hours);
  120. printf("\t\t\t\t\t课程 Credits(学分)\t");
  121. printf("%d\n", lesson_1[i].Credits);
  122. printf("\t\t\t\t\t课程Commencement_ofemesters(开课学期)\t");
  123. printf("%s\n", lesson_1[i].Commencement_ofemesters);}
  124. }
  125. }
  126. if(k==2)
  127. {
  128. printf("\t\t\t\t\t请输入该课程的性质\t(如必修课 公共课 选修课)");
  129. scanf("%s",c);
  130. for (i = 0; i < num; i++)
  131. {
  132. if(strcmp(lesson_1[i].quality,c)==0){
  133. printf("\t\t\t\t\t课程id\t");
  134. printf("%d\n", lesson_1[i].id);
  135. printf("\t\t\t\t\t课程name\t");
  136. printf("%s\n", lesson_1[i].name);
  137. printf("\t\t\t\t\t课程quality(特性)\t");
  138. printf("%s\n", lesson_1[i].quality);
  139. printf("\t\t\t\t\t课程Total_credit_hours(总学时)\t");
  140. printf("%d\n", lesson_1[i].Total_credit_hours);
  141. printf("\t\t\t\t\t课程Computer_based_hours(上机学时,若没有为0)\t");
  142. printf("%d\n", lesson_1[i].Computer_based_hours);
  143. printf("\t\t\t\t\t课程 Credits(学分)\t");
  144. printf("%d\n", lesson_1[i].Credits);
  145. printf("\t\t\t\t\t课程Commencement_ofemesters(开课学期)\t");
  146. printf("%s\n", lesson_1[i].Commencement_ofemesters);}
  147. }
  148. }printf("\t\t\t\t\t是否继续查询\n\t\t\t\t\t1.是\n\t\t\t\t\t0.否,返回主菜单\n");
  149. }while(chose()==1);
  150. }
  151. void print_mune1() {
  152. printf("\t\t\t\t\t\t\t学生选修课程系统\t\n\n\n\n\n");
  153. printf("\t\t\t\t\t\t\t1. 课程信息录入\n\n\n");
  154. printf("\t\t\t\t\t\t\t2. 课程信息浏览\n\n\n");
  155. printf("\t\t\t\t\t\t\t3. 课程信息查询\n\n\n");
  156. printf("\t\t\t\t\t\t\t4. 课程信息修改\n\n\n");
  157. printf("\t\t\t\t\t\t\t5. 学生选修课程\n\n\n");
  158. printf("\t\t\t\t\t\t\t0. 退出\n\n\n\n\n");
  159. }
  160. void change(){
  161. int id,i;
  162. printf("\t\t\t\t\t请输入要修改课程的id\t");
  163. scanf("%d",&id);
  164. do {
  165. for( i=0;i<num;i++){
  166. if(lesson_1[i].id==id){
  167. printf("\n\t\t\t\t\t请输入课程id\t");
  168. scanf("%d", &lesson_1[i].id);
  169. printf("\t\t\t\t\t请输入课程name\t");
  170. scanf("%s",lesson_1[i].name);
  171. printf("\t\t\t\t\t请输入课程quality(特性)\t");
  172. scanf("%s", lesson_1[i].quality);
  173. printf("\t\t\t\t\t请输入课程Total_credit_hours(总学时)\t");
  174. scanf("%d", &lesson_1[i].Total_credit_hours);
  175. printf("\t\t\t\t\t请输入课程Computer_based_hours(上机学时,若没有为0)\t");
  176. scanf("%d", &lesson_1[i].Computer_based_hours);
  177. printf("\t\t\t\t\t请输入课程 Credits(学分)\t");
  178. scanf("%d",& lesson_1[i].Credits);
  179. printf("\t\t\t\t\t请输入课程Commencement_ofemesters(开课学期)\t");
  180. scanf("%s", lesson_1[i].Commencement_ofemesters);
  181. }
  182. }
  183. printf("\t\t\t\t\t是否继续修改\n\t\t\t\t\t1.是\n\t\t\t\t\t0.否,返回主菜单\n");
  184. } while (chose() == 1);
  185. printf("\t\t\t\t\t已回到主菜单");
  186. }
  187. void major(){
  188. int n,i,t=0,sum=0,k,j=0;
  189. do
  190. { printf("\t\t\t\t\t请输入学号\t");
  191. scanf("%d",&stu[j].id);
  192. printf("\t\t\t\t\t请输入名字\t");
  193. scanf("%s",stu[j].name);
  194. //printf("\t\t\t\t\t请输入选课数量\t");
  195. //scanf("%d",&stu[j].choose_num);
  196. read();
  197. printf("\t\t\t\t\t输入想选择课程,输入一共要选的课程数量 n,和想选课程的第x位置\n");
  198. printf("\t\t\t\t\t例如\t3\n\t\t\t\t\t\t1 2 3\n");
  199. printf("\t\t\t\t\t请输入: n ");
  200. scanf("%d",&n);
  201. stu[j].choose_num=n;
  202. for(i=0;i<n;i++){
  203. printf("\t\t\t\t\t请输入第%d课程序号\n",i+1);
  204. printf("\t\t\t\t\t");
  205. scanf("%d",&t);
  206. stu[j].le[i]=lesson_1[t-1];
  207. /*stu[j].le[i].id=lesson_1[t-1].id;
  208. stu[j].le[i].Computer_based_hours=lesson_1[t-1].Computer_based_hours;
  209. stu[j].le[i].Credits=lesson_1[t-1].Credits;
  210. strcpy(stu[j].le[i].name,lesson_1[t-1].name);
  211. strcpy(stu[j].le[i].quality,lesson_1[t-1].quality);
  212. strcpy(stu[j].le[i].Commencement_ofemesters,lesson_1[t-1].Commencement_ofemesters);
  213. sum+=lesson_1[t-1].Credits;*/
  214. }
  215. sum+=lesson_1[t-1].Credits;
  216. if(sum<60)printf("\t\t\t\t\t你的总学分少于60\n");
  217. printf("\t\t\t\t\t是否重新选课\n\t\t\t\t\t1.是\n\t\t\t\t\t0.否,返回主菜单\n");
  218. }while(chose()==1);
  219. j++;
  220. printf("\t\t\t\t\t已回到主菜单");
  221. }
  222. int key(){
  223. char k[100]="key";
  224. char s[100];
  225. printf("\t\t\t\t\t该功能需要管理员密码\n");
  226. printf("\t\t\t\t\t请输入密码:(退出请输入0)\n");
  227. printf("\t\t\t\t\t");
  228. scanf("%s",s);
  229. if(strcmp(s,k)==0)return 1;
  230. return 0;
  231. }
  232. void save(){
  233. FILE*fp1,*fp2;int i=0,j=0;
  234. //fp1=fopen("lesson_data","a+");
  235. //fp2=fopen("stu_data","a+");
  236. if((fp1=fopen("lesson_data.txt","wb"))==NULL||(fp2=fopen("stu_data.txt","wb"))==NULL){
  237. printf("\t\t\t\t\t打开文件失败\n");
  238. exit(0);
  239. }
  240. for(i=0;i<N;i++)if(strcmp(lesson_1[i].name,"\0"))fprintf(fp1,"序号:%-10d \n名字:%-10s\n 总学时:%-10d\n性质:%-10s\n 上机学时:%-10d \n学分:%-10d\n开学日期: %-10s\n",lesson_1[i].id,lesson_1[i].name,lesson_1[i].Total_credit_hours,lesson_1[i].quality,lesson_1[i].Computer_based_hours,lesson_1[i].Credits,lesson_1[i].Commencement_ofemesters);
  241. for(i=0;i<N;i++)if(strcmp(stu[i].name,"\0"))fprintf(fp2,"%d %s %d",stu[i].id,stu[i].name,stu[i].choose_num);
  242. for(i=0;i<N;i++){
  243. for(j=0;j<N;j++){
  244. if(strcmp(stu[i].name,"\0")&&strcmp(stu[i].le[j].name,"0"))
  245. fprintf(fp2,"%d %s %s %d %d %d %s",stu[i].le[j].id,stu[i].le[j].name,stu[i].le[j].quality,stu[i].le[j].Total_credit_hours,stu[i].le[j].Computer_based_hours,stu[i].le[j].Credits,stu[i].le[j].Commencement_ofemesters);
  246. }
  247. }
  248. printf("\t\t\t\t\t\t\t信息已保存\n");
  249. fclose(fp1);
  250. fclose(fp2);
  251. }
  252. void load(){
  253. FILE*fp1,*fp2;int i=0,j=0;
  254. //fp1=fopen("lesson_data","a+");
  255. //fp2=fopen("stu_data","a+");
  256. if((fp1=fopen("lesson_data.txt","r"))==NULL||(fp2=fopen("stu_data.txt","r"))==NULL){
  257. printf("\t\t\t\t\t打开文件失败\n");
  258. exit(0);
  259. }
  260. /*fprintf(fp1,"序号 %d 名字 %s 特性 %s 总学时 %d 上机学时%d 学分%d 学期 %s",lesson_1[i].id,lesson_1[i].name,lesson_1[i].quality,lesson_1[i].Total_credit_hours,lesson_1[i].Computer_based_hours,lesson_1[i].Credits,lesson_1[i].Commencement_ofemesters);
  261. fprintf(fp2,"学号 %d 姓名 %s 选课数量 %d 选择课程信息 序号 %d 名字 %s 特性 %s 总学时 %d 上机学时%d 学分%d 学期 %s",stu[i].id,stu)
  262. */
  263. for(i=0;i<N;i++){/*if(strcmp(lesson_1[i].name,"\0"))*/fscanf(fp1,"序号:%d \n名字:%s\n 总学时:%d\n性质:%s\n 上机学时:%d \n学分:%d\n开学日期: %s\n",&lesson_1[i].id,lesson_1[i].name,&lesson_1[i].Total_credit_hours,lesson_1[i].quality,&lesson_1[i].Computer_based_hours,&lesson_1[i].Credits,lesson_1[i].Commencement_ofemesters);if(lesson_1[i].id!=0)num++;}
  264. for(i=0;i<N;i++)/*if(strcmp(stu[i].name,"\0"))*/fscanf(fp2,"%d %s %d",&stu[i].id,stu[i].name,&stu[i].choose_num);
  265. for(i=0;i<N;i++){
  266. for(j=0;j<N;j++){
  267. /* if(strcmp(stu[i].name,"\0"))*/fscanf(fp2,"%d %s %s %d %d %d %s",&stu[i].le[j].id,stu[i].le[j].name,stu[i].le[j].quality,&stu[i].le[j].Total_credit_hours,&stu[i].le[j].Computer_based_hours,&stu[i].le[j].Credits,stu[i].le[j].Commencement_ofemesters);
  268. }
  269. }
  270. //printf("%s",lesson_1[0].name);
  271. printf("\t\t\t\t\t\t\t文件系统加载成功\n");
  272. fclose(fp1);
  273. fclose(fp2);
  274. }
  275. int main()
  276. {int p;
  277. load();
  278. do{
  279. print_mune1();
  280. p=chose();
  281. if (p == 1 && key()) //1. 课程信息录入
  282. {
  283. in_put();
  284. }
  285. if (p== 2) //2. 课程信息浏览
  286. {
  287. read();
  288. }
  289. if(p==3){//3. 课程信息查询
  290. inquire();
  291. }
  292. if(p==4&&key()){//4. 课程信息修改
  293. change();
  294. }
  295. if(p==5){//5. 学生选修课程
  296. major();
  297. }
  298. if(p==0){//0. 退出
  299. break;
  300. }
  301. }while(1);
  302. save();
  303. }

  1. 支持文件读写两个结构体变量。
  2. 课设哈哈哈。
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/615740
推荐阅读
相关标签
  

闽ICP备14008679号