|
如题:按照每个学生全部科目成绩总分从高分到低分排列学生姓名及总分
我的程序如下,用的是数组,可是最后不知道怎么输出二维数组,弄的排序没法整,还请各位大大看看,或者有更好的方法也行,还有看我的StringSplit($strAllStudentName, ",",3)输出的数组得到的结果为什么会多一个行号.先谢谢,步骤实在多,还请大大们只看最下面的程序.;学生成绩统计
;==================================
#include <array.au3>
;====================>变量定义
;===============================================================================
Dim $strCalculateTotalScoreEachStudent;======================>每个学生总成绩
Dim $strCalculateAverageScoreEachStudent;=====================>每个学生平均成绩
Dim $strCalculateTotalScoreEachSubject;=========================>每个科目总成绩
Dim $strCalculateAverageScoreEachSubject;==========================>每个科目平均成绩
Dim $strCalculateFailChinese;===========================>筛选 语文 单科成绩<60分的学生,列出学生名单和成绩
Dim $strCalculateHeJiongFailEachSubject;===================>筛选何炅成绩<60分的科目 ,列出所有科目和成绩
Dim $strCalculateMathPhyChemOneHundredEightyThreeSubject;==========>列出数学、物理、化学总分>180分的学生,列出三科成绩
Dim $strCalculateFailSingleSubject;===================>筛选出3个以上单科<60分 列出科目和分数
Dim $strDescTotalScoreEachStudent;=========================>按照 学生总成绩 降序排列 列出学生 总分
Dim $strDescTotalScoreEachSubject;============================>按照 科目总成绩 降序排列 列出科目 总分
Dim $strCalculateMaleScienceTotalScore;==========================>统计全部男生理科总成绩
Dim $strCalculateMaleArtTotalScore;=================================>统计全部男生文科总成绩
Dim $strCalculateFemaleScienceTotalScore;=============================>统计全部女生理科总成绩
Dim $strCalculateFemaleArtTotalScore;====================================>统计全部女生文科总成绩
Dim $strCalculateMaleRatioFemaleScienceTotalScore;=========================>计算 男生理科总成绩/女生理科总成绩 精确小数点后1位
Dim $strCalculateMaleRatioFemaleArtTotalScore;================================>计算 男生文科总成绩/女生文科总成绩 精确小数点后1位
Dim $ExcelWorkBook;=============>打开excel表格
Dim $strStuscoreArray;===============>获取excel表格数据
Dim $intStuscoreRows, $intStuscoreCols;==============>获取学生成绩表行数与列数(行数=每科目成绩,行数0=姓名数据,行数1=性别数据,列数=学生列表,列数0=字段)
Dim $c, $r, $i, $k;==================>循环变量
Dim $strScoreOutput, $strScoreOutputArray;======================>全局输出变量与数组
Dim $strMathematics, $strPhysics, $strChemistry, $strBiology, $strChinese, $strHistory, $strPolitics, $strGeography, $strEnglish;==========>课程变量
Dim $strMathPhyChemTotalScore;=========>数理化总分
Dim $strFailTimes, $strFailSingleSubjectArray;========>不及格次数;保存不及格单个科目的数组
Dim $strAllStudentName, $strStudentNameArray, $strSaveTotalScoreEachStudent, $strCalculateTotalScoreEachStudentArray;保存学生全部名字与数组;保存每个学生总成绩及数组
$strFailTimes = 0
;==================================>读取excel本地文件数据:学生成绩表
$ExcelWorkBook = ObjGet(@ScriptDir & "\学生成绩表.xls")
With $ExcelWorkBook.worksheets("Sheet1")
$strStuscoreArray = .range("a1" ).currentregion.value
.parent.close(False)
EndWith
$intStuscoreRows = UBound($strStuscoreArray, 1);================>获取学生成绩表行数与列数
$intStuscoreCols = UBound($strStuscoreArray, 2)
#cs
;================>计算每个学生 总成绩和平均成绩
$strScoreOutput = ""
For $c = 1 To $intStuscoreCols - 1
For $r = 2 To $intStuscoreRows - 1
$strCalculateTotalScoreEachStudent = $strCalculateTotalScoreEachStudent + $strStuscoreArray[$r][$c];============>获得每个学生总成绩
$strCalculateAverageScoreEachStudent = Round($strCalculateTotalScoreEachStudent / ($intStuscoreRows - 2), 1);=============>获得每个学生平均成绩
Next
$strScoreOutput = $strScoreOutput & $strStuscoreArray[0][$c] & @TAB & $strCalculateTotalScoreEachStudent & @TAB & $strCalculateAverageScoreEachStudent & @LF
$strCalculateTotalScoreEachStudent = 0
$strCalculateAverageScoreEachStudent = 0
Next
MsgBox(0, "每个学生总分和平均分", "姓名" & @TAB & "总分" & @TAB & "平均分" & @LF & $strScoreOutput)
;================>计算科目 总成绩和平均成绩
$strScoreOutput = ""
For $r = 2 To $intStuscoreRows - 1
For $c = 1 To $intStuscoreCols - 1
$strCalculateTotalScoreEachSubject = $strCalculateTotalScoreEachSubject + $strStuscoreArray[$r][$c];============>获得科目总成绩
$strCalculateAverageScoreEachSubject = Round($strCalculateTotalScoreEachSubject / ($intStuscoreCols - 1), 1);=============>获得科目平均成绩
Next
$strScoreOutput = $strScoreOutput & $strStuscoreArray[$r][0] & @TAB & $strCalculateTotalScoreEachSubject & @TAB & $strCalculateAverageScoreEachSubject & @LF
$strCalculateTotalScoreEachSubject = 0
$strCalculateAverageScoreEachStudent = 0
Next
MsgBox(0, "每个科目总分和平均分", "科目" & @TAB & "总分" & @TAB & "平均分" & @LF & $strScoreOutput)
;================>筛选 语文 单科成绩<60分的学生,列出学生名单和成绩
$strScoreOutput = ""
For $r = 2 To $intStuscoreRows - 1
If $strStuscoreArray[$r][0] == "语文" Then
For $c = 1 To $intStuscoreCols - 1
If $strStuscoreArray[$r][$c] < 60 Then
$strCalculateFailChinese = $strStuscoreArray[$r][$c];======================>语文不及格的分数
$strScoreOutput = $strScoreOutput & $strStuscoreArray[0][$c] & @TAB & $strCalculateFailChinese & @LF;=============>输出语文不及格的学生和分数
EndIf
Next
ExitLoop
EndIf
Next
MsgBox(0, "语文不及格的学生", "姓名" & @TAB & "分数" & @LF & $strScoreOutput)
;================>筛选 何炅 单科成绩<60分的科目,列出科目和分数
$strScoreOutput = ""
For $c = 1 To $intStuscoreCols - 1
If $strStuscoreArray[0][$c] == "何炅" Then
For $r = 2 To $intStuscoreRows - 1
If $strStuscoreArray[$r][$c] < 60 Then
$strCalculateHeJiongFailEachSubject = $strStuscoreArray[$r][$c];======================>何炅科目不及格的分数
$strScoreOutput = $strScoreOutput & $strStuscoreArray[$r][0] & @TAB & $strCalculateHeJiongFailEachSubject & @LF;=============>输出何炅不及格的科目和分数
EndIf
Next
ExitLoop
EndIf
Next
MsgBox(0, "何炅不及格的科目", "科目" & @TAB & "分数" & @LF & $strScoreOutput)
;================>列出数学、物理、化学总分>180分的学生,列出三科成绩
$strScoreOutput = ""
For $c = 1 To $intStuscoreCols - 1
For $r = 2 To $intStuscoreRows - 1
If $strStuscoreArray[$r][0] == "数学" Then
$strMathematics = $strStuscoreArray[$r][$c]
EndIf
If $strStuscoreArray[$r][0] == "物理" Then
$strPhysics = $strStuscoreArray[$r][$c]
EndIf
If $strStuscoreArray[$r][0] == "化学" Then
$strChemistry = $strStuscoreArray[$r][$c]
EndIf
Next
$strMathPhyChemTotalScore = $strMathematics + $strPhysics + $strChemistry;================>数理化总分
If $strMathPhyChemTotalScore > 180 Then;============================>判断数理化总分是否超过180分
$strScoreOutput = $strScoreOutput & $strStuscoreArray[0][$c] & @TAB & $strMathematics & @TAB & $strPhysics & @TAB & $strChemistry & @LF;========>输出数理化成绩
EndIf
$strMathematics = 0
$strPhysics = 0
$strChemistry = 0
Next
MsgBox(0, "数理化总分超过180分的学生", "姓名" & @TAB & "数学" & @TAB & "物理" & @TAB & "化学" & @LF & $strScoreOutput)
;================>筛选出3个以上单科<60分 列出科目和分数
$strScoreOutput = ""
For $c = 1 To $intStuscoreCols - 1
For $r = 2 To $intStuscoreRows - 1
If $strStuscoreArray[$r][$c] < 60 Then
$strCalculateFailSingleSubject = $strCalculateFailSingleSubject & $strStuscoreArray[$r][0] & @TAB & $strStuscoreArray[$r][$c] & @LF;==========>所有不及格科目和成绩
$strFailTimes = $strFailTimes + 1;============>记录不及格次数
EndIf
Next
If $strFailTimes >= 3 Then
$strScoreOutput = $strScoreOutput & "姓名" & @TAB & $strStuscoreArray[0][$c] & @LF & $strCalculateFailSingleSubject & @LF;============>输出每个人不及格的科目和成绩
EndIf
$strCalculateFailSingleSubject = ""
$strFailTimes = 0
Next
MsgBox(0, "三科以上不及格的学生", $strScoreOutput)
#ce
;================>按照 学生总成绩 降序排列 列出姓名 总分
$strScoreOutput = ""
For $c = 1 To $intStuscoreCols - 1
For $r = 2 To $intStuscoreRows - 1
$strCalculateTotalScoreEachStudent = $strCalculateTotalScoreEachStudent + $strStuscoreArray[$r][$c];============>获得每个学生总成绩
Next
$strSaveTotalScoreEachStudent = $strSaveTotalScoreEachStudent & $strCalculateTotalScoreEachStudent & ",";==============>用字符串保存每个学生的总成绩
$strAllStudentName = $strAllStudentName & $strStuscoreArray[0][$c] & ",";================>用字符串保存每个学生的名字
$strCalculateTotalScoreEachStudent = 0
Next
$strCalculateTotalScoreEachStudentArray = StringSplit($strSaveTotalScoreEachStudent, ",",3);==============>将学生总成绩保存进数组
$strStudentNameArray = StringSplit($strAllStudentName, ",",3);================>将学生名字保存进数组
For $i = 0 To 1
For $k = 0 To UBound($strStudentNameArray) - 1
$strScoreOutputArray[$i][$k] = $strAllStudentName[$k]
Next
Next
_ArrayDisplay($strScoreOutputArray)
;MsgBox(0, "降序学生总分", "姓名" & @TAB & "总分" & @LF & $strScoreOutput)
|
|