How to resolve the algorithm Calendar step by step in the BASIC programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Calendar step by step in the BASIC programming language

Table of Contents

Problem Statement

Create a routine that will generate a text calendar for any year.
Test the calendar by generating a calendar for the year 1969, on a device of the time. Choose one of the following devices:

(Ideally, the program will generate well-formatted calendars for any page width from 20 characters up.) Kudos (κῦδος) for routines that also transition from Julian to Gregorian calendar. This task is inspired by Real Programmers Don't Use PASCAL by Ed Post, Datamation, volume 29 number 7, July 1983. For further Kudos see task CALENDAR, where all code is to be in UPPERCASE. For economy of size, do not actually include Snoopy generation in either the code or the output, instead just output a place-holder.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Calendar step by step in the BASIC programming language

Source code in the basic programming language

DECLARE month$[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }
DECLARE month[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
year$ = "1969"
' Leap year
INCR month[1], IIF(MOD(VAL(year$), 4) = 0 OR MOD(VAL(year$), 100) = 0 AND MOD(VAL(year$), 400) <> 0, 1, 0)
PRINT ALIGN$("[SNOOPY HERE]", 132, 2)
PRINT ALIGN$(year$, 132, 2)
FOR nr = 0 TO 11
    row = 3
    GOTOXY 1+(nr %6)*22, row+(nr/6)*9
    PRINT ALIGN$(month$[nr], 21, 2);
    INCR row
    GOTOXY 1+(nr %6)*22, row+(nr/6)*9
    PRINT ALIGN$("Mo Tu We Th Fr Sa Su", 21, 2);
    INCR row
    ' Each day
    FOR day = 1 TO month[nr]
        ' Zeller
        J = VAL(LEFT$(year$, 2))
        K = VAL(MID$(year$, 3, 2))
        m = nr+1
        IF nr < 2 THEN
            INCR m, 12
            DECR K
        END IF
        h = (day + ((m+1)*26)/10 + K + (K/4) + (J/4) + 5*J)
        daynr = MOD(h, 7) - 2
        IF daynr < 0 THEN INCR daynr, 7
        IF daynr = 0 AND day > 1 THEN INCR row
        GOTOXY 1+(nr %6)*22+daynr*3, row+(nr/6)*9
        PRINT day;
    NEXT
NEXT

  

You may also check:How to resolve the algorithm Middle three digits step by step in the Dart programming language
You may also check:How to resolve the algorithm 100 doors step by step in the Bracmat programming language
You may also check:How to resolve the algorithm Take notes on the command line step by step in the PL/I programming language
You may also check:How to resolve the algorithm Babbage problem step by step in the Liberty BASIC programming language
You may also check:How to resolve the algorithm Assertions step by step in the AutoHotkey programming language