Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

How do you do this?

Name: Anonymous 2013-02-02 22:23


(define-struct trans (action amount))
;; A trans is a structure (make-trans a amt),
;; that represents a transaction for a bank account, where
;; a is a symbol, either ‘deposit or ‘withdraw. A deposit is a ;; payment made into the account. A withdrawal is a payment
;; made out of the account.
;; amt is a positive number representing the amount added
;; or removed from the account.


Use accumulative recursion to write a function named update-balance that consumes a list of transactions that took place during the month (lot), and a starting balance at the beginning of the month (start-bal). The function produces the balance of a bank account after processing all of the transactions in lot. The balance may drop below zero at any point. You may assume that deposits and withdrawals will have no more than two decimal places and thus the balance produced by update-balance will have no more than two decimal places.
For example:

   (update-balance
      (list (make-trans ‘withdraw 604.34)
            (make-trans ‘deposit 300)) 0) => -304.34
   (update-balance
(list (make-trans ‘withdraw 20.99)(make-trans ‘deposit 60) (make-trans ‘deposit 900)(make-trans ‘withdraw 55.5)
(make-trans ‘deposit 100)(make-trans ‘deposit 40))50) => 1073.51

Name: Anonymous 2013-02-02 22:28

Try something like

fold accumTransactions Transactions | commit

Name: Anonymous 2013-02-02 22:36

You're never going to pass this class.

Name: Anonymous 2013-02-02 22:39

What the fuck do you even do in your midterms? This is like the fifth question you make.

Tried asking Stack Overflow?

Name: Anonymous 2013-02-02 23:35

ugh why recursion ? ^^

Name: Anonymous 2013-02-02 23:39

does it even store all the intermediate balances..? if yes then fair enough...

Name: Anonymous 2013-02-02 23:52

Easy.

I don't feel bad about helping because there's no way in hell you'll pass this class anyway.

(define make-trans cons)
(define trans-type car)
(define trans-amt cdr)

(define (update-balance lot start-bal)
   (if (null? lot)
     start-bal
     (update-balance
       (cdr lot)
       (let ((trans (car lot)))
         ((case (trans-type trans)
            ((deposit) +)
            ((withdraw) -)
            (else (error "transaction type"
                         (trans-type trans))))
           start-bal
           (trans-amt trans))))))

Name: Anonymous 2013-02-03 0:00

ihn octave... would be something like

nuBalance = balance + sum(trans(2, (trans(1,:)==1)) - sum(trans(2, (trans(1,:)==-1));

Name: Anonymous 2013-02-03 15:12

I'm pretty sure you can do this in a single fold over lot

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List