Initial commit

This commit is contained in:
Folkert Kevelam 2025-06-13 21:09:10 +02:00
parent f0fceb7473
commit 5f5c2c3c5a
2 changed files with 63 additions and 0 deletions

28
src/finance.adb Normal file
View File

@ -0,0 +1,28 @@
package body Finance is
function Round (N : Decimal) return Decimal is
begin
return N;
end Round;
procedure Add_Entry
(Trans : in out Transaction;
E : Transaction_Entry)
is
begin
Trans.Entries.Append (E);
end Add_Entry;
function Validate (T : Transaction)
return Boolean
is
Sum : Decimal := 0.0;
begin
for E of T.Entries loop
Sum := @ + E.Amount;
end loop;
return Round (Sum) = 0.0;
end Validate;
end Finance;

35
src/finance.ads Normal file
View File

@ -0,0 +1,35 @@
with Ada.Containers.Vectors;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
package Finance is
type Decimal is delta 1.0E-20 digits 38;
type Transaction_Entry is
record
Amount : Decimal;
Account : Unbounded_String;
end record;
package Entry_Vec is new Ada.Containers.Vectors (
Index_Type => Natural,
Element_Type => Transaction_Entry
);
use type Entry_Vec.Vector;
type Transaction is
record
Entries : Entry_Vec.Vector;
end record;
function Round (N : Decimal) return Decimal;
procedure Add_Entry
(Trans : in out Transaction;
E : Transaction_Entry);
function Validate (T : Transaction)
return Boolean;
end Finance;