Add initial UE4 A.2

This commit is contained in:
Ivaylo Ivanov 2021-11-10 17:08:35 +01:00
parent b0c2e9ad5b
commit c31798f66c
1 changed files with 40 additions and 16 deletions

View File

@ -289,29 +289,53 @@ Aufgabe A.1
Aufgabe A.2
% > data EuroCent = EC { euro :: Nat1,
% > cent :: Nat1
Nur Werte zwischen 0 und 99 fuer cent!
% Nur Werte zwischen 0 und 99 fuer cent!
> data EuroCent = EC { euro :: Nat1,
> cent :: Nat1
> } deriving (Eq,Ord,Show)
% > } deriving (Eq,Ord,Show)
> data K_Geschaeftsvorfall = K_Zahlung { ec_netto :: EuroCent,
> zahlungsdatum' :: Datum
> }
> | K_Gutschrift { ec_gutschrift :: EuroCent,
> gutschriftsdatum' :: Datum
> } deriving (Eq,Show)
% > data K_Geschaeftsvorfall = K_Zahlung { ec_netto :: EuroCent,
% > zahlungsdatum' :: Datum
% > }
% > | K_Gutschrift { ec_gutschrift :: EuroCent,
% > gutschriftsdatum' :: Datum
% > } deriving (Eq,Show)
> newtype KonsolidiertesKassabuch
> = KKB [(P_Geschaeftspartner,K_Geschaeftsvorfall)]
> deriving (Eq,Show)
% > newtype KonsolidiertesKassabuch
% > = KKB [(P_Geschaeftspartner,K_Geschaeftsvorfall)]
% > deriving (Eq,Show)
> konsolidiere :: Kassabuch -> KonsolidiertesKassabuch
> konsolidiere k = consolidate_cash_book k []
% > konsolidiere :: Kassabuch -> KonsolidiertesKassabuch
Knapp, aber gut nachvollziehbar geht konsolidiere folgendermassen vor:
...
> consolidate_cash_book :: Kassabuch -> [(P_Geschaeftspartner,K_Geschaeftsvorfall)] -> KonsolidiertesKassabuch
> consolidate_cash_book (KB (x:xs)) res
> | length x /= 0 && null xs = KKB(res ++ [entry])
> | otherwise = consolidate_cash_book (KB(xs)) (res ++ [entry])
> where
> (g, v) = x
> entry = consolidate_payment $ eval_payment_sum $ eval_payment_date (g, v)
> consolidate_payment :: AP_Kassabucheintrag -> (P_Geschaeftspartner,K_Geschaeftsvorfall)
> consolidate_payment (g, v) = (g, consolidate_payment_sum v)
> consolidate_payment_sum :: AP_Geschaeftsvorfall -> K_Geschaeftsvorfall
> consolidate_payment_sum g
> | is_p_credit g = K_Gutschrift (res) (gutschriftsdatum g)
> | otherwise = K_Zahlung (res') (zahlungsdatum g)
> where
> sum = gutschrift g
> sum' = netto g
> res = EuroCent (sum/100) (sum `mod` 100)
> res' = EuroCent (sum'/100) (sum' `mod` 100)
> is_p_credit :: AP_Geschaeftsvorfall -> Bool
> is_p_credit g =
> case g of
> P_Gutschrift _ _ -> True
> _ -> False
Aufgabe A.3