' Console Table Generator — headers, rows, column alignment, formatting
#COMPILE EXE
#DIM ALL

SUB PrintSeparator()
    LOCAL i AS LONG
    PRINT "+-------+--------+--------+----------+----------+"
END SUB

SUB NumericTable()
    LOCAL i AS LONG
    LOCAL d1 AS STRING
    LOCAL d2 AS STRING
    LOCAL d3 AS STRING
    LOCAL d4 AS STRING

    PRINT "Numeric Table:"
    PRINT "+-------+--------+--------+----------+----------+"
    PRINT "| Num   | Square | Cube   | Sqrt     | Recip    |"
    PRINT "+-------+--------+--------+----------+----------+"
    FOR i = 1 TO 8
        d1 = STR$(i)
        d2 = STR$(i * i)
        d3 = STR$(i * i * i)
        d4 = STR$(SQR(i))
        PRINT "| " & d1 & " | " & d2 & " | " & d3 & " | " & d4 & " |"
    NEXT i
    PRINT "+-------+--------+--------+----------+----------+"
    PRINT
END SUB

SUB EmployeeTable()
    PRINT "Employee Table:"
    PRINT "+--------------+-------------+---------+-------+"
    PRINT "| Name         | Department  | Salary  | Years |"
    PRINT "+--------------+-------------+---------+-------+"
    PRINT "| Alice Smith  | Engineering | 85000   | 5     |"
    PRINT "+--------------+-------------+---------+-------+"
    PRINT
END SUB

SUB MonthDaysTable()
    LOCAL i AS LONG
    LOCAL m AS STRING
    LOCAL d AS STRING
    PRINT "Month Days Table:"
    PRINT "+------------+------+"
    PRINT "| Month      | Days |"
    PRINT "+------------+------+"
    FOR i = 1 TO 12
        IF i = 1 THEN m = "January"
        IF i = 2 THEN m = "February"
        IF i = 3 THEN m = "March"
        IF i = 4 THEN m = "April"
        IF i = 5 THEN m = "May"
        IF i = 6 THEN m = "June"
        IF i = 7 THEN m = "July"
        IF i = 8 THEN m = "August"
        IF i = 9 THEN m = "September"
        IF i = 10 THEN m = "October"
        IF i = 11 THEN m = "November"
        IF i = 12 THEN m = "December"
        IF i = 1 THEN d = "31"
        IF i = 2 THEN d = "28/29"
        IF i = 3 THEN d = "31"
        IF i = 4 THEN d = "30"
        IF i = 5 THEN d = "31"
        IF i = 6 THEN d = "30"
        IF i = 7 THEN d = "31"
        IF i = 8 THEN d = "31"
        IF i = 9 THEN d = "30"
        IF i = 10 THEN d = "31"
        IF i = 11 THEN d = "30"
        IF i = 12 THEN d = "31"
        PRINT "| " & LEFT$(m & "          ", 10) & " |  " & d & "   |"
    NEXT i
    PRINT "+------------+------+"
    PRINT
END SUB

SUB FibonacciTable()
    LOCAL i AS LONG
    LOCAL a AS LONG
    LOCAL b AS LONG
    LOCAL c AS LONG
    LOCAL ratio AS STRING
    PRINT "Fibonacci Ratio Table:"
    PRINT "+-------+--------------+---------------+"
    PRINT "|   n   |   Fib(n)     |    Ratio      |"
    PRINT "+-------+--------------+---------------+"
    a = 0
    b = 1
    FOR i = 1 TO 15
        IF i > 2 AND b <> 0 THEN
            ratio = STR$(a / b)
        ELSE
            ratio = "     N/A     "
        END IF
        PRINT "| " & STR$(i) & "    | " & STR$(a) & "    | " & ratio & " |"
        c = a + b
        a = b
        b = c
    NEXT i
    PRINT "+-------+--------------+---------------+"
    PRINT
END SUB

SUB MultiplicationTable()
    LOCAL i AS LONG
    LOCAL j AS LONG
    PRINT "Multiplication Table (5x5):"
    PRINT "     1   2   3   4   5"
    PRINT "   +-------------------+"
    FOR i = 1 TO 5
        PRINT STR$(i) & "  | " & STR$(i * 1) & "    " & STR$(i * 2) & "    " & STR$(i * 3) & "    " & STR$(i * 4) & "    " & STR$(i * 5)
    NEXT i
    PRINT
END SUB

SUB PowersTable()
    LOCAL i AS LONG
    LOCAL j AS LONG
    LOCAL pow AS LONG
    LOCAL fact AS LONG
    PRINT "Powers of 2 Table:"
    PRINT "+------+---------+------------+"
    PRINT "|  n   |  2^n    |   n!       |"
    PRINT "+------+---------+------------+"
    pow = 1
    FOR i = 0 TO 10
        IF i > 0 THEN pow = pow * 2
        fact = 1
        FOR j = 2 TO i
            fact = fact * j
        NEXT j
        PRINT "| " & STR$(i) & "   | " & STR$(pow) & " | " & STR$(fact) & " |"
    NEXT i
    PRINT "+------+---------+------------+"
    PRINT
END SUB

FUNCTION PBMAIN() AS LONG
    PRINT "=========================="
    PRINT " Console Table Generator "
    PRINT "=========================="
    PRINT
    CALL NumericTable()
    CALL EmployeeTable()
    CALL MonthDaysTable()
    CALL FibonacciTable()
    CALL MultiplicationTable()
    CALL PowersTable()
    PRINT "All tables generated."
    FUNCTION = 0
END FUNCTION
