Benutzer-Werkzeuge

Webseiten-Werkzeuge


papierkorb:test1-2.blk

Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.

Link zu dieser Vergleichsansicht

papierkorb:test1-2.blk [2025-08-16 17:50] – ↷ Seite von projects:test1-2.blk nach papierkorb:test1-2.blk verschoben mkapapierkorb:test1-2.blk [Unbekanntes Datum] (aktuell) – gelöscht - Externe Bearbeitung (Unbekanntes Datum) 127.0.0.1
Zeile 1: Zeile 1:
-=== MID TERM EXAM 2 === 
-<code> 
-Screen 0 not modified      
- 0 \                                              13:36JWB02/16/86  
- 1 \ Last change:   Screen  011                   20:25JWB02/17/86  
-                                                                  
-                      MATHEMATICS  495                            
-                                                                  
-                                                                  
-         INTRODUCTION TO THE FORTH PROGRAMMING LANGUAGE           
-                                                                  
-                                                                  
-                       MID TERM EXAM                              
-10                                                                  
-11                     FEBRUARY 18, 1986                            
-12                                                                  
-13                     TOTAL  MARKS = 25                            
-14                                                                  
-15                                                                  
  
- 
-Screen 1 not modified      
- 0 \ QUESTION 1 ( 5 MARKS )                       13:45JWB02/16/86  
- 1 Show the resulting stack after return is pressed.                
-                                                                  
- 3 Example:   54  21  13   SWAP  DROP                               
-  Answer:   54  13        <top of stack.                          
-                                                                  
- 6 a)  13  17  23  31   ROT    ROT                                  
-                                                                  
- 8 b)  13  31  17  23   OVER   OVER                                 
-                                                                  
-10 c)  23  17  13     PICK    PICK  2  PICK                     
-11                                                                  
-12 d)  11  5  -14     /MOD                                        
-13                                                                  
-14 e)  25  50  10   */  5  +  10  /                                 
-15                                                                  
- 
- 
-Screen 2 not modified      
- 0 \ QUESTION 2 ( 5 MARKS )                       16:13JWB02/16/86  
- 1 Design the FORTH word EIGHT that will draw  the outline of the   
- 2 number eight on the display.  The outline must use the           
- 3 word  WHITE  ( or WW )  from the CHECKER-BOARD  program.         
-                                                                  
- 5 : WHITE   177  EMIT  ;                        XXXXXX             
-                                              X      X            
- 7 The word EIGHT takes no stack parameters.    X      X            
- 8 The output should look exactly like the      X      X            
- 9 figure at right except that it will not       XXXXXX             
-10 be made from X's.  To obtain full marks      X      X            
-11 you should demonstrate your knowledge of          X            
-12 factoring (ie  your definition of EIGHT      X      X            
-13 should not be one great big word!).           XXXXXX             
-14                                                                  
-15                                                                  
- 
- 
-Screen 3 not modified      
- 0 \ QUESTION 3 ( 5 MARKS )                       16:15JWB02/16/86  
- 1 A closed rectangular tank has a square base, b cm by b cm,       
- 2 and is h cm high.                                                
- 3 a) Write the word AREA that takes two stack inputs base, and     
-    height and leaves the surface area, a= 2bb +4bh, on the stack 
-    AREA  ( b h   a )                                             
- 6 b) Write the word VOLUME that takes two stack inputs base, and   
-    height and leaves the volume, v=bbh, on the stack.            
-    VOLUME ( b h  v )                                             
- 9 c) Write the word TANK that takes two stack inputs base, and     
-10    height and uses the words AREA and VOLUME above to produce    
-11    the following report when executed as shown below:            
-12    4 5 TANK                                                      
-13    The surface area is  112  square centimeters.                 
-14    THe volume is   80  cubic centimeters.                        
-15                                                                  
- 
- 
-Screen 4 not modified      
- 0 \ QUESTION 4 ( 5 MARKS )                       16:49JWB10/27/85  
- 1 a) Show how you would create a FORTH variable called  VALVE  .   
-    The variable VALVE will be used to contain the percentage     
-    that a valve is open ( 0 is closed, 100 full open).           
-                                                                  
- 5 b) Design the word  STATUS?  to display the current valve state. 
-    ie  STATUS?    displays:   Valve is now  XX percent open.     
-                                                                  
- 8 c) Write  INITIAL-SETTING   that sets  variable   VALVE          
-    to the top stack number.                                      
-10                                                                  
-11 d) Write the word OPEN which adds the top stack number to VALVE  
-12    and word CLOSE which subtracts top stack number from VALVE .  
-13 e) Can the value of VALVE ever become less than 0 using CLOSE ?  
-14    Can the value of VALVE ever exceed 100 using OPEN ?           
-15    Fix OPEN and CLOSE so that VALVE is always between 0 and 100. 
- 
- 
-Screen 5 not modified      
- 0 \ QUESTION 5 ( 5 MARKS )                       16:19JWB02/16/86  
- 1 a) Create an array called DATA that will hold 50 16bit numbers.  
-                                                                  
- 3 b) Write a word called CLEAR-DATA which initializes              
-    each cell of the array DATA to zero.                          
-                                                                  
- 6 c) Write a word called COUNT-DATA that counts the number of      
-    non zero entries in the array and saves it in the variable N. 
-                                                                  
- 9 d) Write a word called SUM-DATA that leaves the sum of all non   
-10    zero entries in the array DATA in the variable SSUM  .        
-11                                                                  
-12 e) Write a word called SUM-SQR that leaves the sum of squares    
-13    of all non zero entries in the array DATA in the variable     
-14     SSQR  .                                                      
-15                                                                  
- 
- 
-Screen 8 not modified      
- 0 \  32 bit square root KS  4TH DIM V4N1P9                         
-                                                                  
- 2 : EASY-BITS ( drem1 partial.root1 count   drem2  partial.root2 ) 
-      DO  >R  D2*  D2*                                          
-            R@  -  DUP  0<                                        
-            IF    R@ + R> 2*  1-                                  
-            ELSE       R> 2*  3  +                                
-            THEN  LOOP  ;                                         
-                                                                  
- 9 : 2'S-BIT ( drem2 proot2   drem3  proot3 ) \ get penultimate bit 
-10      >R  D2*  DUP  0<                                            
-11      IF   D2*  R@  -  R>  1+                                     
-12      ELSE D2*  R@  2DUP  U<                                      
-13           IF   DROP  R> 1-                                       
-14           ELSE  -    R> 1+                                       
-15      THEN THEN ;                                                 
- 
- 
-Screen 9 not modified      
- 0 \  32 bit square root KS  4TH DIM V4N1P9                         
- 1 : 1'S-BIT   ( drem3 proot3   fullroot )  \ remainder lost        
-      >R  DUP  0<                                                 
-      IF    2DROP  R>  1+                                         
-      ELSE  D2*  32768 R@  DU<  0=  R>  THEN ;                    
- 5 \ 32-bit unsigned radicand to 16-bit unsigned square root        
- 6 : SQRT     ( ud      )                                         
-          1 8 EASY-BITS  ROT  DROP  6 EASY-BITS                 
-         2'S-BIT  1'S-BIT  ;                                      
- 9 \ Display square root of 16-bit number with 3 decimal places.    
-10 : .SQRT  ( n   -- )  \ n  must be < 4096                         
-11         16 *  62500  UM*                                         
-12         SQRT  0 <#  # # #  ASCII . HOLD  #S #>                   
-13         TYPE  SPACE ;                                            
-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:25JWB02/17/86  
- 1 Show the resulting stack after return is pressed.                
-                                                                  
- 3 Example:   54  21  13   SWAP  DROP                               
-  Answer:   54  13        <top of stack.                          
-                                                                  
- 6 a)  13  17  23  31   ROT    ROT              13 31 17 23         
-                                                                  
- 8 b)  13  31  17  23   OVER   OVER             13 31 17 23 17 23   
-                                                                  
-10 c)  23  17  13     PICK 2 PICK 2 PICK      23 17 13 23 17 13   
-11                                                                  
-12 d)  11  5  -14     /MOD                    11  5  1 -3         
-13                                                                  
-14 e)  25  50  10   */  5  +  10  /             13                  
-15                                                                  
- 
- 
-Screen 12 not modified      
- 0 \ ANSWER TO QUESTION NUMBER 2  ( 5 MARKS )     20:25JWB02/17/86  
-                                                                  
- 2 : WHITE   177  EMIT  ;                                           
- 3 : .TOP  ( --  -- )                                               
-         SPACE 6 0 ?DO WHITE LOOP ;                               
- 5 : .ROW  ( --  -- )                                               
-         WHITE 6 0 ?DO SPACE LOOP WHITE ;                         
-                                                                  
- 8 : EIGHT ( --  -- )                                               
-         CR .TOP                                                  
-10         3 0 DO CR .ROW LOOP                                      
-11         CR .TOP                                                  
-12         3 0 DO CR .ROW LOOP                                      
-13         CR .TOP                                                  
-14         CR  ;                                                    
-15                                                                  
- 
- 
-Screen 13 not modified      
- 0 \ ANSWER TO QUESTION 3  ( 5 MARKS )            18:04JWB02/16/86  
-  : AREA ( b h   a )                                              
-      OVER DUP *  2 * ROT ROT  * 4 * +  ;                         
-                                                                  
-  : VOLUME ( b h   v )                                            
-      OVER * *  ;                                                 
-                                                                  
-  :  TANK ( b h  --  )                                            
-    CR OVER OVER                                                  
-    CR ." The surface area is " AREA .                            
-10       ." square centimeters."                                    
-11    CR ." The volume is " VOLUME .                                
-12       ." cubic centimeters."                                     
-13    CR  ;                                                         
-14          TANK                                                
-15                                                                  
- 
- 
-Screen 14 not modified      
- 0 \ ANSWER TO QUESTION 4 ( 5 MARKS)              20:22JWB02/17/86  
- 1 ( a) VARIABALE  VALVE                                            
-                                                                  
- 3 ( b) : STATUS? ( --  -- )                                        
-          CR ." Valve is now  " VALVE @ . ." percent open." ;     
-                                                                  
- 6 ( c) : INITIAL-SETTING  ( n  -- )                                
-          0 MAX 100 MIN  VALVE ! ;                                
-                                                                  
- 9 ( d) : OPEN  ( n  -- )          VALVE +! ;                       
-10      : CLOSE ( n  -- )  NEGATE  VALVE +! ;                       
-11                                                                  
-12 ( e) : OPEN  ( n  -- )  VALVE @    + 100 MIN VALVE ! ;           
-13      : CLOSE ( n  -- )  VALVE @ SWAP - 0 MAX VAVLE ! ;           
-14                                                                  
-15                                                                  
- 
- 
-Screen 15 not modified      
- 0 \ ANSWER TO QUESTION 5:  ( 5 MARKS )           18:36JWB02/16/86  
- 1 ( a) CREATE  DATA  100 ALLOT                                     
- 2 ( b)  : CLEAR-DATA ( --  -- )                                    
-           DATA  100 0  FILL ;                                    
- 4 ( a)  VARIABLE N   VARIABLE SSUM     VARIABLE SSQR               
-  : DATA@ ( i  -- )                                               
-      DATA SWAP 2* + @ ;                                          
- 7 ( c)                                                             
-  : COUNT-DATA ( --   -- ) 0 N !                                  
-    50 0 DO I DATA@ IF 1 N +! THEN LOOP  ;                        
-10 ( d)                                                             
-11  : SUM-DATA  ( --   -- ) 0 SSUM !                                
-12    50 0 DO I DATA@ ?DUP IF SSUM +!  THEN  LOOP ;                 
-13 ( e)                                                             
-14  : SUM-SQR  ( --  -- ) 0 SSQR !                                  
-15    50 0 DO I DATA@ ?DUP IF DUP * SSQR +!  THEN  LOOP ;  -->      
- 
- 
-Screen 16 not modified      
- 0 \  Used for testing solution.                  18:34JWB02/16/86  
-                                                                  
-      : #IN  QUERY  INTERPRET ;                                   
-      : ENTER-DATA ( --  -- )                                     
-        CLEAR-DATA  0  BEGIN                                      
-        CR DUP . ASCII > EMIT  #IN DUP 0<>                        
-        WHILE  OVER 2* DATA + ! 1+ REPEAT  2DROP ;                
-                                                                  
-                                                                  
-                                                                  
-10                                                                  
-11                                                                  
-12                                                                  
-13                                                                  
-14                                                                  
-15                                                                  
- 
-</code> 
papierkorb/test1-2.blk.1755359401.txt.gz · Zuletzt geändert: 2025-08-16 17:50 von mka