;; 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 hw5-main) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f () #f)))
Copyright By PowCoder代写 加微信 powcoder
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Problem 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; You are going to make yourself a useful interactive app: flash cards
; (https://en.wikipedia.org/wiki/Flashcard).
; To begin, consider the following data definition…
(define-struct flashcard [front back])
; A FlashCard is a (make-flashcard String String)
; Interpretation: the front and back of a card
; TODO 1/4: Complete the design recipe for FlashCard.
; Now a single flash card wouldn’t be super useful, and so…
; TODO 2/4: Design ListOfFlashCard (LoFC) to support an arbitrarily sized
; sequence of flash cards. Importantly…
; – These should be proper lists (i.e., using cons and ‘()).
; – Make sure to give yourself a few example lists, of different sizes;
; hopefully they are useful in your classes!
; – Remember that your LoFC template should reflect that your list
; elements are themselves designed types (FlashCard).
; Now, for practice…
; TODO 3/4: Design the function has-text?, which determines if a list of flash
; cards contains any card that contains a supplied text.
; Hint: the string-contains? function is very useful for determining
; if one string contains another 🙂
; Finally, let’s put this list to use 🙂
; TODO 4/4: Design the program go-cards, which helps you study with a supplied list
; of cards. It starts on the first card and then flips it when a key is
; pressed, and then goes to the front of the next card when another key is
; pressed. The program should end when the last card has been flipped, and
; the go-cards function should return how many cards were in the original
; list. Some hints…
; – To get you started, you have been supplied the data definition of a
; way to represent the state of the program (don’t forget to uncomment
; the structure definition and finish the design recipe for data!).
; – The return value of this function is a bit challenging, since the list
; you get at the end is empty! So uncomment the code we’ve given you below,
; but to understand: you can *add* the length of the originally supplied
; list to that of the (empty) final list and still get the right answer 🙂
; – Be sure to follow the templates for all your data, which will typically
; entail helpers for the FS, the LoFC, and the FC.
; – As long as the program operates as described, you are welcome to make it
; look as simple or as creative as you would like – we hope it helps you
; in your classes!! 🙂
; (define-struct fs [cards front?])
; A FlashState (FS) is a (make-fs LoFC Boolean)
; Interpretation: a list of cards, and whether
; the front is face up
; go-cards : LoFC -> Nat
; displays the cards in sequence (flip via key),
; returning the number of cards
(define (go-cards lofc)
(length lofc)
(length (fs-cards
(big-bang (make-fs lofc #t)
[to-draw draw-fs]
[on-key flip-fs]
[stop-when done-fs?])))))
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com