Chapter 9 – Further Programs (Star Tester)

The Messier List, check out the fake comets
Telescope, the facts about telescopes, binoculars, cameras and astronomy
Star Tester, a quiz
Ellipses, various ellipses
Spectrum World Map, a map of the world in CHR$ CODE.

Star Tester

This is a short demonstration program to show how a simple quiz, using questions and answers, can be set up. Obviously, the quiz does not have to relate to astronomy, but it does for the purposes of this book. The program as it stands contains only ten star names, grouped in pairs in a$ and this is far too few to be really effective. In the example, ‘Antares’ = ‘Alpha Scorpii’, ‘Regulus’ = ‘Alpha Leonis’ — these are the alternative names for each star.’ Thus the program is ripe for expansion by the user perhaps with entirely different paired names.

The program
The program works in the following way. A DIMensional array is set up in line 30 to accept (in this case) 10 names with a maximum length of 13 characters to cope with the longest a$ – a$(2), a$(6) and a$(10) all have a total of 13 letters and spaces. A DIM b$(13), a single DIMensioned array, is also set up to receive the answers to be INPUT in Line 230.

The computer asks the user up to ten questions via the FOR/NEXT f loop in Line 160. The variable z in Line 170 selects a RANDOM number between 1 and 10 and PRINTs to the screen the a$ with this number. The computer also decides that the answer will be:

a$(z + t)

where variable t acts as a switch eg

if z = 1 then t = 1 if z = 2 then t = – 1

and so on for each odd or even number that is thrown up for z so that t has a value of 1 or – 1 as the case may be. If a$(l) to a$(10) in Lines 40 to 130 inclusive are checked, then it can be seen that the computer has identified each answer correctly by grouping the a$ in pairs.

Line 230 INPUTs and PRINTs the answer, and the ‘?’ is overprinted by using the expression PRINT CHR$ 8; b$. Lines 310 and 320 mark the answers and tot up the correct results with the variables score which is PRINTed at the end of the f loop.

The program uses the automatic scroll conditions by POKEing (POKE 23692, 255) and PRINTing below screen line number 21, so that the questions and answers flow up from the bottom of the screen next to the INPUT line 22. This is effected by program Line 350. Figure 9.5 is a typical COPY of the screen display.

Figure 9.5
Star_Tester

Although the computer is looking for an answer which is precisely correct in upper and lower case lettering, there are insufficient permutations in a range of numbers from 1 to 10 without frequent repetition. Ideally the minimum should be about 30 questions, ie 15 paired questions/answers — preferably more to avoid repetition. Amending the program to receive extra questions involves minimal changes and can be done in two ways.

1) Additional listing in the a$
This is fairly straightforward and simply means squeezing more a$s into the listing, starting at a$(ll) — assuming the first 10 questions/answers in the listing are to be retained. For neatness, Lines 40 to 130 should be renumbered (perhaps as Lines 40 to 50 inclusive) and the extra new items for the a$ started from Line 51:

51 LETa$(11) = “…star name 6a…”
52 LETa$(12) = “…star name 6b…”
53 LETa$(13) = “…star name 7a…”
54 LETa$(14) = “…star name 7b…”
55 LETa$(15) = “…

and so on with all the extra data. Finally, amend the DIMensional array in Line 30 to account for the extra questions included:

30 DIM a$ (total number in a$, 13): DIM b$(13)

and amend the last value in the Line 170:

170 LET z = 1 + INT (RND*total number of questions in a$)

The program can now be RUN (RUN because all the program is contained in the LISTing).

2) INPUT subroutine
There is no particular need for the questions and answers to appear in the program and they can be INPUT via a subroutine. The procedure is as follows:

Delete Lines 20 to 130 inclusive

Amend Line 280 (final command) to GOTO 1 (in lieu of RUN)
Add the subroutine 400 DIM a$(50,13): DIM b$(13)

This allows for 50 questions/answers — 25 pairs — a maximum of 13 characters long, including spaces.)

410 FOR n = 1 TO 50
420 PRINT n; ” “; LET c$ = “”
430 INPUT c$ : PRINT c$
440 IFc$ = “stop” THEN STOP
450 LET a$(n) = c$
460 NEXT n: STOP

The subroutine is started with GOTO 400 and the paired questions/answers are INPUT sequentially. It is not necessary to use up all the DIMension a$ array if you run out of questions as long as the last INPUT was an even numbered item. Simply INPUT “stop” and Line 440 will STOP the program. The program should now be SAVEd with GOTO 9990 as a precaution and VERIFYed. Now amend Line 170 to read:

170 LET z = 1 +INT(RND*(n-l))

The variable n is the last value + 1 used in the INPUT loop in Line 440. The program should be SAVEd and VERIFYed as version no 3 by amending Line 9990 to read:

9990 SAVE “startest3” LINE 1

and then, as a direct command, GOTO 9990. The amendment will ensure that the program starts automatically when LOADed with LOAD “”or LOAD “startest3” (which is preferred) and so avoid the pressing of the RUN key which will erase all the DATA from the computer. All would not be lost of course — simple reLOAD but this time enter GOTO 1.

Now that the program is safely on tape, it is time to test the program started with GOTO 1.

Adding more questions
If less than the full quota of 50 questions/answers was initially INPUT, then more can be added by BREAKing the program and entering as a direct command:

CLS: GOTO 420

which will pick up the INPUT routine where it left off and start the n loop again. Again the INPUT can be terminated before all 50 items have been entered with:

INPUT “stop”

and as a direct command to restart the quiz with GOTO 1. The current value of n will again update the maximum RANDOM number for the variable z. It is a wise precaution to SAVE each version where more DATA is INPUT before the quiz is tested. Better safe than sorry.

10 REM Star Tester
30 DIM a$(10,13): DIM b$(13)
40 LET a$(1)=”Antares”
50 LET a$(2)=”Alpha Scorpii”
60 LET a$(3)=”Regulus”
70 LET a$(4)=”Alpha Leonis”
80 LET a$(5)=”Betelgeuse”
90 LET a$(6)=”Alpha Orionis”
100 LET a$(7)=”Vega”
110 LET a$(8)=”Alpha Lyrae”
120 LET a$(9)=”Rigel”
130 LET a$(10)=”Beta Orionis”
140 LET score=0
160 FOR f=1 TO 10: LET t=1
170 LET z=1+INT (RND*10)
180 LET q=z/2
190 IF INT q=q THEN LET t=-1
200 GO SUB 340
210 PRINT f;”)”;a$(z);” is? “;
220 LET x$=a$(z+t)
230 INPUT b$: PRINT CHR$ 8;CHR$ 8;” “;b$
240 GO SUB 300: LET x=z
250 GO SUB 340: PRINT : NEXT f
270 GO SUB 340: PRINT “Your score: “;score;” correct answers”
280 PRINT FLASH 1;” Try again? – press any key “: PAUSE 0: RUN
300 GO SUB 340
310 PRINT PAPER 5; FLASH 1 AND b$x$;x$;
320 IF b$=x$ THEN LET score=score+1: PRINT PAPER 6; FLASH 1;” is correct”: GO TO 340
330 PRINT PAPER 5;” is the answer!”
350 POKE 23692,255: PRINT AT 20,0: PRINT : RETURN

Advertisements