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

我的整个程序是在这里运行的,学生文档、教师文档都是被调用的,然后呢,这只是一个简单初学者的练手之作,管理员的功能我没有写,因为我觉得实现学生教师的练手就差不多了,然后这个学生成绩管理系统,学生只能查询自己的成绩,教师可以查询,修改学生的成绩,但是教师在查全部成绩时只能查询到自己班级的全班成绩,并且实现了各科成绩、排名等排序显示功能,最后这个系统我没有做一些检错机制,最好先建个stu.txt和stu.txt来保存数据,我不知道没有这两个文档,程序会不会出错或这两个文档里面没有数据会不会出错大笑


--manager.lua

function check(stu)--检查是否有此账户,能否登录成功
while true do
os.execute("cls")
io.write("请输入你的账号:")
local name = io.read()
print('\n')
io.write("请输入你的密码:")
local passwd = io.read()

local i= 1
while i<=table.maxn(stu) do
if stu[i][2] == name then
if stu[i][3] == passwd then 
return stu[i]
end
end
i = i+1
end
print("没有此账户或密码错误,请重新输入")
print("没有这个选项!!!")
print("按enter继续")
io.read()
end
end


function login_interface(stu_table,tea_table)


while true do
os.execute("cls")
print("欢迎进入学生管理系统\n")
print("1.学生登录")
print("2.教师登录")
print("3.管理员登录")
print("4.退出")
choose = io.read()
if choose == "1" then
stu_person = check(stu_table,count_stu)
if stu_person then
print(stu)
require "stu"
stu_interface(stu_person)
end
elseif choose == "2" then
tea_person = check(tea_table,count_tea)
if tea_person then
require "tea"
--print("登录成功")
tea_interface(tea_person,stu_table)
end
elseif choose == "3" then
while true do
os.execute("cls")
io.write("请输入你的账号:")
local name = io.read()
io.write("请输入你的密码:")
local passwd = io.read()
if (name == "admin") and (passwd == "admin") then 
manager_interface(stu_table,tea_table)
else
print("没有此账户或密码错误,请重新输入")
print("按enter继续")
io.read()
end
end
elseif choose == "4" then
print("是否保存修改y/任意按键")
respond = io.read()
if respond == "y" then
savestu(stu)
end
os.exit()
else
print("没有这个选项!!")
print("按enter继续")
io.read()
end
end

end


function savestu(stu)
local file = assert(io.open("stu.txt","w"),"error open")
for i=1,#stu do
s = table.concat(stu[i],'\t')
file:write(s,'\n')
end
file:close()
print("已保存修改")
end


function readstu_data()   --从文件中读取学生资料
stu = {}
local file = assert(io.open("stu.txt"),"error open")
countsi = 1
counts = countsi
for s in file:lines() do
counts = countsi
stu[countsi] = {}
local countsj = 1
start = 1
while true do
--print(s)
local i,j,value = string.find(s,"(%S+)",start)
--print(i,j,value)
if value == nil then break end
if countsj >= 5 then
stu[countsi][countsj] = tonumber(value)
else
stu[countsi][countsj] = value
end
countsj = countsj + 1
start = j+1
--print(start,countsj)
end
countsi = countsi + 1
end
io.close(file)

--for i=1,#stu do
--print(stu[i][1],stu[i][2],stu[i][4],stu[i][5],stu[i][6],stu[i][7],stu[i][8],stu[i][9])
--end
--io.read()
return stu
end 


function readtea_data()   --从文件中读取教师资料
tea = {}
file = io.open("tea.txt")
countsi = 1
counts = countsi
for s in file:lines() do
counts = countsi
tea[countsi] = {}
local countsj = 1
start = 1
while true do
local i,j,value = string.find(s,"(%S+)",start)
if value == nil then break end
--print(i,j,value)
tea[countsi][countsj] = value
countsj = countsj + 1
start = j+1
end
countsi = countsi + 1
end
io.close(file)
return tea
end


function manager_interface(stu,tea)
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
elseif choose == "2" then
elseif choose == "3" then
elseif choose == "4" then
elseif choose == "5" then
else
print("没有这个选项!!!")
print("按enter继续")
io.read()
end
end
end




stu = readstu_data()
tea = readtea_data()
login_interface(stu,tea)

猜你喜欢

转载自blog.csdn.net/lvyan1994/article/details/53097990
今日推荐