exam3.1.1-exam3.1.4

444阅读 0评论2011-12-07 maunix
分类:LINUX

  1. ;; mht created on Nov 8, 2011

  2. ;; profit : number number -> number
  3. ;; to compute the profit as the difference between revenue and costs at some given ticket-price
  4. ;; example : (profit 5) should be (- 600 184.8)
  5. (define (profit ticket-price)
  6.   (- (revenue ticket-price)
  7.      (costs ticket-price)))

  8. ;; revenue : number -> number
  9. ;; to compute the revenue given ticket-price
  10. ;; example : (revenue 5) should be (* 5 120)
  11. (define (revenue ticket-price)
  12.   (* ticket-price
  13.      (attendees ticket-price)))

  14. ;; costs : number -> number
  15. ;; to compute the costs given ticket-price
  16. ;; example : (costs 5) should be (+ 180 (* 120 0.04))
  17. (define (costs ticket-price)
  18.   (+ 180 (
  19.           * .04 (attendees ticket-price))))

  20. ;; attendees : number -> number
  21. ;; to compute the number of attendees, given ticket-price
  22. ;; example : (attendees 5) should be 120
  23. ;; (attendees 3) should be 420
  24. ;; (attendees 4) should be 270
  25. (define (attendees ticket-price)
  26.   (+ 120
  27.      (* (/ 15 .10) (- 5.00 ticket-price))))

  28. ;; test:
  29. (attendees 4)
  30. (costs 5)
  31. (profit 3)
  32. (profit 4)
  33. (profit 5)

  34. ;; new-costs: number -> number
  35. ;; to compute the costs given ticket-price
  36. ;;
  37. (define (new-costs ticket-price)
  38.   (* 1.54 (attendees ticket-price)))
  39. ;; test
  40. ;(new-costs 5)


  41. ;; new-profit
  42. (define (new-profit ticket-price)
  43.   (- (revenue ticket-price)
  44.      (new-costs ticket-price)))
  45.      
  46. (new-profit 3)
  47. (new-profit 4)
  48. (new-profit 5)
上一篇:exam2.4.4
下一篇:exam3.3.1