Kheb ook is men best gedaan, dees progje zou het verschil van datums in dagen moeten berekenen, het houdt wel geen rekening met schrikkeljaren

Wel met 28dagen in februarie etc. Tis enkel nog maar vraag 1a. De rest morgen misschien of nooit
Datum.Mod
Code: Select all
MODULE Datum;
IMPORT
OutExt, In;
TYPE
DatumPtr = POINTER TO Datum;
Datum =
RECORD
dag: INTEGER;
maand: INTEGER;
jaar: INTEGER;
END;
PROCEDURE Verschil (oudste: DatumPtr; jongste: DatumPtr):INTEGER;
VAR
verschil: INTEGER;
i: INTEGER;
fout: INTEGER;
daycount: INTEGER;
BEGIN
fout := -1;
verschil := 0;
verschil := ((jongste^.jaar) - oudste^.jaar) * 365;
IF (jongste^.maand = oudste^.maand) THEN
verschil := verschil;
ELSIF (jongste^.maand < oudste^.maand) THEN
i := oudste^.maand;
WHILE i # jongste^.maand DO
DEC(i);
IF (i < 1) THEN
i := 12;
ELSE
END;
CASE i OF
1, 3, 5, 7, 8, 10, 12: verschil := verschil - 31;
| 4, 6, 9, 11: verschil := verschil - 30;
| 2: verschil := verschil - 28;
ELSE
RETURN fout;
END;
END;
ELSIF (jongste^.maand > oudste^.maand) THEN
i := jongste^.maand;
WHILE i # oudste^.maand DO
DEC(i);
IF (i < 1) THEN
i := 12;
ELSE
END;
CASE i OF
1, 3, 5, 7, 8, 10, 12: verschil := verschil + 31;
| 4, 6, 9, 11: verschil := verschil + 30;
| 2: verschil := verschil + 28;
ELSE
RETURN fout;
END;
END;
ELSE;
RETURN fout;
END;
IF (jongste^.dag = oudste^.dag) THEN
verschil := verschil;
ELSIF (jongste^.dag < oudste^.dag) THEN
i := oudste^.dag;
daycount := 0;
WHILE i # jongste^.dag DO
DEC(i);
INC(daycount);
END;
verschil := verschil - daycount;
ELSIF (jongste^.dag > oudste^.dag) THEN
i := oudste^.dag;
daycount := 0;
WHILE i # jongste^.dag DO
INC(i);
INC(daycount);
END;
verschil := verschil + daycount;
ELSE
RETURN fout;
END;
RETURN verschil;
END Verschil;
PROCEDURE Doe*;
VAR
eerste, tweede, jongste, oudste: DatumPtr;
counter: SHORTINT;
BEGIN
NEW(eerste);
NEW(tweede);
NEW(jongste);
NEW(oudste);
counter := 0;
In.Open;
In.Int(eerste^.dag);
In.Int(eerste^.maand);
In.Int(eerste^.jaar);
In.Int(tweede^.dag);
In.Int(tweede^.maand);
In.Int(tweede^.jaar);
IF eerste^.jaar = tweede^.jaar THEN
IF eerste^.maand = tweede^.maand THEN
IF eerste^.dag = tweede^.dag THEN
jongste^ := eerste^;
oudste^ := tweede^;
ELSIF eerste^.dag > tweede^.dag THEN
jongste^ := eerste^;
oudste^ := tweede^;
ELSE
jongste^ := tweede^;
oudste^ := eerste^;
END;
ELSIF eerste^.maand > tweede^.maand THEN
oudste^ := tweede^;
jongste^ := eerste^;
ELSE
jongste^ := tweede^;
oudste^ := eerste^;
END;
ELSIF eerste^.jaar > tweede^.jaar THEN
oudste^ := tweede^;
jongste^ := eerste^;
ELSE
jongste^ := tweede^;
oudste^ := eerste^;
END;
OutExt.String("Het verschil in aantal dagen tussen");
OutExt.Ln;
OutExt.Int(oudste^.dag,0);
OutExt.String("/");
OutExt.Int(oudste^.maand,0);
OutExt.String("/");
OutExt.Int(oudste^.jaar,0);
OutExt.String(" en ");
OutExt.Int(jongste^.dag,0);
OutExt.String("/");
OutExt.Int(jongste^.maand,0);
OutExt.String("/");
OutExt.Int(jongste^.jaar,0);
OutExt.String(" is ");
OutExt.Int(Verschil(oudste, jongste),0);
OutExt.Ln;
END Doe;
END Datum.
Datum.Tool
Code: Select all
(*
Date Created: 19/01/2006
*)
System.Recall
Builder.Compile \wesv2
OutExt.Mod
Datum.Mod
~
Builder.Compile \f *
System.Free
Datum.Mod
OutExt.Mod
~
OutExt.Clear
Datum.Doe
5 1 2001 1 1 2002~