FLORIDA HIGH SCHOOLS COMPUTING COMPETITION '81 BASIC PROGRAM SOLUTIONS '1.1 ' This program will compute precent of heads and tails. ' INPUT "Enter number of heads: "; H INPUT "Enter number of tails: "; T S = H + T PRINT "PERCENT HEADS:"; H / S * 100 PRINT "PERCENT TAILS:"; T / S * 100 '1.2 ' This program will display the angle of a polygon. ' INPUT "Enter number of sides: "; N PRINT "ANGLE="; 180 * (N - 2) / N '1.3 ' This program will compute the value of a function. ' INPUT "A, B, C, X: "; A, B, C, X PRINT "AX^2 + BX + C ="; A * X * X + B * X + C '1.4 ' This program will compute the net price after discounts. ' INPUT "Enter original price: "; P FOR I = 1 TO 2 PRINT "Enter discount"; I; " percent:"; : INPUT D P = P - P * D / 100 NEXT I PRINT "FINAL NET PRICE: $"; INT(P * 100 + .5) / 100 '1.5 ' This program will determine the quadrant of a point. ' INPUT "Enter X, Y: "; X, Y IF X > 0 AND Y > 0 THEN PRINT "QUADRANT: I" IF X < 0 AND Y > 0 THEN PRINT "QUADRANT: II" IF X < 0 AND Y < 0 THEN PRINT "QUADRANT: III" IF X > 0 AND Y < 0 THEN PRINT "QUADRANT: IV" IF X = 0 THEN PRINT "LIES ON THE Y-AXIS" IF Y = 0 THEN PRINT "LIES ON THE X-AXIS" '2.1 ' This program will sum two fractions. ' INPUT "Enter a, b, c, d: "; A, B, C, D NUM = A * D + B * C: DEN = B * D FOR I = NUM TO 1 STEP -1 IF NUM MOD I = 0 AND DEN MOD I = 0 THEN PRINT NUM / I; "/"; DEN / I: END END IF NEXT I '2.2 ' This program will determine if quad is equilateral. ' FOR I = 1 TO 4 PRINT "Enter point"; I; ":"; : INPUT A(I), B(I) NEXT I A(5) = A(1): B(5) = B(1) FOR I = 1 TO 4 C(I) = SQR((A(I) - A(I + 1)) ^ 2 + (B(I) - B(I + 1)) ^ 2) NEXT I PRINT "QUAD IS "; FOR I = 1 TO 3 IF ABS(C(I) - C(I + 1)) > .1 THEN PRINT "NOT EQUILATERAL": END NEXT I PRINT "EQUILATERAL" '2.3 ' This program will print discount rate for phone call. ' INPUT "Enter day, time: "; D, T IF T >= 1700 AND T < 2300 THEN PRINT "20%": END IF T >= 2300 OR T < 700 THEN PRINT "40%": END IF D = 7 THEN PRINT "20%": END IF D = 1 THEN PRINT "40%": END PRINT "NO DISCOUNT" '2.4 ' This program will determine if graph is parallel. ' INPUT "Enter A, B, C: "; A, B, C INPUT "Enter D, E, F: "; D, E, F PRINT "LINES ARE "; IF A * E <> D * B THEN PRINT "NOT "; PRINT "PARALLEL" '2.5 ' This program will find the LCM of 3 integers. ' INPUT "Enter three integers: "; A, B, C FOR I = 1 TO B * C S = S + A IF S MOD B = 0 AND S MOD C = 0 THEN PRINT S: END NEXT I '3.1 ' This program will convert a number from base 10 to 8. ' INPUT "Enter numeral, base: "; N, B J = INT(LOG(N) / LOG(B)) FOR I = J TO 0 STEP -1 X = INT(N / B ^ I): PRINT USING "#"; X; N = N - X * B ^ I NEXT I PRINT '3.2 ' This program will print the mode in a list. ' INPUT "Enter how many numbers: "; N DIM A(N + 1), B(N + 1): A(N + 1) = -999 FOR I = 1 TO N: INPUT "Enter #: "; A(I): NEXT I FOR I = 1 TO N FOR J = I + 1 TO N IF A(I) = A(J) THEN B(I) = B(I) + 1 NEXT J IF B(I) > X THEN X = B(I) NEXT I PRINT "MODE(S):"; FOR I = 1 TO N IF B(I) = X THEN PRINT A(I); NEXT I PRINT : PRINT "NUMBER OF OCCURRENCES:"; X + 1 '3.3 ' This program will compute gross weekly pay. ' INPUT "Employee Number: "; E$ INPUT "Regular rate of pay/hour $"; R INPUT "Enter hours for M,T,W,R,F:"; H(1), H(2), H(3), H(4), H(5) FOR I = 1 TO 5 IF H(I) <= 8 THEN PAY = PAY + H(I) * R ELSE PAY = PAY + 8 * R + (H(I) - 8) * R * 2 END IF NEXT I PRINT "EMPLOYEE NUMBER: "; E$ PRINT USING "GROSS WEEKLY PAY: $###.##"; PAY '3.4 ' This program will play tic-tac-toe with a user. ' 'Board numbering system DATA 1,2,3, 8,9,4, 7,6,5 'Sets of 3 winning squares (in addition to above list) DATA 1,8,7, 2,9,6, 3,4,5, 1,9,5, 3,9,7 'Vertical and horizontal coordinates for squares R(1) = 1: C(1) = 1: R(2) = 1: C(2) = 5: R(3) = 1: C(3) = 9 R(4) = 3: C(4) = 9: R(5) = 5: C(5) = 9: R(6) = 5: C(6) = 5 R(7) = 5: C(7) = 1: R(8) = 3: C(8) = 1: R(9) = 3: C(9) = 5 ' RANDOMIZE TIMER PL$(0) = "YOU": PL$(1) = "COMPUTER" CLS : A$ = " | |": B$ = "---------": PRINT A$: PRINT B$: PRINT A$: PRINT B$: PRINT A$ FOR I = 1 TO 9 A(I) = 9: LOCATE R(I), C(I): PRINT MID$(STR$(I), 2, 1) NEXT I A(9) = 1: LOCATE R(9), C(9): PRINT "X" ' FOR MOV = 2 TO 9 IF MOV = 2 OR MOV = 4 OR MOV = 6 OR MOV = 8 THEN P = 0 ELSE P = 1 END IF IF P = 0 THEN ' Your move DO LOCATE 8, 3: INPUT "Enter #"; N LOCATE 8, 11: PRINT " " LOOP UNTIL A(N) > 1 A(N) = 0: LOCATE R(N), C(N): PRINT "O" GOSUB CheckWinner ELSE ' Computers move DO X = INT(RND(8) * 8 + 1) LOOP UNTIL A(X) > 1 A(X) = 1: LOCATE R(X), C(X): PRINT "X" GOSUB CheckWinner END IF NEXT MOV LOCATE 10, 3: PRINT "TIE GAME": END ' Determine if someone wins CheckWinner: FOR I = 1 TO 8 READ B, C, D IF A(B) = P AND A(C) = P AND A(D) = P THEN LOCATE 10, 3: PRINT PL$(P); " WON!": END END IF NEXT I: RESTORE: RETURN '3.5 ' This program will print a list of people who will retire. ' TM = 4: TY = 1981 'Today's month and year INPUT "Enter number of employees:"; N FOR I = 1 TO N PRINT INPUT "Social Security No.:"; S$(I) INPUT "Name:"; N$(I) INPUT "Birthdate (Month and day:"; BM$(I) INPUT "Birthdate (Year):"; BY(I) NEXT I ' Determine who retires when FOR Y = TY - 69 TO TY - 65 YR = Y - (TY - 70) FOR I = 1 TO N IF BY(I) <= Y THEN A(YR) = A(YR) + 1 A$(YR, A(YR)) = " #" + S$(I) + " " + N$(I) B(YR, A(YR)) = BY(I) END IF NEXT I NEXT Y ' Display retirers FOR Y = 1 TO 5 IF A(Y) > 0 THEN GOSUB SortDates PRINT : PRINT "RETIRE WITHIN"; Y; "YEARS" FOR I = 1 TO A(Y): PRINT A$(Y, I): NEXT I END IF NEXT Y: END ' Sort people by birthdates SortDates: FOR I = 1 TO A(Y) - 1 FOR J = I + 1 TO A(Y) IF B(Y, I) > B(Y, J) THEN X = B(Y, I): B(Y, I) = B(Y, J): B(Y, J) = X X$ = A$(Y, I): A$(Y, I) = A$(Y, J): A$(Y, J) = X$ END IF NEXT J NEXT I: RETURN