lua 自学笔记 练习篇-学生成绩管理系统之教师文档

tea.lua


function query_stu_interface()  --按条件查询个别学生的成绩
require "stu"
while true do
os.execute("cls")
print("1.按学号查询")
print("2.按姓名查询")
print("3.返回上一层")
choose = io.read()
if choose == "1" then
os.execute("cls")
print("请输入要查找的学生的学号")
data = io.read()
student = query_stu(stu,data,choose)
if student then
print_scorce(student)
else
print("没有这个学号的学生")
print("按enter继续")
io.read()
end
elseif choose == "2" then
os.execute("cls")
print("请输入要查找的学生的姓名")
data = io.read()
student = query_stu(stu,data,choose)
if student then
print_scorce(student)
else
print("没有这个姓名的学生")
print("按enter继续")
io.read()
end
elseif choose == "3" then
break
else
print("没有这个选项!!!")
print("按enter继续")
io.read()
end
end
end


function query_stu(stu,data,num)  ---根据条件查询个别学生的成绩
if num == "1" then
for i=1,table.maxn(stu) do
--print(stu[i][1],data)
if stu[i][1] == data then return stu[i] end
end
elseif num == "2" then
for i=1,table.maxn(stu) do
if stu[i][2] == data then return stu[i] end
end
else
end
end


function modify_stu_scorce(stu)  --修改学生成绩1
while true do
os.execute("cls")
print("1.修改语文成绩")
print("2.修改数学成绩")
print("3.修改英语成绩")
print("4.返回上一层")
choose = io.read()
if choose == "1" then
modeify_stu_scorce2(stu)
elseif choose == "2" then
modeify_stu_scorce2(stu)
elseif choose == "3" then
modeify_stu_scorce2(stu)
elseif choose == "4" then break
else
print("没有这个选项")
print("按enter继续")
io.read()
end
end
end


function modeify_stu_scorce2(stu) --修改学生成绩2
require("stu")
os.execute("cls")
print("请输入修改后的分数")
scorce = io.read()
stu[5] = tonumber(scorce)


os.execute("cls")
print("修改后的:")
print_scorce(stu)
end


function modify_stu_interface2(stu,data,choose) --修改学生成绩菜单2
isright = 0
if choose == "1" then
for i=1,table.maxn(stu) do
--print(stu[i][1],data)
if stu[i][1] == data then 
modify_stu_scorce(stu[i]) 
isright = 1
break
end
end
elseif choose == "2" then
for i=1,table.maxn(stu) do
--print(stu[i][2],data)
if stu[i][2] == data then 
modify_stu_scorce(stu[i])
isright = 1
break
end
end
else
end
if isright == 0 then
print("没有这个学号或姓名的学生")
print("按enter继续")
io.read()
end
end


function modify_stu_interface(stu)   --修改学生成绩菜单1
while true do
os.execute("cls")
print("1.按学号查询")
print("2.按姓名查询")
print("3.返回上一层")
choose = io.read()
if choose == "1" then
os.execute("cls")
print("请输入要修改的学生的学号")
data = io.read()
student = modify_stu_interface2(stu,data,choose)
count_scorce_rank(stu)
elseif choose == "2" then
os.execute("cls")
print("请输入要修改的学生的姓名")
data = io.read()
student = modify_stu_interface2(stu,data,choose)
count_scorce_rank(stu)
elseif choose == "3" then break
else
print("没有这个选项!!!")
print("按enter继续")
io.read()
end
end
count_scorce_rank(stu)
end




function query_class_scorce(stu,tea)   -----查询本班的成绩
while true do
os.execute("cls")
print("1.按语文成绩排序")
print("2.按数学成绩排序")
print("3.按英语成绩排序")
print("4.按学号排序")
print("5.按排名排序")
print("6.返回上一层")
choose = io.read()
if choose == "6" then break end
print_class(stu,tea,choose)
end
end


function print_class(stu,tea,choose) ---打印一个班的成绩
stu_class = {}
count = 1
for i=1,table.maxn(stu) do
if tea[4] == stu[i][4] then
stu_class[count]={}
for j=1,9 do
stu_class[count][j] = stu[i][j]
end
count = count + 1
end
end

--for i=1,#stu_class do
--print(stu_class[i][1],stu_class[i][2],stu_class[i][4],stu_class[i][5],stu_class[i][6],stu_class[i][7],stu_class[i][8],stu_class[i][9])
--end
--io.read()
if count == 1 then
print("没有这个班级的学生")
else
if choose == "1" then
for i=1,#stu_class-1 do
for j=i+1,#stu_class do
if(stu_class[i][5]<stu_class[j][5]) then
stu_class[i],stu_class[j] = stu_class[j],stu_class[i]
end
end
end
print_class_person1(stu_class)
elseif choose == "2" then
for i=1,#stu_class-1 do
for j=i+1,#stu_class do
if(stu_class[i][6]<stu_class[j][6]) then 
stu_class[i],stu_class[j] = stu_class[j],stu_class[i]
end
end
end
print_class_person1(stu_class)
elseif choose == "3" then
for i=1,#stu_class-1 do
for j=i+1,#stu_class do
if(stu_class[i][7]<stu_class[j][7]) then
stu_class[i],stu_class[j] = stu_class[j],stu_class[i]
end
end
end
print_class_person1(stu_class)
elseif choose == "4" then
for i=1,#stu_class-1 do
for j=i+1,#stu_class do
if(stu_class[i][1]>stu_class[j][1]) then
stu_class[i],stu_class[j] = stu_class[j],stu_class[i]
end
end
end
print_class_person1(stu_class)
elseif choose == "5" then
for i=1,#stu_class-1 do
for j=i+1,#stu_class do
if(stu_class[i][9]>stu_class[j][9]) then
stu_class[i],stu_class[j] = stu_class[j],stu_class[i]
end
end
end
print_class_person1(stu_class)
else
print("没有这个选项!!!")
print("输入enter继续")
io.read()
end
end
end


function print_class_person1(stu)  
os.execute("cls")
print("学号","姓名 ","班级","语文","数学","英语","总分数","排名")
for i=1,#stu do
print_class_person2(stu[i])
end
print("按enter继续")
io.read()
end


function print_class_person2(stu)  ---打印一个班的成绩
print(stu[1],stu[2],stu[4],stu[5],stu[6],stu[7],stu[8],stu[9])
end


function print_tea(tea)     ---打印教师信息
os.execute("cls")
print("教工号","姓名","所教班级","电话")
print(tea[1],tea[2],tea[4],tea[5])
print("按enter继续")
io.read()
end


function count_scorce_rank(stu)
for i=1,table.maxn(stu) do
stu[i][8] = stu[i][5] + stu[i][6] + stu[i][7]
end
for i=1,table.maxn(stu)-1 do
for j=i+1,table.maxn(stu) do
if stu[i][8]<stu[j][8] then
stu[i],stu[j] = stu[j],stu[i]
end
end
end
for i=1,table.maxn(stu)-1 do
stu[i][9] = i
end
end


function tea_interface(tea,stu)   ----教师的欢迎界面
while true do
os.execute("cls")
print("欢迎"..tea[2].."教师登录学生管理系统")
print("1.查询学生成绩")
print("2.修改学生成绩")
print("3.查询全部成绩")
print("4.查询个人资料")
print("5.返回上一层")
choose = io.read()
if choose == "1" then
query_stu_interface(stu)
elseif choose == "2" then
modify_stu_interface(stu)
elseif choose == "3" then
query_class_scorce(stu,tea)
elseif choose == "4" then
print_tea(tea)
elseif choose == "5" then break
else
print("没有这个选项!!!")
print("按enter继续")
io.read()
end
end
end

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值