Area Program Example

The following DataBasic program finds the area of various geometric figures.

* Display figure menu
*
    EQUATE ERASE TO CHAR(12)
    T=25; C=45
    PRINT ERASE
    PRINT @(-4):@(T-3,4):'THIS PROGRAM FINDS THE'
    PRINT @(T-3):'AREAS OF GEOMETRIC FIGURES.':
    PRINT @(T+3,7):'TYPE':@(C-2):'CODE'
    PRINT @(T):'-------------- ----'
    PRINT @(T):'RECTANGLE':@(C):'1'
    PRINT @(T):'CIRCLE':@(C):'2'
    PRINT @(T):'TRIANGLE':@(C):'3'
    PRINT @(T):'PARALLELOGRAM':@(C):'4'
    PRINT @(T):'RHOMBUS':@(C):'5'
    PRINT @(T):'TRAPEZOID':@(C):'6'
* Prompt for selection
    P=@(1,17):'ENTER '
    Q=@(1,18):'ENTER '
    R=@(1,19):'ENTER '
    AREA=@(1,20):'AREA = '
    PRINT @(1,16):'ENTER A FIGURE TYPE CODE':
10  PRINT @(26,16):' ':@(25,16):; INPUT CODE
    BEGIN CASE
*
*   Rectangle
       CASE CODE = 1
          PRINT P:'LENGTH':; INPUT LENGTH
          PRINT Q:'WIDTH ':; INPUT WIDTH
          PRINT AREA:LENGTH*WIDTH:
*
*   Circle
       CASE CODE = 2
          PRINT P:'RADIUS':; INPUT RADIUS
          PRINT AREA:; PRINT RADIUS*RADIUS*3.1416
*
*   Triangle
       CASE CODE = 3
          PRINT P:'BASE':; INPUT BASE
          PRINT Q:'ALTITUDE':; INPUT ALTITUDE
          PRINT AREA:BASE*ALTITUDE/2
*
*   Parallelogram
       CASE CODE = 4
          PRINT P:'BASE':; INPUT BASE
          PRINT Q:'HEIGHT':; INPUT HEIGHT
          PRINT AREA:BASE*HEIGHT
*   Rhombus
       CASE CODE = 5
          PRINT P:'LENGTH OF FIRST DIAGONAL':
          INPUT DIAG1
          PRINT Q:'LENGTH OF SECOND DIAGONAL':
          INPUT DIAG2
          PRINT AREA:DIAG1*DIAG2/2
*
*   Trapezoid
       CASE CODE = 6
          PRINT P:'LENGTH OF FIRST BASE':
          INPUT BASE1
          PRINT Q:'LENGTH OF SECOND BASE':
          INPUT BASE2
          PRINT R:'HEIGHT':; INPUT HEIGHT
          PRINT AREA:HEIGHT* (BASE1+BASE2)/2
*
       CASE CODE <1 OR CODE >6
          PRINT @(1,18):'ILLEGAL FIGURE CODE'
    END CASE
20  PRINT @(1,22):'ENTER CR TO CONTINUE OR X TO QUIT':
    INPUT X
    IF X MATCHES '' THEN
       FOR I=20 TO 17 STEP -1
          PRINT @(0,I):EOL:
       NEXT I
       GOTO 10
       END
    END