标签:sed ogr remove tee int menu pms ini math
do
local scores={"Chiese","Mathematics","English","Programming"}
Mainmenu={"1-Add","2-Remove","3-Query","4-Show ranking","5-Show Statistics","0-Exit"}
student={"SID","CID","name",scores}
for i=1,100,1 do
student[i].SID=2017081000+i
student[i].scores.Chiese=0
student[i].scores.Mathematics=0
student[i].scores.English=0
student[i].scores.Programming=0
end
local function Add()
print("Please enter the SID,CID,name and four scores.Enter 0 to finish.")
local sid=io.read("*number")
for j=1,100,1 do
if(sid==student[j].SID) then
local cid=io.read("*number")
if(cid>=0 and cid<=20) then
student[j].CID=cid
end
local name=io.read("*string")
if(string.len(name)>=1 and string.len(name)<=10) then
student[j].name=name
end
local Chiese=io.read("*number")
student[j].scores.Chiese=Chiese
local Mathematics=io.read("*number")
student[j].scores.Mathematics=Mathematics
local English=io.read("*number")
student[j].scores.English=English
local Programming=io.read("*number")
student[j].scores.Programming=Programming
else return
end
end
return ChooseMenu()
end
local function Remove()
print("Please enter SID or name.Enter 0 to finish.")
local nx=io.read()
if(tonumber(nx)) then
for i=1,100,1 do
if(student[i].SID==nx) then
table.remove(student[i])
end
end
else
for i=1,100,1 do
if(student[i].name==nx) then
table.remove(student[i])
end
end
return ChooseMenu()
end
local function Query()
print("Please enter SID or name.Enter 0 to finish.")
local nx=io.read()
if(tonumber(nx)) then
for i=1,100,1 do
if(student[i].SID==nx) then
print("SID:",student[i].SID)
print("CID:",student[i].CID)
print("name:",student[i].name)
print("Chiese score:",student[i].scores.Chiese)
print("Mathematics score:",student[i].scores.Mathematics)
print("English score:",student[i].scores.English)
print("Programming:",student[i].scores.Programming)
end
end
else
for i=1,100,1 do
if(student[i].name==nx) then
print("SID:",student[i].SID)
print("CID:",student[i].CID)
print("name:",student[i].name)
print("Chiese score:",student[i].scores.Chiese)
print("Mathematics score:",student[i].scores.Mathematics)
print("English score:",student[i].scores.English)
print("Programming:",student[i].scores.Programming)
end
end
return ChooseMenu()
end
local function Show_ranking()
print("Showing the ranklist hurts students‘ self-esteem.Don‘t do that.")
return ChooseMenu()
end
local function Show_Statistics()
print("Please enter calss ID,0 or the whostatistics.")
local cid=io.read("*number")
if(cid>=0 and cid<=20) then
local Statistics={}
for j=1,100,1 do
if(student[j].CID=cid) then
k=1
table.insert(Statistics[k],student[j])
k=k+1
end
end
local ChieseScore={}
local MathematicsScore={}
local EnglishScore={}
local ProgrammingScore={}
local total={}
for f=1,k do
total.Chiese=total+Statistic[f].scores.Chiese
total.Mathematics=total+Statistic[f].scores.Mathematics
total.English=total+Statistic[f].scores.English
total.Programming=total+Statistic[f].scores.Programming
end
ChieseScore.AverageScore=total.Chiese/k
MathematicsScore.AverageScore=total.Mathematics/k
EnglishScore.AverageScore=total.English/k
ProgrammingScore.AverageScore=total.Programming/k
NumberOfPassed={}
NumberOfFailed={}
for l=1,k do
if(Statistic[l].scores.Chiese>=60 and Statistic[l].scores.Chiese<=100) then
NumberOfPassed.Chiese=NumberOfPassed.Chiese+1
else
NumberOfFailed.Chiese=NumberOfFailed.Chiese+1
--end
if(Statistic[l].scores.Mathematics>=60 and Statistic[l].scores.Mathematics<=100) then
NumberOfPassed.Mathematics=NumberOfPassed.Mathematics+1
else
NumberOfFailed.Mathematics=NumberOfFailed.Mathematics+1
--end
if(Statistic[l].scores.English>=60 and Statistic[l].scores.English<=100) then
NumberOfPassed.English=NumberOfPassed.English+1
else
NumberOfFailed.English=NumberOfFailed.English+1
end
if(Statistic[l].scores.Programming>=60 and Statistic[l].scores.Chiese<=100) then
NumberOfPassed.Programming=NumberOfPassed.Programming+1
else
NumberOfFailed.Programming=NumberOfFailed.Programming+1
--end
end
print("Chiese\nAverage Score:")
print(ChieseScore.AverageScore)
print("\n Number of passed students:",NumberOfPassed.Chiese)
print("\n Number of failed students:",NumberOfFailed.Chiese)
print("\n\n\nMathematics\nAverage Score:")
print(MathematicsScore.AverageScore)
print("\n Number of passed students:",NumberOfPassed.Mathematics)
print("\n Number of failed students:",NumberOfFailed.Mathematics)
print("\n\n\nEnglish\nAverage Score:")
print(EnglishScore.AverageScore)
print("\n Number of passed students:",NumberOfPassed.English)
print("\n Number of failed students:",NumberOfFailed.English)
print("\n\n\nProgramming\nAverage Score:")
print(ProgrammingScore.AverageScore)
print("\n Number of passed students:",NumberOfPassed.Programming)
print("\n Number of failed students:",NumberOfFailed.Programming)
print("\n\n\nOverall:\n")
print("\n Number of students who passed all subjects:",NumberOfPassed.all)
print("\n Number of students who passed 3 or more subjects:",NumberOfPassed.three)
print("\n Number of students who passed 2 or more subjects:",NumberOfPassed.two)
print("\n Number of students who passed 1 or more subjects:",NumberOfPassed.one)
print("\n Number of students who failed all subjects:",NumberOfFailed.four)
end
return ChooseMenu()
end
local function Exit()
return
end
local ChooseMenu
local ChooseMenu=function()
print("Welcome to Student Performance Management System(SPMS).")
print("请输入按钮编号:")
local n=io.read("*number")
--print(n)
if n==1 then
return Add()
elseif n==2 then
return Remove()
elseif n==3 then
return Query()
elseif n==4 then
return Show_ranking()
elseif n==5 then
return Show_Statistics()
elseif n==0 then
return Exit()
elseif return ChooseMenu()
end
ChooseMenu()
end
标签:sed ogr remove tee int menu pms ini math
原文地址:http://www.cnblogs.com/xiyushimei/p/7944035.html