NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

;; The first three lines of this file were inserted by DrRacket. They record metadata
;; about the language level of this file in a form that our tools can easily process.
#reader(lib "htdp-beginner-reader.ss" "lang")((modname sparplan-template) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ())))
;; Authors: GLOWKA HAQUE

;; Error tolerance: 3 decimal digits
(define tolerance 0.001)

;; === Problem 9.1 ===

;; add-interest: number number--> number
;; nimmt Kapital und Zinssatz, berechnet daraus das Endkapital
;; Bsp. (add-interest 100 0.01) sollte 101 ausgeben
;;
(define (add-interest capital interest)
(if (> 0 capital) capital


(if(> 0 interest)
(error "add-interest: no negative interest rates allowed")
(+(* capital interest)capital)))
)

;; Tests - these do NOT count as "your" tests!
(check-expect (add-interest 100 0.02) 102)
(check-within (add-interest 1337.15 0.008) 1347.8472 tolerance)
(check-error (add-interest 4711 -0.005) "add-interest: no negative interest rates allowed")

;; === Problem 9.2 ===

;; average-yearly-return:
;;konsumiert Anfangskapital, Endkapital, Vertragslaufzeit und berechnet daraus den Durchschnittszinssatz
;;
(define (average-yearly-return capital-after capital-before years)
(- (expt(/ capital-after capital-before)(/ 1 years))1))

;; Tests - these do NOT count as "your" tests!
(check-within (average-yearly-return 110 100 5) 0.0192 tolerance)
(check-within (average-yearly-return 3500 3000 10) 0.0155 tolerance)

;; === Problem 9.3 ===

;; savings-plan-a: number number --> number
;; konsumiert jeweils das Anfangskapital und die Vertragslaufzeit und geben das Endkapital zurück
;; im falle einer Laufzeitangabe von weniger als einem oder mehr als drei Jahren gibt es einen FEHLER
;;


(define (savings-plan-a capital years)
(cond
[(and(>= years 1)(< years 2))(add-interest capital 0.005) ]
[(and(>= years 2)(< years 3))(add-interest(add-interest capital 0.005) 0.01)]
[(and(>= years 3)(< years 4))(add-interest (add-interest(add-interest capital 0.005) 0.01) 0.015)]
[else (error "savings-plan-a: invalid runtime")]))


;; Tests - these do NOT count as "your" tests!
(check-within (savings-plan-a 1000 1) 1005 tolerance)
(check-within (savings-plan-a 1000 2) 1015.05 tolerance)
(check-within (savings-plan-a 1000 3) 1030.276 tolerance)
(check-error (savings-plan-a 1000 0.5)"savings-plan-a: invalid runtime")
(check-error (savings-plan-a 1000 4) "savings-plan-a: invalid runtime")

;; savings-plan-b:
;;
;;
;;
(define (savings-plan-b capital years)
(cond
[(and(>= years 1)(< years 2))(add-interest capital 0.005) ]
[(and(>= years 2)(< years 3)) (add-interest(add-interest capital 0.005) 0.005)]
[(and(>= years 3)(< years 4))(+ 30(add-interest (add-interest(add-interest capital 0.005) 0.005) 0.005))]
[else (error "savings-plan-b: invalid runtime")]))



;; Tests - these do NOT count as "your" tests!
(check-within (savings-plan-b 1000 1) 1005 tolerance)
(check-within (savings-plan-b 1000 2) 1010.025 tolerance)
(check-within (savings-plan-b 1000 3) 1045.075 tolerance)
(check-error (savings-plan-b 1000 0.5) "savings-plan-b: invalid runtime")
(check-error (savings-plan-b 1000 4) "savings-plan-b: invalid runtime")

;; === Problem 9.4 ====

;; best-savings-plan: number number --> symbol
;;konsumiert Anfangskapital und die Laufzeit, anhand dessen vergleicht er die Sparpläne und gibt den am meisten geeigneten aus
;;
;;
(define (best-savings-plan capital years)
(if (<(savings-plan-b capital years)(savings-plan-a capital years))
'SavingsPlanA
'SavingsPlanB))

;; Tests - these do NOT count as "your" tests!
(check-expect (best-savings-plan 2000 3) 'SavingsPlanA)
(check-expect (best-savings-plan 1000 3) 'SavingsPlanB)
(check-expect (best-savings-plan 500 2) 'SavingsPlanA)
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.