home *** CD-ROM | disk | FTP | other *** search
-
- Program CALENDAR;
-
- Label Again,Amonth;
-
- Const
- Months: Array[1..12] of string[9]=('January','February','March','April',
- 'May','June','July','August','September','October','November','December');
- WeekDay: Array[0..6] of string[3]=('Sun','Mon','Tue','Wed','Thu',
- 'Fri','Sat');
- JulianDay: Array[1..12] of integer=(0,31,59,90,120,151,181,212,243,273,
- 304,334);
- DaysInMonth: Array[1..12] of Integer=(31,28,31,30,31,30,31,31,30,31,30,31);
- XPOS: Array[0..6] of integer = (15,23,31,39,47,55,63);
-
- Type
- AnyString = String[70];
-
- Var
- SYear: String[4];
- Display: String[20];
- Month,
- Day,
- Yr,Y,C,
- Cn,D,L,
- Row,
- Year,
- Jday,
- Leap: Integer;
- Ch: Char;
-
- Procedure Stars(N: Integer);
- Var L: Integer;
- Begin
- for L := 1 to N do
- Write('*');
- End;
-
- Procedure Spaces(N: Integer);
- Var L: Integer;
- Begin
- for L := 1 to N do
- Write(' ');
- End;
-
- Procedure WrDay(X: Integer; S: AnyString);
- Begin
- GotoXY(XPOS[X],Row); Write(s);
- End;
-
- Procedure WrM(X: Integer; S: AnyString);
- Begin
- GotoXY(X,4); Write(s);
- End;
-
- Procedure WrD(X,DayCount: Integer);
- Begin
- If X = 0 then Row := Row + 2;
- GotoXY(XPOS[X],Row); Write(DayCount:2);
- End;
-
- Procedure FirstDay(M,Yr: Integer);
- Begin
- Y := Yr - 1801; C := Trunc((Yr-1)/100); Cn := Trunc(Yr/100);
- D := (5+Y+Trunc(Y/4)-(C-18)+Trunc((C-16)/4)) Mod 7;
- If Yr Mod 4 = 0 then Leap := 1 else Leap := 0;
- Jday := JulianDay[M] + 1; If M > 2 then Jday := Jday + Leap;
- D := D + (Jday Mod 7); {* Answer in D (1=Sat...7=Fri) *}
- End;
-
- {************************ Main Program ***************************}
- Begin
- Again:
- HighVideo;
- GotoXY(1,22);
- ClrEol;
- Write('Calendar Year: ');
- Readln(Year);
- If (Year >= 0) And (Year < 100) then Year := Year + 1900; Str(Year,Syear);
- GotoXY(1,23);
- ClrEol;
- If (Year < 1801) or (Year > 2199) then
- Begin
- WriteLn('Calendar Years Must Be Between 1801 and 2199!');
- Goto Again;
- End;
- Amonth:
- GotoXY(1,23);
- ClrEol;
- Write('Calendar Month: ');
- Readln(Month);
- GotoXY(1,24);
- ClrEol;
- If (Month < 0) or (Month > 12) then
- Begin
- WriteLn('Calendar Months Must Be 1..12!');
- Goto Amonth;
- End;
- Clrscr;
- GotoXY(28,2);
- WriteLn('Perpetual Calendar -- DSOFT');
- Spaces(5);
- Stars(70);
- Writeln; {* Display Calendar Header *}
- Spaces(5);
- Stars(9);
- Spaces(18);
- Write(copy(Syear,1,1));
- Spaces(4);
- Write(copy(Syear,2,1));
- Spaces(4);
- Write(copy(Syear,3,1));
- Spaces(4);
- Write(copy(Syear,4,1));
- Spaces(18);
- Stars(9);
- Writeln;
- Row := 6;
- Spaces(5);
- Stars(70);
- Writeln;
- Spaces(5);
- Stars(2);
- Spaces(66);
- Stars(2);
- WriteLn;
- For L := 1 to 13 do
- Begin
- GotoXY(6,6+L);
- Stars(2);
- GotoXY(74,6+L);
- Stars(2);
- End;
- GotoXY(6,20);
- Stars(70);
- WriteLn;
- FirstDay(Month,Year); {* D is now equal to the first day of the month *}
- For L := 0 to 6 do
- WrDay(L,WeekDay[L]);
- WriteLn;
- Spaces(5);
- Stars(70);
- WriteLn;
- Row := 9;
- L := Length(Months[Month]);
- WrM(17,Months[Month]);
- WrM(65-L,Months[Month]);
- L := DaysInMonth[Month];
- If Month = 2
- then
- L := L + Leap;
- For C := 1 to L do
- Begin
- CN := (D + C - 3) Mod 7; If CN < 0 then CN := CN + 7;
- WrD(CN,C);
- End;
- GotoXY(1,22); ClrEol;
- Write('Another Calendar (Y/N)');
- Repeat Read(Kbd,Ch) until UpCase(Ch) in ['Y','N'];
- If UpCase(Ch) = 'Y'
- Then
- goto Again
- else
- GotoXY(1,22);
- End.