Commit 3eb24fb1 authored by rokka's avatar rokka

A3

parent e1e2d1ab
mohamada_kroell_*.zip
File added
;; 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 A32) (read-case-sensitive #t) (teachpacks ((lib "image.rkt" "teachpack" "2htdp") (lib "universe.rkt" "teachpack" "2htdp"))) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ((lib "image.rkt" "teachpack" "2htdp") (lib "universe.rkt" "teachpack" "2htdp")) #f)))
(require racket/base)
(require racket/date)
; Number Number Number Number Number Number -> Number
; Calculates the age in years by comparing the given birthday (bday.bmon.byear)
; with the given date (cday.cmon.cyear)
(check-expect (age 27 3 1991 8 5 2019) 28)
(check-expect (age 27 3 1998 27 3 1999) 1)
(define (age bday bmon byear cday cmon cyear)
(cond
[( < cmon bmon) (- (- cyear byear) 1)]
[( > cmon bmon) (- cyear byear)]
[( < cday bday) (- (- cyear byear) 1)]
[else ( - cyear byear)]
)
)
; vector -> vector
; retrieves the current command-line arguments
(define args (current-command-line-arguments))
; Number Number Number date -> Number
; Calculates the age by comparing the given birthday (bday.bmon.byear)
; with the given date (cdate)
(check-expect (call-age 8 5 2020 (current-date)) "Still swimming in the balls")
(check-expect (call-age 27 3 1991 (current-date)) 28)
(define (call-age bday bmon byear cdate)
(cond
[(or ( > byear (date-year cdate))
( and (> byear (date-year cdate))
(> bmon (date-month cdate)))
( and (> byear (date-year cdate))
(> bmon (date-month cdate))
(> bday (date-day cdate))))
"Still swimming in the balls"]
[else (age bday bmon byear (date-day cdate) (date-month cdate) (date-year cdate))]
))
; This program expects three command-line arguments representig
; a valid date and prints the current age.
; Example: racket batch-skel.rkt 1 5 1992
(if (= (vector-length args) 3)
(display (call-age
(string->number (vector-ref args 0))
(string->number (vector-ref args 1))
(string->number (vector-ref args 2))
(current-date) ))
(error "Bitte genau drei Parameter uebergeben"))
\ No newline at end of file
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment