以下两个例程源程序均可在本站下载后直接运行,/*后字符为注释
****四则运算****
例程:
]10 CLS
]20 DIM OPERAND(6),OPERATOR(6),EPS(12)
]30 DIM PRIORITY(6,6),STACK1(6),STACK2(6)
]40 RANGE=10:AMOUNT=10IFFICULTY=1
]50 FOR I=0 TO 6
]60 FOR J=0 TO 6
]70 READ PRIORITY(I,J)
]80 NEXT J
]90 NEXT I
]200 CLS
]210 LOCATE 1,4RINT "小学四则运算"RINT "1,开始测试" /*主菜单*/
]220 PRINT "2,选择难度"
]230 PRINT "3,题目数量"
]240 PRINT "请选择(1-3):";
]250 LOCATE 5,13:CHOICE$=INDEX$ /*定位光标*/
]252 IF ASC(CHOICE$)=27 THEN GOTO 9999
]260 IF NOT (CHOICE$="b" OR CHOICE$="n" OR CHOICE$="m") THEN GOTO 200
]272 IF CHOICE$="b" GOTO 400
]273 IF CHOICE$="n" GOTO 500
]274 IF CHOICE$="m" GOTO 600
]400 IF DIFFICULTY<6 THEN IF DIFFICULTY=5 THEN GOTO 1000 ELSE GOTO 700
]500 CLS
]510 PRINT "1,加法 2,减法": PRINT "3,乘法 4,除法" /*二级菜单*/
]520 PRINT "5,四则混合 6,小于10": PRINT "7,小于100"
]540 PRINT "请选择(1-7):";
]550 LOCATE 5,13:CHOICE$=INDEX$
]562 IF CHOICE$="b" THEN DIFFICULTY=1: GOTO 200
]563 IF CHOICE$="n" THEN DIFFICULTY=2: GOTO 200
]564 IF CHOICE$="m" THEN DIFFICULTY=3: GOTO 200
]565 IF CHOICE$="g" THEN DIFFICULTY=4: GOTO 200
]566 IF CHOICE$="h" THEN DIFFICULTY=5: GOTO 200
]567 IF CHOICE$<>"j" AND CHOICE$<>"t" THEN GOTO 500
]570 IF CHOICE$="j" THEN RANGE=10 ELSE IF CHOICE$="t" THEN RANGE=100
]580 GOTO 200
]600 CLS
]610 PRINT RINT "请输入题目数量:";
]620 INPUT " ";A$
]630 AMOUNT=INT(VAL(A$)) /*将字符转化为数值*/
]640 IF AMOUNT <=0 THEN GOTO 600
]660 GOTO 200
]700 REM 简单运算
]701 RIGHT=0
]710 FOR TIMES=1 TO AMOUNT
]730 NUM1=INT(RANGE*RND(1)) /*使所取的随机数小于10,由RANGE值决定*/
]740 NUM2=INT(RANGE*RND(1))
]750 IF DIFFICULTY=4 AND NUM2<=1 THEN GOTO 740
]760 ON DIFFICULTY GOSUB 3500,3600,3700,3800
]770 IF ANSWER <0 THEN GOTO 730
]775 IF ANSWER <>INT(ANSWER) AND DIFFICULTY=4 THEN GOTO 730 /*答题错误转730重做此题*/
]780 CLS: PRINT NUM1;
]790 ON DIFFICULTY GOSUB 2510,2520,2530,2540
]800 PRINT NUM2;"=";
]810 INPUT REPLY$
]815 IF LEN(REPLY$)>0 AND VAL(REPLY$)=0 AND REPLY$<>"0" THEN GOTO 780
]820 IF ABS(VAL(REPLY$)-ANSWER)<.01 THEN PRINT "太棒了!^_^":RIGHT=RIGHT+1:GOTO 830
]825 PRINT "加油喔!"RINT "正确答案:";INT(ANSWER+0.5)
]830 IF TIMES<>AMOUNT THEN PRINT "按任意键继续...";:GOSUB 3900
]880 NEXT TIMES
]890 PRINT "总共答对:";RIGHT;" 答错:",AMOUNT-RIGHT
]900 PRINT "是否继续(Y/N)";
]910 CON$=INKEY$
]920 IF CON$<>"n" THEN GOTO 700
]930 GOTO 200
]1000 REM 四则混合运算
]1001 RIGHT =0
]1010 FOR TIMES=1 TO AMOUNT
]1019 REM 生成表达式
]1020 FOR I=0 TO 6
]1024 OPERAND(I)=0:OPERATOR(I)=0
]1050 EPS(I)=0:EPS(12-I)=0
]1060 NEXT I
]1069 REM NUM:操作数的个数(2-4)
]1070 NUM=INT(3*RND(1))+2
]1080 FOR I=0 TO NUM-1
]1090 OPERAND(I)=INT(RANGE*RND(1))
]1110 NEXT I
]1120 IF INT(4*RND(1))=1 AND NUM<>2 THEN GOTO 1170
]1130 FOR I=0 TO NUM-2
]1140 OPERATOR(I)=INT(4*RND(1))+1
]1150 NEXT I
]1160 GOTO 1300
]1169 REM 生成带括号的表达式
]1170 BRACKET=INT((NUM-1)*RND(1))
]1180 FOR I=0 TO NUM
]1190 OPERATOR(I)=INT(4*RND(1))+1
]1200 NEXT I
]1210 OPERATOR(BRACKET)=5
]1220 OPERATOR(BAACKET+2)=6
]1299 REM 为计算表达式的值做准备
]1300 J=0: I=0 :EXPROI=0
]1310 WHILE INT(I+0.5)<INT(NUM+0.5)
]1320 IF OPERATOR(J)=5 THEN J=J+1:EPS(EXPROI)=-5:EXPROI=EXPPOI+1
]1330 EPS(EXPPOI)=OPERAND(I):EXPROI=EXPPOI+1
]1340 ON OPERATOR(J) GOSUB 2000,2100,2200,2300
]1350 IF OPERATOR(J)=6 THEN J=J+1:EPS(EXPPOI)=-6:EXPPOI=EXPPOI+1:GOTO 1340
]1360 I=I+1:j=J+1
]1370 WEND
]1390 EPS(EXPPOI)=-7
]1499 REM 计算运算式的值
]1500 ST1=0: ST2=0: EXPPOI=0
]1510 STACK2(ST2)=-7:ST2=ST2+1
]1520 CH=EPS(EXPPOI):EXPPOI=EXPPOI+1
]1530 WHILE NOT (CH-7 AND STACK2(ST2-1)=-7)
]1540 IF CH>0 THEN GOSUB 1570 ELSE GOSUB 1580
]1550 WEND
]1560 GOTO 1600
]1570 STACK1(ST1)=CH:ST1=ST1+1:CH=EPS(EXPPOI):EXPPOI=EXPPOI+1
]1575 RETURN
]1580 ON PRIORITY(-STACK2(ST2-1)-1,-CH-1) GOSUB 3100,3200,3300 '注意ON语句的用法
]1585 RETURN
]1599 REM 判断用户答案是否正确
]1600 IF STACK1(ST1-1)<0 THEN GOTO 1020
]1610 ANSWER=STACK1(ST1-1)
]1615 CLS
]1620 FOR K=0 TO EXPPOI-1
]1630 IF EPS(K)>=0 THEN PRINT EPS(K);ELSE ON -EPS(K) GOSUB 2510,2520,2540,2550,2560
]1650 NEXT K
]1660 PRINT "=";
]1670 INPUT REPLY$
]1675 IF LEN(REPLY$)>0 AND VAL(REPLY$)>0 AND VAL(REPLY$=0 AND REPLY$<>"0" THEN GOTO 1615
]1680 IF ABS(VAL(REPLY$)-ANSWER)<.01 THEN GOSUB 1910 ELSE GOSUB 1930
]1690 IF TIMES <> AMOUNT THEN PRINT "按任意键继续...";:GOSUB 3900
]1700 NEXT TIMES
]1710 PRINT "总共答对:";RIGHT;" 答错:";AMOUNT-RIGHT
]1720 PRINT "是否继续(Y/N)";
]1730 CON$=INKEY$
]1740 IF CON$<>"n" THEN GOTO 1000
]1800 GOTO 200
]1910 PRINT "太棒了!^_^"RINT=RIGHT+1
]1920 RETURN
]1930 PRINT "加油喔!"RINT "正确答案:";:IF ANSWER<1 THEN PRINT "0";
]1940 PRINT INT (ANSWER*1000+0.5)/1000
]1950 RETURN
]2000 EPS(EXPROI)=-1:EXPPOI=EXPPOI+1
]2010 RETURN
]2100 EPS(EXPPOI)=-2:EXPPOI=EXPPOI+1
]2110 RETURN
]2200 EPS(EXPPOI)=-3:EXPPOI=EXPPOI+1
]2210 RETURN
]2300 EPS(EXPPOI)=-4:EXPPOI=EXPPOI+1
]2310 RETURN
]2510 PRINT "+";:RETURN
]2520 PRINT "-";:RETURN
]2530 PRINT "X";:RETURN
]2540 PRINT "/";:RETURN
]2550 PRINT "(";:RETURN
]2560 PRINT ")";:RETURN
]3100 STACK2(ST2)=CH:ST2=ST2+1
]3310 CH=EPS(EXPPOI):EXPPOI=EXPPOI+1
]3120 RETURN
]3200 ST2=ST2-1:STACK2(ST2)=0
]3210 CH=EPS(EXPPOI):EXPPOI=EXPPOI+1
]3220 RETURN
]3300 ST2=ST2-1:THETA=STACK(ST2):STACK2(ST2)=0
]3310 ST1=ST1-1:NUM2=STACK1(ST1):STACK1(ST1)=0
]3320 ST1=ST1-1:NUM1=STACK1(ST1):STACK1(ST1)=0
]3330 ON-THETA GOSUB 3500,3600,3700,3810
]3340 STACK1(ST1)=ANSWER:ST1=ST1+1
]3350 IF THETA=-4 AND ANSWER=9999 THEN GOTO 1020
]3360 RETURN
]3500 ANSWER=NUM1+NUM2: RETURN
]3600 ANSWER=NUM1-NUM2:RETURN
]3700 ANSWER=NUM1*NUM2:RETURN
]3800 ANSWER=NUM1/NUM2:RETURN
]3810 IF NUM2=0 THEN ANSWER=9999 ELSE ANSWER=NUM1/NUM2
]3820 RETURN
]3900 KEYVAL$=CHR$(255)
]3910 WHILE 1
]3920 IF KEYVAL$<>INKEY$ THEN GOTO 3940
]3930 WEND
]3940 RETURN
]4001 DATA 3,3,1,1,1,3,3
]4002 DATA 3,3,1,1,1,3,3
]4003 DATA 3,3,3,3,1,3,3
]4004 DATA 3,3,3,3,1,3,3
]4005 DATA 1,1,1,1,1,2,0
]4006 DATA 3,3,3,3,0,3,3
]4007 DATA 1,1,1,1,1,0,2
]9999 END ***翻牌成对**** ]10 GRAPH
]20 DIM POSXY$(18),CHARXY%(18,2),OPFLAG%(18),DELFLAG%(18),OPCUNT%(18)
]21 DIM NUM$(9),TEMP1$(18)
]30 FLAG%=1:TOTAL%=0;SUM%=0:STAY%=10:TIMER=0:CUOCOUNT%=0
]31 BLK1X%=2:BLK1Y%=1:BLK2X%=2:BLK2Y%=1
]33 GOSUB 1700
]40 CLS
]50 FOR I=1 TO 18
]60 OPFLAG%(I)=0ELFLAG%(I)=0:OPCOUNT%(I)=0
]70 NEXT I
]80 GOSUB 900: GOSUB 1000: GOSUB 1600: GOSUB 1500
]90 LET X%=1ET Y%=1:STARTFLAG%=0;TIMER=0
]100 IF TOTAL%=18 THEN GOSUB 1900:GOTO 200
]110 STAY%=1: GOSUB 1600
]111 LOCATE X%,Y%: PRINT " "
]112 IF PEEK(199)<128 THEN 173
]120 M1$=INKEY$
]125 LOCATE X%,Y%RINT "■";
]130 IF M1$=CHR$(23) THEN GOSUB 300
]140 IF M1$=CHR$(22) THEN GOSUB 400
]150 IF M1$=CHR$(20) THEN GOSUB 500
]160 IF M1$=CHR$(21) THEN GOSUB 600
]170 IF M1$=CHR$(13) THEN GOSUB 1100
]171 IF M1$=CHR$(27) THEN 190
]173 STAY%=1: GOSUB 1600
]174 LOCATE X%,Y%: PRINT " ";
]180 GOTO 100
]190 CLS: LOCATE 2,3: PRINT "退出";
]200 CLS
]201 END
]300 REM SUB OPEN -LEFT *****************<<<<<<<<<<<<<<<<
]310 STARTFLAG%=1
]320 GOSUB 700
]330 IF Y%=1 AND X%=1 THEN Y%=11:X%=3: GOTO 350
]340 IF Y%=1 THEN X%=X%-1:Y%=11 ELSE Y%=Y%-2
]350 XL1%=X%-1:YL1%=(Y%+1)/2:XYSRT1%=XL1%*6+YL1%
]360 IF OPFLAG%(XYSRT1%)=1 OR DELFLAG%(XYSRT1%)=1 THEN GOTO 330
]380 OLD$=M1$
]390 RETURN
]400 REM SUB OPEN -RIGHT ****************<<<<<<<<<<<<<<<<
]401 STARTFLAG%=1
]410 IF TOTAL%=18 THEN GOTO 490
]420 GOSUB 700
]430 IF Y%=11 AND X%=3 THEN Y%=1:X%=1:GOTO 450
]440 IF Y%=11 THEN X%=X%+1:Y%=1 ELSE Y%=Y%+2
]450 XL1%=X%-1:YL1%=(Y%+1)/2:XYSRT1%=XL1%*6+YL1%
]460 IF DELFLAG%(XYSRT1%)=1 OR OPFLAG%(XYSRT1%)=1 THEN GOTO 430
]480 OLD$=M1$
]490 RETURN
]500 REM SUB OPEN -UP^^^^^^^^^^^^^^^^^^^^^^
]501 STARTFLAG%=1
]510 GOSUB 700
]520 IF X%=1 THEN X%=3 ELSE X%=X%-1
]530 XL1%=X%-1:YL1%=(Y%+1)/2:XYSRT1%=XL1%*6+YL1%
]540 IF OPFLAG%(XYSRT1%)=1 OR DELFLAG%(XYSRT1%)=1 THEN GOTO 520
]580 OLD$=M1$
]590 RETURN
]600 REM SUB OPEN -DOWN ^^^^^^^^^^^^^^^^^^^^^^^^^^
]601 STARTFLAG%=1
]610 GOSUB 700
]620 IF X%=3 THEN X%=1 ELSE X%=X%+1
]630 XL1%=X%-1:YL1%=(Y%+1)/2:XYSRT1%=XL1%*6+YL1%
]640 IF OPFLAG%(XYSRT1%)=1 OR DELFLAG%(XYSRT1%)=1 THEN GOTO 620
]680 RERUTN
]700 REM SUB SOPEN -RESTORE ***************************
]710 XL1%=X%-1:YL1%=(Y%+1)/2:XYSRT1%=XL1%*6+YL1%
]720 IF DELFLAG%(XYSRT1%)=1 OR OPFLAG%(XYSRT1%)=1 THEN GOTO 740
]730 LOCATE X%,Y%RINT "■";
]740 RETURN
]800 REM read----Number
]820 N=0
]830 READ CH$
]840 WHILE ASC(CH$)<>48+TMP%
]850 READ CH$
]855 WEND
]856 FOR I=1 TO 9: READ NUM$(I):NEXT I
]860 DATA "0","苣","菡","菰","蓣","蓐","葳","蒇","蕨","蕤"
]861 DATA "1","睃","眭","睦","瞵","睥","瞍","睢","瞧","睫"
]826 DATA "2","呔","嘻","喳","嗒","啖","叨","嗡","
]863 DATA "3","蛳","蚊","蜩","螨","蟒","嚏","蜓","蜞","蛴"
]864 DATA "4","蹯","蹊","跄","跟","跖","硗","蹂","蹰","踔"
]865 DATA "5","疳","疟","癃","瘾","瘼","疠","瘛","疽","痈"
]866 DATA "6","宥","寡","褰","蹇","搴","謇","甯","窦","窳"
]867 DATA "7","崦","研","岘","嵴","峒","崛","嵝","峋","崾"
]868 DATA "8","堞","垅","埒","垤","塥","垭","埚","墒"
]869 DATA "9","漭","澌","渫","潆","滠","溽","滹","滤","淠"
]890 RETURN
]900 REM reNdomIze-XY-POS
]930 TMP%=INT(RND(1)*9)
]931 IF TMP%=0 THEN 930
]932 K=1
]935 LOCATE 1,18: PRINT TMP%
]938 GOSUB 800
]940 FOR I=1 TO 18
]941 IF K=10 THEN K=1
]942 TEMP1$(I)=NUM$(K)
]943 K=K+1
]950 NEXT I
]960 I=0:K=1
]970 FOR I=0 TO 17
]971 IF I=17 THEN POSXY$(K)=TEMP1$(1):GOTO 990
]980 N=INT(RND(1)=(18-I))
]981 IF N=0 THEN GOTO 980
]983 POSXY$(K)=TEMP1$(N):K=k+1: TEMP1$(N)=TEMP1$(18-I)
]984 NEXT I
]990 RETURN
]1000 REM PUTCHAR
]1010 I=1
]1020 FOR POSX=1 TO 3 STEP 1
]1030 FOR POSY=1 TO 11 STEP 2
]1040 LOCATE POSX,POSY: PRINT POSXY$(I);
]1050 CHARXY%(I,0)=POSX:CHARXY%(I,1)=POSY: I=I+1
]1060 NEXT POSY
]1070 NEXT POSX
]1090 RETURN
]1100 REM OPEN A CARD
]1110 IF STARTFLAG%=0 THEN X%=1: Y%=1
]1120 XL1%=X%-1:YL1%=(Y%+1)/2:XYSRT1%=XL1%*6+YL1%
]1130 OPFLAG%(XYSRT1%)=1
]1140 LOCATE X%,Y%: PRINT " ";
]1150 LOCAT CHARXY%(XYSRT1%,0),CHARXY%(XYSRT1%,1): PRINT POSXY$(XYSRT1%);
]1154 FLAG%=FLAG%+1:OPCOUNT%(XYSRT1%)=OPCOUNT%(XYSRT1%)+1
]1160 IF FLAG%/2-INT(FLAG%/2)<>0 THEN FLAG%=1 ELSE FLAG%=0
]1170 IF FLAG%=0 THEN CHAR1$=POSXY$(XYSRT1%): BLK1X%=X%: BLK1Y%=Y%: GOTO 1180
]1171 IF FLAG%=1 THEN CHAR2$=POSXY$(XYSRT1%): BLK2X%=X%: BLK2Y%=Y%: GOSUB 1200
]1180 GOSUB 400
]1190 RETURN
]1120 REM PEI DUI(Y/N)? rem FLAG%=1--->OPeN: FLAG%=0---->No OPEN
]1240 IF CHAR1$=CHAR2$ THEN GOSUB 1300
]1250 IF CHAR1$<>CHAR2$ THEN GOSUB 1400
]1290 RETURN
]1300 REM Pel Dul(Y)->Erase 2 block ''''''''''''''
]1310 LOCATE BLK1X%,BLK1Y%: PRINT " ";
]1320 LOCATE BLK2X%,BLK2Y%: print " ";
]1330 XL1%=BLK1X%-1:YL1%=(BLK1Y%+1)/2:XYSRT1%=XL1%*6+YL1%
]1340 XL1%=BLK2X%-1:YL1%=(BLK2Y%+1)/2:XYSRT2%=XL1%*6+YL1%
]1350 DELFLAG%(XYSRT1%)=1: DELFLAG%(XYSRT2%)=1
]1360 TOTAL%=TOTAL%+2
]1370 IF OPCOUNT%(XYSRT1%)=1 AND OPCOUNT%(XYSRT2%) THEN GOTO 1371
]1371 SUM%=SUM%+20: GOTO 1380
]1374 SUM%=SUM%+10
]1380 LOCATE 2,14: PRINT "得分";
]1382 LOCATE 2,18: PRINT " ";
]1383 LOCATE 2,18: PRINT SUM%;
]1384 LOCATE 3,14: PRINT "翻错"
]1385 LCOATE 3,18: PRINT " "
]1386 LOCATE 3,18: PRINT CUOCOUNT%;
]1390 RETURN
]1400 REM Pel DuI(N)->Close 2 blk#########################
]1410 XL1%=BLKX%-1:YL1%=(BLK1Y%+1)/2:XYSRT1%=XL1%*6+YL1%
]1420 XL1%=BLK2X%-1: YL1%=(BLK2Y%+1)/2:XYSRT2%=XL1%*6+YL1%
]1422 OPFLAG%(XYSRT1%)=0: OPFLAG%(XYSRT2%)=0:CUOCOUNT%=CUOCOUNT%+1
]1425 STAY%=1: GOSUB 1600
]1430 LOCATE CHARXY%(XYSRT2%,0),CHARXY%(XYSRT2%,1): PRINT POSXY$(XYSRT2%);
]1440 LOCATE BLK2X%,BLK2Y%: PRINT "■";
]1450 LOCATE BLK1X%,BLK1Y%: PRINT "■";
]1460 IF OPCOUNT%(XYSRT%)>3 OR OPCOUNT%(XYSRT2%)>3 THEN GOSUB 1800
]1470 LOCATE 2,14: PRINT "得分";
]1472 LOCATE 2,18: PRINT " ";
]1473 LOCATE 2,18: PRINT SUM%;
]1474 LOCATE 3,14: PRINT "翻错";
]1475 LOCATE 3,18: PRINT " ";
]1476 LOCATE 3,18: PRINT CUOCOUNT%;
]1490 RETURN
]1500 REM BLOCK
]1510 LOCATE 1,14: PRINT "难度";
]1515 LOCATE 1,19: PRINT NAN%;
]1520 FOR LINEX=1 TO 3 STEP 1
]1530 FOR LINEY=1 TO 11 STEP 2
]1540 LOCATE LINEX,LINEY: PRINT "■";
]1550 NEXT LINEY
]1560 NEXT LINEX
]1590 RETURN
]1600 REM sub
]1610 TM1=PEEK(1131)
]1620 TM2=PEEK(1131)
]1640 IF TM1=TM2 THEN GOTO 1630
]1650 STAY%=STAY%-1
]1660 IF TIMER=1 THEN LOCATE 1,18: PRINT " J";OCATE 1,18RINT STAY%;
]1670 TM1=TM2
]1680 WEND
]1682 LOCATE 1,18: PRINT " ";
]1690 RETURN
]1700 REM NAN% du
]1710 CLS
]1720 LOCATE 2,4: PRINT "难度";
]1730 locate 3,4: PRINT "请选择(1-9):";
]1735 TIMER=1
]1741 PLAY "CDEF"
]1742 PLAY "DD"
]1743 PLAY "L8 AG L2A P2 L8 GFED L2 C L1 D P1"
]1760 CMD$=INKEY$
]1761 IF CMD$="b" THEN NAN%=1: GOTO 1780
]1762 IF CMD4="n" THEN NAN%=2: GOTO 1780
]1763 IF CMD$="m" THEN NAN%=3: GOTO 1780
]1763 IF CMD$="g" THEN NAN%=4: GOTO 1780
]1765 IF CMD$="h" THEN NAN%=5: GOTO 1780
]1766 IF CMD$="j" THEN NAN%=6: GOTO 1780
]1767 IF CMD$="t" THEN NAN%=7: GOTO 1780
]1768 IF CMD$="y" THEN NAN%=8: GOTO 1780
]1769 IF CMD$="u" THEN NAN%=9: GOTO 1780
]1770 IF CMD$=CHR$(13) THEN NAN%-0: GOTO 1780 ELSE 1760
]1775 LOCATE 1,18: PRINT " "
]1780 LOCATE 1,18: PRINT NAN%
]1790 STAY%=30-NAN%*3
]1799 RETRUN
]1800 REM SUB SCORE
]1810 IF SUM%-5 <0 THEN SUM%-5 <0 THEN SUM%-5 <0 THEN SUM%-0 ELSE SUM%=SUM%-5
]1820 RETURN
]1900 REM End_sub
]1910 CLS: LOCATE 2,6: PRINT "真棒!";
]1920 LOCATE 4,2: PRINT "欢迎下次光临!"
]1930 STAY%=8: GOSUB 1600
]1950 RETURN
]1960 RETURN |