




已阅读5页,还剩27页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
学生信息管理系统在Linux下Shell编程实现:功能:对学生信息进行管理。要求实现数据的基本操作:学院和学生信息的增加,修改,删除,统计。具体要求:(1)构造两个类似数据库的文本文件: 第一个为学院信息文件(students.db),包含字段: 学院编号(唯一),学院名称 第二个为学生信息文件(colleges.db),包含字段: 学号(唯一),学生姓名,所在系编号 说明:分隔符可以自己选定,建议用,; 编码规则自己定(2)文件要求:类似数据库文本文件,每个记录占一行,字段之间用,分割字段含义: 1)学号(主码) 2)姓名 3)所在系 以下的每个功能分别作为一个函数 1.向该文件中插入记录 2.显示该文件中的每条记录的每个字段值 3.从该文件中删除指定学号的记录 shell程序代码如下:#! /bin/shinsert_s()file_name=/root/aillo/students.dbdialog -title Student: Insert a record -inputbox Please input the students information in the sort:(id,name,college): 20 50 2tmp.txtcontent=$(cat tmp.txt)IFS=,read sid sname sinmenu.txt sid=$(cat menu.txt) if $sid != 0 ;then dialog -title ERROR -msgbox Record has existed! 20 30 else echo $content$file_namedialog -title Reply Info -msgbox Add successfully! 10 30 fiinsert_c()file_name=/root/aillo/colleges.dbdialog -title College: Insert a record -inputbox Please input the colleges information in the sort(cid,cname): 20 50 2tmp.txtcontent=$(cat tmp.txt)IFS=,read cid cnametmp.txt cid=$(cat tmp.txt) if $cid != 0 ;then dialog -title ERROR -msgbox Record has existed! 30 50 else echo $content$file_namedialog -title Reply Info -msgbox Add successfully! 10 30 fidelete_s()file_name=/root/aillo/students.dbdialog -title Student: Delete a record -inputbox Please input the ID of the student you want to delete: 20 50 2tmp.txtread sidtmp.txtmv tmp.txt $file_namedialog -title Reply Info -msgbox the record has been delete! 10 30delete_c()file_name=/root/aillo/colleges.dbdialog -title College: Delete a record -inputbox Please input the ID of the college you want to delete: 20 50 2tmp.txtread cidtmp.txtmv tmp.txt $file_namedialog -title Reply Info -msgbox the record has been delete! 10 30display_s()file_name=/root/aillo/students.dbcat $file_name | while read linedoecho $linetmp.txtIFS=,read sid sname sint.txtecho sname: $snamet.txtecho sin: $sint.txtecho -t.txtIFS= donecontent=$(cat t.txt)dialog -title All Students Info -msgbox $content 50 50rm t.txtdisplay_c()file_name=/root/aillo/colleges.dbcat $file_name | while read linedoecho $linetmp.txtIFS=,read cid cnamet.txtecho cname: $cnamet.txtecho -t.txtIFS= donecontent=$(cat t.txt)dialog -title All colleges Info -msgbox $content 50 50rm t.txtcount()file_name=/root/aillo/students.dbdialog -title Count -inputbox Please input the id of college students you want to count: 20 50 2tmp.txtread p1tmp.txtIFS=,read p1 p2 p3tmp.txtecho $p1,$p2,$p3tmp.txtIFS= mv tmp.txt $file_namedialog -title Reply Info -msgbox The information has been modified! 10 30change_c()file_name=/root/aillo/colleges.dbdialog -title Modify Colleges Info -inputbox Please input the new information: 20 50 2tmp.txtIFS=,read p1 p2tmp.txtecho $p1,$p2tmp.txtIFS= mv tmp.txt $file_namedialog -title Reply Info -msgbox The information has been modified! 10 30status=1dialog -title Students Info Manage System -msgbox nWelccome to use the System!n 10 35if $? != 0 ;thensleep 1dialog -clearexit 0fiwhile $status = 1 dodialog -title Main Menu -menu Choices 15 20 2 1 Student 2 College 2tmp.txtMY_CHOICE=$(cat tmp.txt)if $? != 0 ;thensleep 1dialog -clearexit 0fiif $MY_CHOICE = 1 ;thendialog -title Student Info Manage -menu Choose Operation 20 30 7 1 INSERT 2 DELETE 3 MODIFY 4 COUNT 5 DISPLAY 6 BACK 7 EXIT 2tmp.txtif $? != 0 ;thensleep 1dialog -clearexit 0fichoice_2=$(cat tmp.txt)if $choice_2 = 1 ;theninsert_selif $choice_2 = 2 ;thendelete_selif $choice_2 = 3 ;thenchange_selif $choice_2 = 4 ;thencountelif $choice_2 = 5 ;thendisplay_selif $choice_2 = 6 ;thencontinueelsebreakfielsedialog -title College Info Manage -menu Choose Operation 20 30 7 1 INSERT 2 DELETE 3 MODIFY 4 COUNT 5 DISPLAY 6 BACK 7 EXIT 2tmp.txtif $? != 0 ;thensleep 1dialog -clearexit 0fichoice_2=$(cat tmp.txt)if $choice_2 = 1 ;theninsert_celif $choice_2 = 2 ;thendelete_celif $choice_2 = 3 ;thenchange_celif $choice_2 = 4 ;thencountelif $choice_2 = 5 ;thendisplay_celif $choice_2 = 6 ;thencontinueelsebreakfifidialog -yesno Do you want to continue ? 10 20if $? = 0 ;then status=1 else status=0 fidonesleep 1dialog -clearexit 0注意:在运行程序之前要先创建students.db和colleges.db这两个文件,不然会出错运行结果:(1)欢迎界面和主界面(2)选择操作界面(3)插入一条记录(4)显示所有的学生/学院信息(5)删除一条记录(6)修改记录(7)经过删除修改后的信息(8)统计某个学院的学生数学生成绩管理view plaincopy to clipboardprint?1. #PowerbyoAthEvil 2. #E-mail: 3. #Blog:/oathevil 4. #!/bin/bash 5. 6. DIALOG=/usr/bin/dialog7. TMP=./tmp/tmp.$8. FILE_FACULTY=./file/Faculty.dat9. FILE_STUDENT=./file/Student.dat10. FILE_SCORE=./file/Score.dat11. msg()12. $DIALOG-titlePrompt-msgbox$1153013. 14. 15. Insert()16. case$1in17. Faculty) 18. #Getfacultyidtobeinserted 19. $DIALOG-title$1-inputboxEnterFacultyId:630/20. 2$TMP_INSERT_INS21. faculty_id=$(cat$TMP_INSERT_INS) 22. #CheckIftherecordof$facultyexists 23. exportn=$(cat$FILE_FACULTY|grep$faculty_id,|wc-l|tr-d)24. ifx$n!=x0|x$faculty_id=x;then25. msgInvalidfacultyidoralreadyexsitance!26. return27. fi 28. #Getfacultynametobeinserted 29. $DIALOG-title$1-inputboxEnterFacultyName:630/30. 2$TMP_INSERT_INS31. faculty_name=$(cat$TMP_INSERT_INS) 32. #Checkiffacultyidandfacultynametobeinsertedarevalid 33. ifx$faculty_id=x|x$faculty_name=x;then34. ifx$faculty_id=x;then35. msgInvalidfacultyid!36. else37. msgInvalidfacultyname!38. fi39. else40. echo$faculty_id,$faculty_name$FILE_FACULTY41. msgInsertrecordsuccessfully!42. fi43. 44. rm-f$TMP_INSERT_INS45. ;46. Student) 47. #GetStudentidtobeinserted 48. $DIALOG-title$1-inputboxEnterStudentId:630/49. 2$TMP_STUDENT_INS50. student_id=$(cat$TMP_STUDENT_INS) 51. 52. #CheckIftherecordof$student_idexists 53. exportn=$(cat$FILE_STUDENT|grep$student_id,|wc-l|tr-d)54. ifx$n!=x0|x$student_id=x;then55. msgInvalidstudentidoralreadyexsitance!56. return57. fi58. 59. $DIALOG-title$1-inputboxEnterStudentName:630/60. 2$TMP_STUDENT_INS61. student_name=$(cat$TMP_STUDENT_INS)62. ifx$student_name=x;then63. msgInvalidstudentname!64. return65. fi66. 67. $DIALOG-title$1-inputboxEnterFacultyId:630/68. 2$TMP_STUDENT_INS69. faculty_id=$(cat$TMP_STUDENT_INS)70. 71. ifx$faculty_id=x;then72. msgInvalidfacultyid!73. return74. fi75. 76. $DIALOG-title$1-inputboxEnterStudentStatus:630/77. 2$TMP_STUDENT_INS78. student_status=$(cat$TMP_STUDENT_INS)79. 80. ifx$student_status=x;then81. msgInvalidstudentstatus!82. return83. fi84. echo$student_id,$student_name,$faculty_id,$student_status$FILE_STUDENT85. msgInsertrecordsuccessfully!86. 87. rm-f$TMP_STUDENT_INS88. ;89. Score) 90. #Getthescoreinfoofstudent 91. $DIALOG-title$1-inputboxEnterStudentId:630/92. 2$TMP_SCORE_INS93. student_id=$(cat$TMP_SCORE_INS)94. 95. ifx$student_id=x;then96. msgInvalidstudentid!97. return98. fi99. 100. $DIALOG-title$1-inputboxEnterStudentName:630/101. 2$TMP_SCORE_INS102. student_name=$(cat$TMP_SCORE_INS)103. 104. ifx$student_name=x;then105. msgInvalidstudentname!106. return107. fi108. 109. $DIALOG-title$1-inputboxEnterSubjectName:630/110. 2$TMP_SCORE_INS111. subject_name=$(cat$TMP_SCORE_INS)112. 113. ifx$subject_name=x;then114. msgInvalidsubjectname!115. return116. fi 117. 118. #CheckIftherecordof.exists 119. exportn=$(cat$FILE_SCORE|grep$student_id,|grep,$subject_name,|wc-l|tr-d)120. ifx$n!=x0|x$student_id=x;then121. msgTherecordhasalreadyexists!122. return123. fi124. 125. $DIALOG-title$1-inputboxEnterSubjectScore:630/126. 2$TMP_SCORE_INS127. subject_score=$(cat$TMP_SCORE_INS)128. 129. ifx$subject_score=x;then130. msgInvalidstudentscore!131. return132. fi133. 134. $DIALOG-title$1-inputboxEnterFinal/Makeup:630/135. 2$TMP_SCORE_INS136. comment=$(cat$TMP_SCORE_INS)137. 138. ifx$comment=x;then139. msgInvalidcomment!140. return141. fi142. 143. echo$student_id,$student_name,$subject_name,$subject_score,$comment$FILE_SCORE144. msgInsertrecordsuccessfully!145. 146. rm-f$TMP_SCORE_INS147. ;148. 149. esac150. 151. 152. Delete()153. case$1in154. Faculty) 155. #Getfacultyidoftherecordtobedeleted 156. $DIALOG-title$1-inputboxEnterFacultyIdtobedeleted:/157. 6302$TMP_FACULTY_DEL158. faculty_id=$(cat$TMP_FACULTY_DEL) 159. #CheckIftherecordof$facultyexists 160. exportn=$(cat$FILE_FACULTY|grep$faculty_id,|wc-l|tr-d)161. ifx$n=x0|x$faculty_id=x;then162. msgCannotfindinfoof$faculty_id!163. return164. fi 165. #Gettheinfothatdonotcontaintherecordwhoseidis$faculty_id 166. cat$FILE_FACULTY|grep-v$faculty_id,$TMP_FACULTY_DEL 167. #OverwritethefileFaculty.dat 168. mv$TMP_FACULTY_DEL$FILE_FACULTY169. msgDeleteInfoof$faculty_idsuccessfully!170. Student171. ;172. Student) 173. #Getstudentidoftherecordtobedeleted 174. $DIALOG-title$1-inputboxEnterStudentIdtobedeleted:/175. 6302$TMP_STUDENT_DEL176. student_id=$(cat$TMP_STUDENT_DEL) 177. 178. #CheckIftherecordof$facultyexists 179. exportn=$(cat$FILE_STUDENT|grep$student_id,|wc-l|tr-d)180. ifx$n=x0|x$student_id=x;then181. msgCannotfindinfoof$faculty_id!182. return183. fi 184. #Gettheinfothatdonotcontaintherecordwhoseidis$faculty_id 185. cat$FILE_STUDENT|grep-v$student_id,$TMP_STUDENT_DEL 186. #OverwritethefileFaculty.dat 187. mv$TMP_STUDENT_DEL$FILE_STUDENT188. msgDeleteInfoof$student_idsuccessfully!189. ;190. 191. Score) 192. #Getstudentidoftherecordtobedeleted 193. $DIALOG-title$1-inputboxEnterStudentIdtobedeleted:/194. 6302$TMP_SCORE_DEL195. student_id=$(cat$TMP_SCORE_DEL)196. 197. if$student_id=;then198. msgInvalidstudentid!199. return200. fi201. 202. $DIALOG-title$1-inputboxEnterSubjectNametobedeleted:/203. 6302$TMP_SCORE_DEL204. subject_name=$(cat$TMP_SCORE_DEL)205. 206. if$subject_name=;then207. msgInvalidstudentname!208. return209. fi210. 211. tmp_record=$(cat$FILE_SCORE|grep$student_id,|grep,$subject_name,)212. 213. if$tmp_record=;then214. msgCannotfindthe$subject_namescroeof$student_id!215. return216. fi 217. 218. 219. #Gettheinfothatdonotcontaintherecordwhoseidis$faculty_id 220. #cat$FILE_SCORE|grep-v/$student_id,a-zA-Z+,/$subject_name$TMP_SCORE_DEL 221. sed/$tmp_record/d$FILE_SCORE$TMP_SCORE_DEL 222. 223. #OverwritethefileFaculty.dat 224. mv$TMP_SCORE_DEL$FILE_SCORE225. msgDeleteInfoof$student_idsuccessfully!226. ;227. esac228. 229. 230. Modify()231. case$1in232. Faculty) 233. #Getfacultyidtobemodified 234. $DIALOG-title$1-inputboxEnterFacultyIdtobemodified:6302$TMP_FACULTY_MODIFY235. faculty_id=$(cat$TMP_FACULTY_MODIFY) 236. 237. #CheckIftherecordof$facultyexists 238. exportn=$(cat$FILE_FACULTY|grep$faculty_id,|wc-l|tr-d)239. ifx$n=x0|x$faculty_id=x;then240. msgCannotfindinfoof$faculty_id241. return242. fi 243. #Gettheoriginfacultyname 244. old_faculty_name=$(cat$FILE_FACULTY|grep$faculty_id,|awk-F,print$2) 245. #Prompttheoldfacultynamewhenaskingusertoinputthe/ 246. newfa
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 开关灯效果英语课堂游戏
- CN120204559A 气管插管机器人
- XXX乡村振兴工作经验材料范文
- 外研版八年级英语上册Unit1 This is me学情评估卷(含答案)
- 老年人体检项目课件
- CN120201699A 一种船用水下密封舱的主动冷却装置及方法
- CN120198910A 基于几何均值和图结构的细胞图像分析方法及系统
- CN120198471A 无监督的视频sar图像配准方法、装置、设备和介质
- 老师外出培训知识课件
- 配电网知识培训课件
- 人教新课标品德与社会五年级上册《诚信是金2》教学设计【教案】
- 2025浙江省储备粮管理集团有限公司所属企业招聘7人(第一批)笔试参考题库附带答案详解(10套)
- 2024年四川泸州医疗卫生辅助岗位招募笔试真题
- GB/T 45933-2025养老机构康复辅助器具基本配置
- 机加检验员考试试题及答案
- 2025安宁疗护实践指南(试行)知识测试试题及答案
- 弱视的课件教学课件
- 2025年时事政治试题库及答案(共550题)
- 掌上华医基层培训公卫人员考试题目含答案
- 中国城市轨道交通全自动运行系统技术指南
- 2025年河南省中考招生考试数学真题试卷(真题+答案)
评论
0/150
提交评论