学生信息管理.docx

上传人:b****5 文档编号:6656905 上传时间:2023-01-08 格式:DOCX 页数:35 大小:127.59KB
下载 相关 举报
学生信息管理.docx_第1页
第1页 / 共35页
学生信息管理.docx_第2页
第2页 / 共35页
学生信息管理.docx_第3页
第3页 / 共35页
学生信息管理.docx_第4页
第4页 / 共35页
学生信息管理.docx_第5页
第5页 / 共35页
点击查看更多>>
下载资源
资源描述

学生信息管理.docx

《学生信息管理.docx》由会员分享,可在线阅读,更多相关《学生信息管理.docx(35页珍藏版)》请在冰豆网上搜索。

学生信息管理.docx

学生信息管理

学生信息管理系统

在Linux下Shell编程实现:

功能:

对学生信息进行管理。

要求实现数据的基本操作:

学院和学生信息的增加,修改,删除,统计。

具体要求:

(1)构造两个类似数据库的文本文件:

  第一个为学院信息文件(students.db),包含字段:

  学院编号(唯一),学院名称

  第二个为学生信息文件(colleges.db),包含字段:

  学号(唯一),学生姓名,所在系编号

  说明:

分隔符可以自己选定,建议用",";编码规则自己定

(2)文件要求:

类似数据库文本文件,每个记录占一行,字段之间用","分割字段含义:

       1)学号(主码) 2)姓名  3)所在系

 以下的每个功能分别作为一个函数

      1.向该文件中插入记录

      2.显示该文件中的每条记录的每个字段值

      3.从该文件中删除指定学号的记录

 shell程序代码如下:

#!

/bin/sh

insert_s()

{

file_name="/root/aillo/students.db"

dialog--title"Student:

Insertarecord"--inputbox"Pleaseinputthestudent'sinformationinthesort:

(id,name,college):

"20502>tmp.txt

content=$(cattmp.txt)

IFS=","

readsidsnamesin

unsetIFS

grep-c"$sid"$file_name>menu.txt

sid=$(catmenu.txt)

if["$sid"!

="0"];then

dialog--title"ERROR"--msgbox"Recordhasexisted!

"2030

else

echo"$content">>$file_name

dialog--title"ReplyInfo"--msgbox"Addsuccessfully!

"1030

fi

}

insert_c()

{

file_name="/root/aillo/colleges.db"

dialog--title"College:

Insertarecord"--inputbox"Pleaseinputthecollege'sinformationinthesort(cid,cname):

"20502>tmp.txt

content=$(cattmp.txt)

IFS=","

readcidcname

unsetIFS

grep-c"$cid"$file_name>tmp.txt

cid=$(cattmp.txt)

if["$cid"!

="0"];then

dialog--title"ERROR"--msgbox"Recordhasexisted!

"3050

else

echo"$content">>$file_name

dialog--title"ReplyInfo"--msgbox"Addsuccessfully!

"1030

fi

}

delete_s()

{file_name="/root/aillo/students.db"

dialog--title"Student:

Deletearecord"--inputbox"PleaseinputtheIDofthestudentyouwanttodelete:

"20502>tmp.txt

readsid

grep-v$sid$file_name>tmp.txt

mvtmp.txt$file_name

dialog--title"ReplyInfo"--msgbox"therecordhasbeendelete!

"1030

}

delete_c()

{file_name="/root/aillo/colleges.db"

dialog--title"College:

Deletearecord"--inputbox"PleaseinputtheIDofthecollegeyouwanttodelete:

"20502>tmp.txt

readcid

grep-v$cid$file_name>tmp.txt

mvtmp.txt$file_name

dialog--title"ReplyInfo"--msgbox"therecordhasbeendelete!

"1030

}

display_s()

{file_name="/root/aillo/students.db"

cat$file_name|whilereadline

do

echo$line>tmp.txt

IFS=","

readsidsnamesin

echo"sid:

$sid">>t.txt

echo"sname:

$sname">>t.txt

echo"sin:

$sin">>t.txt

echo"---------------------">>t.txt

IFS=""

done

content=$(catt.txt)

dialog--title"AllStudents'Info"--msgbox"$content"5050

rmt.txt

}

display_c()

{file_name="/root/aillo/colleges.db"

cat$file_name|whilereadline

do

echo$line>tmp.txt

IFS=","

readcidcname

echo"cid:

$cid">>t.txt

echo"cname:

$cname">>t.txt

echo"---------------------">>t.txt

IFS=""

done

content=$(catt.txt)

dialog--title"Allcolleges'Info"--msgbox"$content"5050

rmt.txt

}

count()

{

file_name="/root/aillo/students.db"

dialog--title"Count"--inputbox"Pleaseinputtheidofcollegestudentsyouwanttocount:

"20502>tmp.txt

readp1

dialog--title"ReplyInfo"--msgbox"Thereare`grep-c$p1$file_name`studentsinthe$p1college!

"1030

}

change_s()

{

file_name="/root/aillo/students.db"

dialog--title"ModifyStudent'sInfo"--inputbox"Pleaseinputthenewinformationyouwanttomodifyinthesort(sid,sname,sin):

"20502>tmp.txt

IFS=","

readp1p2p3

grep-v$p1$file_name>tmp.txt

echo"$p1,$p2,$p3">>tmp.txt

IFS=""

mvtmp.txt$file_name

dialog--title"ReplyInfo"--msgbox"Theinformationhasbeenmodified!

"1030

}

change_c()

{

file_name="/root/aillo/colleges.db"

dialog--title"ModifyCollege'sInfo"--inputbox"Pleaseinputthenewinformation:

"20502>tmp.txt

IFS=","

readp1p2

grep-v$p1$file_name>tmp.txt

echo"$p1,$p2">>tmp.txt

IFS=""

mvtmp.txt$file_name

dialog--title"ReplyInfo"--msgbox"Theinformationhasbeenmodified!

"1030

}

status=1

dialog--title"Students'InfoManageSystem"--msgbox"\\nWelccometousetheSystem!

\\n"1035

if[$?

!

=0];then

sleep1

dialog--clear

exit0

fi

while["$status"="1"]

do

dialog--title"MainMenu"--menu"Choices"152021"Student"2"College"2>tmp.txt

MY_CHOICE=$(cattmp.txt)

if[$?

!

=0];then

sleep1

dialog--clear

exit0

fi

if["$MY_CHOICE"="1"];then

dialog--title"StudentInfoManage"--menu"ChooseOperation"203071"INSERT"2"DELETE"3"MODIFY"4"COUNT"5"DISPLAY"6"BACK"7"EXIT"2>tmp.txt

if[$?

!

=0];then

sleep1

dialog--clear

exit0

fi

choice_2=$(cattmp.txt)

if["$choice_2"="1"];then

insert_s

elif["$choice_2"="2"];then

delete_s

elif["$choice_2"="3"];then

change_s

elif["$choice_2"="4"];then

count

elif["$choice_2"="5"];then

display_s

elif["$choice_2"="6"];then

continue

else

break

fi

else

dialog--title"CollegeInfoManage"--menu"ChooseOperation"203071"INSERT"2"DELETE"3"MODIFY"4"COUNT"5"DISPLAY"6"BACK"7"EXIT"2>tmp.txt

if[$?

!

=0];then

sleep1

dialog--clear

exit0

fi

choice_2=$(cattmp.txt)

if["$choice_2"="1"];then

insert_c

elif["$choice_2"="2"];then

delete_c

elif["$choice_2"="3"];then

change_c

elif["$choice_2"="4"];then

count

elif["$choice_2"="5"];then

display_c

elif["$choice_2"="6"];then

continue

else

break

fi

fi

dialog--yesno"Doyouwanttocontinue?

"1020

if[$?

=0];then

status=1

else

status=0

fi

done

sleep1

dialog--clear

exit0

注意:

在运行程序之前要先创建students.db和colleges.db这两个文件,不然会出错

运行结果:

(1)欢迎界面和主界面

(2)"选择操作"界面

(3)插入一条记录

(4)显示所有的学生/学院信息

(5)删除一条记录

(6)修改记录

(7)经过删除修改后的信息

(8)统计某个学院的学生数

学生成绩管理

 

viewplaincopytoclipboardprint?

1.##Power by oAthEvil 

2.##E-mail:

 oathevil@ 

3.##Blog:

  

4.#!

 /bin/bash  

5.  

6.DIALOG=/usr/bin/dialog  

7.TMP="./tmp/tmp.$"  

8.FILE_FACULTY="./file/Faculty.dat"  

9.FILE_STUDENT="./file/Student.dat"  

10.FILE_SCORE="./file/Score.dat"  

11.msg() {  

12.  $DIALOG --title "Prompt" --msgbox "$1" 15 30  

13.}  

14.  

15.Insert() {  

16.    case "$1" in  

17.        Faculty) 

18.              ####  Get faculty id to be inserted  

19.              $DIALOG --title "$1" --inputbox "Enter [Faculty Id]:

" 6 30/  

20.                 2> ${TMP}_INSERT_INS  

21.              faculty_id=$(cat ${TMP}_INSERT_INS) 

22.                #### Check If the record of $faculty exists  

23.                export n=$(cat $FILE_FACULTY | grep "^${faculty_id}," | wc -l | tr -d " ")  

24.                if [ "x$n" !

= "x0" ] || [ "x$faculty_id" = "x" ] ; then  

25.                    msg "Invalid faculty id or already exsitance !

"  

26.                    return  

27.                fi 

28.              ####  Get faculty name to be inserted  

29.              $DIALOG --title "$1" --inputbox "Enter [Faculty Name]:

" 6 30/  

30.                 2> ${TMP}_INSERT_INS  

31.              faculty_name=$(cat ${TMP}_INSERT_INS) 

32.              ####  Check if faculty id and faculty name to be inserted are valid  

33.              if [ "x$faculty_id" = "x" ] || [ "x$faculty_name" = "x" ] ; then  

34.                  if [ "x$faculty_id" = "x" ] ; then  

35.                msg "Invalid  faculty id !

"  

36.                  else  

37.                msg "Invalid faculty name !

"  

38.                  fi  

39.              else  

40.                  echo $faculty_id,$faculty_name >> $FILE_FACULTY  

41.                  msg "Insert record successfully !

"  

42.              fi  

43.                

44.              rm -f ${TMP}_INSERT_INS  

45.              ;;  

46.        Student) 

47.              ####  Get Student id to be inserted  

48.              $DIALOG --title "$1" --inputbox "Enter [Student Id]:

" 6 30/  

49.                 2> ${TMP}_STUDENT_INS  

50.              student_id=$(cat ${TMP}_STUDENT_INS) 

51.               

52.              #### Check If the record of $student_id exists  

53.                export n=$(cat $FILE_STUDENT | grep "^${student_id}," | wc -l | tr -d " ")  

54.                if [ "x$n" !

= "x0" ] || [ "x$student_id" = "x" ] ; then  

55.                    msg "Invalid student id or already exsitance !

"  

56.                    return  

57.                fi  

58.                

59.              $DIALOG --title "$1" --inputbox "Enter [Student Name]:

" 6 30/  

60.                 2> ${TMP}_STUDENT_INS  

61.              student_name=$(cat ${TMP}_STUDENT_INS)      

62.                if [ "x$student_name" = "x" ] ; then  

63.                    msg "Invalid student name !

"  

64.                    return  

65.                fi      

66.                

67.              $DIALOG --title "$1" --inputbox "Enter [Faculty Id]:

" 6 30/  

68.                 2> ${TMP}_STUDENT_INS  

69.              faculty_id=$(cat ${TMP}_STUDENT_INS)  

70.                

71.              if [ "x$faculty_id" = "x" ] ; then  

72.                    msg "Invalid faculty id !

"  

73.                    return  

74.                fi  

75.                  

76.              $DIALOG --title "$1" --inputbox "Enter [Student Status]:

" 6 30/  

77.                 2> ${TMP}_STUDENT_INS  

78.              student_status=$(cat ${TMP}_STUDENT_INS)  

79.                

80.              if [ "x$student_status" = "x" ] ; then  

81.                    msg "Invalid student status!

"  

82.                    return  

83.                fi  

84.                echo $student_id,$student_name,$faculty_id,$student_status>> $FILE_STUDENT  

85.                msg "Insert record suc

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 医药卫生 > 基础医学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1