程序代码:
* VFP6代码
CLOSE DATABASES ALL
SET SAFETY OFF
SET COLLATE TO "MACHINE"
cStr="班级,总分,语文,数学,英语,物理,化学,生物,历史,地理,政治"
=ALINES(azd,CHRTRAN(cStr,",",CHR(10)+CHR(13)))
* 创建表结构
cField="班级 C(2),总分 N(7,2)"
FOR i=3 TO ALEN(azd,1)
cField=cField+","+azd[i]+" N(6,2)"
ENDFOR
CREATE CURSOR 平均分 (&cfield)
SELECT distinct 班级 FROM 学校 INTO ARRAY abj
LOCAL X[ALEN(abj,1),11],Y[ALEN(abj,1),11],Z[ALEN(abj,1),11]
STORE 0 TO X,Y,Z
* 班级各科全部平均分
SELECT 学校
INDEX on 班级 TAG px
FOR i=1 TO ALEN(abj,1)
X[i,1]=abj[i]
FOR ii=2 TO ALEN(azd,1)
rs=0
ncj=0
SCAN FOR 班级=abj[i]
ncj=ncj+&azd[ii]
rs=rs+1
ENDSCAN
X[i,ii]=ROUND(ncj/rs,2)
ENDFOR
ENDFOR
* 班级各科前20名(最后有相同的分数可能超过20人)平均分
FOR i=ALEN(abj,1) TO 1 STEP -1
Y[i,1]=abj[i]
FOR ii=2 TO ALEN(azd,1)
INDEX on 班级-STR(&azd[ii],7,1) TAG px DESCENDING
rs=0
ncj=0
nfs=0
SCAN FOR 班级=abj[i]
IF &azd[ii]!=nfs AND rs>=20
EXIT
ENDIF
ncj=ncj+&azd[ii]
rs=rs+1
nfs=&azd[ii]
ENDSCAN
Y[i,ii]=ROUND(ncj/rs,2)
ENDFOR
ENDFOR
* 最后平均分
FOR i=1 TO ALEN(abj,1)
Z[i,1]=abj[i]
FOR ii=2 TO ALEN(azd,1)
Z[i,ii]=X[i,ii]*0.6+Y[i,ii]*0.4
ENDFOR
ENDFOR
INSERT INTO 平均分 FROM ARRAY Z
SELECT 平均分
BROWSE
CLOSE DATABASES all
ERASE *.IDX