Add initial implementation for UE4 A.3
This commit is contained in:
parent
0e34fc42a0
commit
cce90430ad
@ -222,7 +222,7 @@ Helper functions:
|
||||
> Gutschrift _ _ -> True
|
||||
> _ -> False
|
||||
|
||||
|
||||
===================================================================================
|
||||
Aufgabe A.1
|
||||
|
||||
> type P_Geschaeftspartner = Geschaeftspartner
|
||||
@ -287,6 +287,7 @@ Aufgabe A.1
|
||||
> n = C ((round(b - (b * s))) :: Nat1)
|
||||
|
||||
|
||||
===================================================================================
|
||||
Aufgabe A.2
|
||||
|
||||
Nur Werte zwischen 0 und 99 fuer cent!
|
||||
@ -306,6 +307,26 @@ Nur Werte zwischen 0 und 99 fuer cent!
|
||||
> = KKB [(P_Geschaeftspartner,K_Geschaeftsvorfall)]
|
||||
> deriving (Eq,Show)
|
||||
|
||||
> instance Num EuroCent where
|
||||
> (+) s s' = (add_ec s s')
|
||||
> (-) s s' = (diff_ec s s')
|
||||
|
||||
> add_ec :: EuroCent -> EuroCent -> EuroCent
|
||||
> add_ec s s'
|
||||
> | total_cents > 100 = EC (total_euro + 1) (total_cents - 100)
|
||||
> | otherwise = EC total_euro total_cents
|
||||
> where
|
||||
> total_cents = (cent s) + (cent s')
|
||||
> total_euro = (euro s) + (euro s')
|
||||
|
||||
> diff_ec :: EuroCent -> EuroCent -> EuroCent
|
||||
> diff_ec s s'
|
||||
> | total_cents < 0 = EC (total_euro - 1) (100 + total_cents)
|
||||
> | otherwise = EC total_euro total_cents
|
||||
> where
|
||||
> total_cents = (cent s) - (cent s')
|
||||
> total_euro = (euro s) - (euro s')
|
||||
|
||||
> konsolidiere :: Kassabuch -> KonsolidiertesKassabuch
|
||||
> konsolidiere k = consolidate_cash_book k []
|
||||
|
||||
@ -346,19 +367,67 @@ Nur Werte zwischen 0 und 99 fuer cent!
|
||||
> P_Gutschrift _ _ -> True
|
||||
> _ -> False
|
||||
|
||||
|
||||
===================================================================================
|
||||
Aufgabe A.3
|
||||
|
||||
% > data Saldo = Forderungssaldo { fs :: EuroCent }
|
||||
% > | Zahlungssaldo { zs :: EuroCent }
|
||||
% > | Ausgeglichen
|
||||
% > | Keine_Geschaeftsbeziehung deriving (Eq,Show)
|
||||
> data Saldo = Forderungssaldo { fs :: EuroCent }
|
||||
> | Zahlungssaldo { zs :: EuroCent }
|
||||
> | Ausgeglichen
|
||||
> | Keine_Geschaeftsbeziehung deriving (Eq,Show)
|
||||
|
||||
% > saldo :: P_Geschaeftspartner -> KonsolidiertesKassabuch -> Saldo
|
||||
> saldo :: P_Geschaeftspartner -> KonsolidiertesKassabuch -> Saldo
|
||||
> saldo p k = get_balance $ get_partner_cashflow p k []
|
||||
|
||||
Knapp, aber gut nachvollziehbar geht saldo folgendermassen vor:
|
||||
...
|
||||
> get_balance :: KonsolidiertesKassabuch -> Saldo
|
||||
> get_balance k
|
||||
> | payments == 0 && credit == 0 = Keine_Geschaeftsbeziehung
|
||||
> | payments == credit = Ausgeglichen
|
||||
> | payments > credit = Zahlungssaldo (payments - credit)
|
||||
> | otherwise = Forderungssaldo (credit - payments)
|
||||
> where
|
||||
> init = EC 0 0
|
||||
> payments = calculate_partner_payments k init
|
||||
> credit = calculate_partner_credit k init
|
||||
|
||||
> get_partner_cashflow :: P_Geschaeftspartner -> KonsolidiertesKassabuch -> [(P_Geschaeftspartner,K_Geschaeftsvorfall)] -> KonsolidiertesKassabuch
|
||||
> get_partner_cashflow p (KKB(x:xs)) res
|
||||
> | length x /= 0 && null xs =
|
||||
> if g == p then KKB(res ++ [(p, v)])
|
||||
> else KKB(res)
|
||||
> | g == p = get_partner_cashflow p (KKB(xs)) (res ++ [(p, v)])
|
||||
> | otherwise = get_partner_cashflow p (KKB(xs)) res
|
||||
> where
|
||||
> (g, v) = x
|
||||
|
||||
> calculate_partner_payments :: KonsolidiertesKassabuch -> EuroCent -> EuroCent
|
||||
> calculate_partner_payments (KKB(x:xs)) res
|
||||
> | length x /= 0 && null xs =
|
||||
> if is_k_credit v then res
|
||||
> else res + (ec_netto v)
|
||||
> | is_k_credit v = calculate_partner_payments (KKB(xs)) res
|
||||
> | otherwise = calculate_partner_payments (KKB(xs)) (res + (ec_netto v))
|
||||
> where
|
||||
> (g,v) = x
|
||||
|
||||
> calculate_partner_credit :: KonsolidiertesKassabuch -> EuroCent -> EuroCent
|
||||
> calculate_partner_credit (KKB(x:xs)) res
|
||||
> | length x /= 0 && null xs =
|
||||
> if is_k_credit v then res + (ec_netto v)
|
||||
> else res
|
||||
> | is_k_credit v = calculate_partner_credit (KKB(xs)) (res + (ec_netto v))
|
||||
> | otherwise = calculate_partner_credit (KKB(xs)) res
|
||||
> where
|
||||
> (g,v) = x
|
||||
|
||||
|
||||
> is_k_credit :: K_Geschaeftsvorfall -> Bool
|
||||
> is_k_credit g =
|
||||
> case g of
|
||||
> K_Gutschrift _ _ -> True
|
||||
> _ -> False
|
||||
|
||||
===================================================================================
|
||||
Aufgabe A.4
|
||||
|
||||
% > newtype SaldiertesKassabuch = SKB [(Geschaeftspartner,Saldo)]
|
||||
|
Reference in New Issue
Block a user