;; Die ersten drei Zeilen dieser Datei wurden von DrRacket eingefügt. Sie enthalten Metadaten ;; über die Sprachebene dieser Datei in einer Form, die DrRacket verarbeiten kann. #reader(lib "DMdA-assignments-reader.ss" "deinprogramm")((modname mutable-account) (read-case-sensitive #f) (teachpacks ()) (deinprogramm-settings #(#f write repeating-decimal #t #t none explicit #f ()))) ; Ein veränderbares Bankkonto besteht aus ; - einen Kontostand (real) (define-record-procedures-2 account make-account account? ((account-balance set-account-balance!))) (: make-account (real -> account)) (: account? (any -> boolean)) (: account-balance (account -> real)) (: set-account-balance! (account real -> unspecific)) ; Abheben von einem Bankkonto (: account-withdraw! (account real -> real)) (define account-withdraw! (lambda (acct amount) (if (>= (account-balance acct) amount) (begin (set-account-balance! acct (- (account-balance acct) amount)) (account-balance acct)) (violation "No money!")))) ; Einzahlen auf ein Bankkonto (: account-deposit! (account real -> real)) (define account-deposit! (lambda (acct amount) (begin (set-account-balance! acct (+ (account-balance acct) amount)) (account-balance acct)))) ; Überweise einen Betrag zwischen zwei Bankkonten (: transfer-money! (account account real -> unspecific)) (define transfer-money! (lambda (acct1 acct2 amount) (begin (account-withdraw! acct1 amount) (account-deposit! acct2 amount)))) (define A1 (make-account 100))