diff --git a/src/finance.adb b/src/finance.adb new file mode 100644 index 0000000..c24cf91 --- /dev/null +++ b/src/finance.adb @@ -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; diff --git a/src/finance.ads b/src/finance.ads new file mode 100644 index 0000000..5dfadd4 --- /dev/null +++ b/src/finance.ads @@ -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;