papierkorb:test1-3.blk
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
| papierkorb:test1-3.blk [2025-08-16 17:50] – ↷ Seite von projects:test1-3.blk nach papierkorb:test1-3.blk verschoben mka | papierkorb:test1-3.blk [Unbekanntes Datum] (aktuell) – gelöscht - Externe Bearbeitung (Unbekanntes Datum) 127.0.0.1 | ||
|---|---|---|---|
| Zeile 1: | Zeile 1: | ||
| - | === MID TERM EXAM 3 === | ||
| - | < | ||
| - | Screen 0 not modified | ||
| - | 0 \ 13: | ||
| - | 1 \ Last change: | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | 10 | ||
| - | 11 | ||
| - | 12 | ||
| - | 13 | ||
| - | 14 | ||
| - | 15 | ||
| - | |||
| - | Screen 1 not modified | ||
| - | 0 \ QUESTION 1 ( 5 MARKS ) | ||
| - | 1 The following words are not part of the Forth 83 standard. | ||
| - | 2 Write short colon definitions for them using only words from | ||
| - | 3 your forth 83 reference sheet. | ||
| - | | ||
| - | 5 Example: | ||
| - | 6 Solution: | ||
| - | | ||
| - | | ||
| - | | ||
| - | 10 a) TUCK ( a b c a c b c ) | ||
| - | 11 b) -ROT ( a b c c a b ) | ||
| - | 12 c) 2OVER1 ( a b c a b c a b ) | ||
| - | 13 d) SPIN ( a b c c b a ) | ||
| - | 14 e) NIP ( a b c a c ) | ||
| - | 15 | ||
| - | |||
| - | |||
| - | Screen 2 not modified | ||
| - | 0 \ QUESTION 2 ( 5 MARKS ) | ||
| - | 1 Design the FORTH word TRIANGLE that will draw the outline for | ||
| - | 2 a triangle on the display using X' | ||
| - | 3 the top stack number to decide how many lines will be used to | ||
| - | 4 make the isosceles triangle. See the sample output below left. | ||
| - | | ||
| - | 6 3 TRIANGLE | ||
| - | | ||
| - | | ||
| - | 9 XXXXX | | ||
| - | 10 5 TRIANGLE | ||
| - | 11 | ||
| - | 12 XXX | ||
| - | 13 | ||
| - | 14 XXXXXXX | ||
| - | 15 XXXXXXXXX | ||
| - | |||
| - | |||
| - | Screen 3 not modified | ||
| - | 0 \ QUESTION 3 ( 5 MARKS ) | ||
| - | 1 A open rectangular tank has a square ends, b meters by b meters, | ||
| - | 2 and is l meters long. | ||
| - | 3 a) Write the word AREA that takes two stack inputs base, and | ||
| - | | ||
| - | | ||
| - | 6 b) Write the word VOLUME that takes two stack inputs base, and | ||
| - | | ||
| - | | ||
| - | 9 c) Write the word TANK that takes two stack inputs base, and | ||
| - | 10 length and uses the words AREA and VOLUME above to produce | ||
| - | 11 a report. For example, 2 3 TANK should give the report below. | ||
| - | 12 Square end of the tank is | ||
| - | 13 Length of the tank is | ||
| - | 14 The surface area of the tank is | ||
| - | 15 THe volume of the tank is | ||
| - | |||
| - | |||
| - | Screen 4 not modified | ||
| - | 0 \ QUESTION 4 ( 5 MARKS ) | ||
| - | 1 a) Show how you would create a variable called | ||
| - | | ||
| - | | ||
| - | 4 b) Design the word VALVE-STATUS to display the current value of | ||
| - | | ||
| - | | ||
| - | 7 c) Write %VALVE-OPEN | ||
| - | | ||
| - | | ||
| - | 10 d) Write %VALVE-INC which increments VALVE-SETTING by top stack | ||
| - | 11 number and %VALVE-DEC which decrements it by the top stack #. | ||
| - | 12 e) Can the VALVE-SETTING ever become less than 0 or greater | ||
| - | 13 than 100 using your words of (d). If so fix them so they | ||
| - | 14 do nothing and issue a warning message if an attempt to | ||
| - | 15 increment or decrement out of range is made. | ||
| - | |||
| - | |||
| - | Screen 5 not modified | ||
| - | 0 \ QUESTION 5 ( 5 MARKS ) | ||
| - | 1 a) Create an array called MARKS that will hold 5 16bit numbers. | ||
| - | 2 b) Write a word called CLEAR-MARKS which initializes | ||
| - | | ||
| - | 4 c) Write a word called SHOW-MARKS that displays and identifies | ||
| - | | ||
| - | | ||
| - | | ||
| - | 8 d) Write a word called TOTAL that computes the sum of all non | ||
| - | | ||
| - | 10 the variable SUM . Save the non zero count in variable N . | ||
| - | 11 e) Write a word called MARK-AVG that computes the average of | ||
| - | 12 all non zero entries in the array MARKS and stores the | ||
| - | 13 result in the variable AVERAGE and displays the result as: | ||
| - | 14 Your current marks average is nnn | ||
| - | 15 MARK-AVG should round correctly to the nearest integer. | ||
| - | |||
| - | Screen 8 not modified | ||
| - | 0 \ 32 bit square root KS 4TH DIM V4N1P9 | ||
| - | | ||
| - | 2 : EASY-BITS ( drem1 partial.root1 count | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | 9 : 2' | ||
| - | 10 >R D2* DUP 0< | ||
| - | 11 IF | ||
| - | 12 ELSE D2* R@ 2DUP U< | ||
| - | 13 | ||
| - | 14 | ||
| - | 15 THEN THEN ; | ||
| - | |||
| - | |||
| - | Screen 9 not modified | ||
| - | 0 \ 32 bit square root KS 4TH DIM V4N1P9 | ||
| - | 1 : 1' | ||
| - | | ||
| - | | ||
| - | | ||
| - | 5 \ 32-bit unsigned radicand to 16-bit unsigned square root | ||
| - | 6 : SQRT ( ud | ||
| - | | ||
| - | | ||
| - | 9 \ Display square root of 16-bit number with 3 decimal places. | ||
| - | 10 : .SQRT ( n -- ) \ n must be < 4096 | ||
| - | 11 16 * 62500 UM* | ||
| - | 12 | ||
| - | 13 | ||
| - | 14 : TEST 100 0 DO CR I 5 .R SPACE I .SQRT LOOP ; | ||
| - | 15 | ||
| - | |||
| - | |||
| - | Screen 11 not modified | ||
| - | 0 \ ANSWER TO QUESTION 5 ( 5 MARKS ) 20: | ||
| - | 1 a) TUCK ( a b c a c b c ) | ||
| - | | ||
| - | | ||
| - | 4 b) -ROT ( a b c c a b ) | ||
| - | | ||
| - | | ||
| - | 7 c) 2OVER1 ( a b c a b c a b ) | ||
| - | | ||
| - | | ||
| - | 10 d) SPIN ( a b c c b a ) | ||
| - | 11 SWAP ROT ; | ||
| - | 12 | ||
| - | 13 e) NIP ( a b c a c ) | ||
| - | 14 SWAP DROP ; | ||
| - | 15 | ||
| - | |||
| - | |||
| - | Screen 12 not modified | ||
| - | 0 \ ANSWER TO QUESTION NUMBER 2 ( 5 MARKS ) | ||
| - | 1 : X' | ||
| - | | ||
| - | | ||
| - | 4 : .ROW ( n r -- ) | ||
| - | | ||
| - | | ||
| - | 7 : (TRIANGLE) ( n -- ) | ||
| - | | ||
| - | | ||
| - | 10 : TRIANGLE | ||
| - | 11 DUP 1 < IF DROP ." Zero or negative not allowed" | ||
| - | 12 ELSE DUP 23 < | ||
| - | 13 IF (TRIANGLE) | ||
| - | 14 ELSE DROP ." Larger than 23 not allowed" | ||
| - | 15 THEN THEN ; | ||
| - | |||
| - | |||
| - | Screen 13 not modified | ||
| - | 0 \ ANSWER TO QUESTION 3 ( 5 MARKS ) 18: | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | 10 CR ." The surface area of the tank is " AREA . | ||
| - | 11 | ||
| - | 12 CR ." The volume of the tank is " VOLUME . | ||
| - | 13 | ||
| - | 14 CR ; | ||
| - | 15 | ||
| - | |||
| - | |||
| - | Screen 14 not modified | ||
| - | 0 \ ANSWER TO QUESTION 4 ( 5 MARKS) | ||
| - | 1 ( a) VARIABLE | ||
| - | 2 ( b) : VALVE-STATUS ( -- -- ) CR ." Valve is now " | ||
| - | | ||
| - | 4 ( c) : [IN] ( x a b | ||
| - | | ||
| - | | ||
| - | | ||
| - | 8 ( d) : %VALVE-INC | ||
| - | | ||
| - | 10 ( e) : %VALVE-INC | ||
| - | 11 | ||
| - | 12 IF VALVE-SETTING ! ELSE DROP WARN THEN ; | ||
| - | 13 : %VALVE-DEC | ||
| - | 14 | ||
| - | 15 IF VALVE-SETTING ! ELSE DROP WARN THEN ; | ||
| - | |||
| - | |||
| - | Screen 15 not modified | ||
| - | 0 \ ANSWER TO QUESTION 5: ( 5 MARKS ) | ||
| - | 1 ( a) CREATE MARKS 70 , 0 , 80 , 0 , 65 , \ average=72 | ||
| - | 2 ( b) : CLEAR-MARKS ( -- -- ) | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | 7 ( c) | ||
| - | | ||
| - | | ||
| - | 10 ( d) | ||
| - | 11 : TOTAL ( -- -- ) 0 SUM ! 0 N ! | ||
| - | 12 5 0 DO I MARKS@ ?DUP IF SUM +! 1 N +! THEN LOOP ; | ||
| - | 13 ( e) : MARKS-AVG | ||
| - | 14 TOTAL SUM @ 2 * N @ / 1+ 2 / AVERAGE ! | ||
| - | 15 CR ." Your current marks average is " AVERAGE @ . ; | ||
| - | |||
| - | |||
| - | Screen 16 not modified | ||
| - | 0 \ Used for testing solution. | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | 10 | ||
| - | 11 | ||
| - | 12 | ||
| - | 13 | ||
| - | 14 | ||
| - | 15 | ||
| - | |||
| - | </ | ||
papierkorb/test1-3.blk.1755359401.txt.gz · Zuletzt geändert: 2025-08-16 17:50 von mka