#reader(lib "htdp-beginner-reader.ss" "lang")((modname web-file-size-mixed-struct) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ())))
(define-struct text-file (name lines))
(define-struct image-file (name width height color?))
(define-struct sound-file (name duration))
(define article (make-text-file "article.doc" 250))
(define pic (make-image-file "blue-car.jpg" 300 450 true))
(define beep (make-sound-file "beep.mp3" 7))
(check-expect (file-size article) 15000)
(check-expect (file-size pic) 405000)
(check-expect (file-size beep) 210)
(define (file-size a-file)
(cond
[(text-file? a-file) (* 60 (text-file-lines a-file))]
[(image-file? a-file)
(cond
[(image-file-color? a-file)
(* 3 (image-file-width a-file) (image-file-height a-file))]
[else (* (image-file-width a-file) (image-file-height a-file))])]
[(sound-file? a-file) (* 30 (sound-file-duration a-file))] ))
(require "../web-launch.rkt")
(define/web text-file/web
(structure make-text-file ["File name" string+] ["Number of lines" number]))
(define/web image-file/web
(structure make-image-file ["File name" string+]
["Width (pixels)" number] ["Height (pixels)" number]
["Full-color" boolean]))
(define/web sound-file/web
(structure make-sound-file ["File name" string+] ["Duration of play (secs)" number]))
(web-launch
"File Size Computer"
(function "Computes the size of a file in bytes"
(file-size ["Web media" (oneof ["Text file" text-file/web]
["Image file" image-file/web]
["Sound file" sound-file/web])]
-> ["Computed size in bytes" number])))