Par: luckyisepicpanda2222 • 1 année de cela
Par: kahin604425 • 2 année de cela
Par: trojan089 • 2 année de cela
Vendeur
S'abonner
travissmith1
Avis reçus
Aperçu du contenu
;; 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-intermediate-reader.ss" "lang")((modname pset-08-solution) (read-
case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-
decimal #f #t none #f () #t)))
;; DO NOT PUT ANYTHING PERSONALLY IDENTIFYING BEYOND YOUR CWL IN THIS FILE.
;; YOUR CWLs WILL BE SUFFICIENT TO IDENTIFY YOU AND, IF YOU HAVE ONE, YOUR
;; PARTNER.
;;
(require spd/tags)
(@assignment pset-08); Do not edit or remove this tag
(@problem 1)
;;
;; Design a function called sum-squares that consumes a list of naturals,
;; and produces the sum of squaring all of the naturals in the list.
;;
;; For example: (sum-squares (list 5 2 4)) produces 45.
;;
;; Your function definition must use built-in abstract functions.
;; For full marks it must be a composition of exactly 2 built-in
;; abstract functions.
;;
(@htdf sum-squares)
(@signature (listof Natural) -> Natural)
;; produce the sum of squaring all of the numbers in lon
(check-expect (sum-squares empty) 0)
(check-expect (sum-squares (list 5 2 4))
(+ (sqr 5) (sqr 2) (sqr 4)))
(@problem 2)
;;
;; Complete the design of the following function.
;;
;; Your function definition must use built-in abstract functions.
;; For full marks it must be a composition of exactly 2 built-in
;; abstract functions.
;;
;; NOTE: Looking up the function string-contains? in the help desk
;; might be helpful...
(@htdf all-a-contain?)
(@signature (listof String) String -> Boolean)
;; determine if all strings that begin with the letter 'a' contain word w
(check-expect (all-a-contain? empty "word") true)
(check-expect (all-a-contain? (list "bicycle" "car" "train" "walk")
"transportation")
true)
(define (all-a-contain? los w)
(local [(define (contains-word? s)
(string-contains? w s))
(define (starts-with-a? s)
(string=? "a" (string-ith s 0)))]
(andmap contains-word? (filter starts-with-a? los))))
;;
;; Before completing problems 3, 4, and 5, please familiarize
;; yourself with the provided data definition for a Cat.
;; An example (listof Cat) is also provided.
;;
(@htdd Cat)
(define-struct cat (name color age))
;; Cat is (make-cat String Color Natural)
;; interp. a cat with a name, coat color, and age (in years)
(define C1 (make-cat "Whiskers" "brown" 13))
(define C2 (make-cat "Si" "black" 4))
(define C3 (make-cat "Am" "white" 4))
(define C4 (make-cat "Meow" "brown" 7))
(define C5 (make-cat "Garfield" "orange" 8))
(define C6 (make-cat "Sassy" "brown" 6))
(define (fn-for-cat c)
(... (cat-name c)
(cat-color c)
(cat-age c)))
(define LOC1 (list C1 C2 C3 C4 C5 C6)) ; to save time with check-expects
(@problem 3)
;;
;; Design a function called brown-cat-names that consumes a list of cats,
;; and produces a list of the names of the cats that are brown in color.
;;
;; For example: (brown-cat-names LOC1)
;; produces: (list "Whiskers" "Meow" "Sassy")
;;
;; Your function definition must use built-in abstract functions.
;; For full marks it must be a composition of exactly 2 built-in
;; abstract functions.
;;
Les clients de Stuvia ont évalués plus de 700 000 résumés. C'est comme ça que vous savez que vous achetez les meilleurs documents.
L’achat facile et rapide
Vous pouvez payer rapidement avec iDeal, carte de crédit ou Stuvia-crédit pour les résumés. Il n'y a pas d'adhésion nécessaire.
Focus sur l’essentiel
Vos camarades écrivent eux-mêmes les notes d’étude, c’est pourquoi les documents sont toujours fiables et à jour. Cela garantit que vous arrivez rapidement au coeur du matériel.
Foire aux questions
Qu'est-ce que j'obtiens en achetant ce document ?
Vous obtenez un PDF, disponible immédiatement après votre achat. Le document acheté est accessible à tout moment, n'importe où et indéfiniment via votre profil.
Garantie de remboursement : comment ça marche ?
Notre garantie de satisfaction garantit que vous trouverez toujours un document d'étude qui vous convient. Vous remplissez un formulaire et notre équipe du service client s'occupe du reste.
Auprès de qui est-ce que j'achète ce résumé ?
Stuvia est une place de marché. Alors, vous n'achetez donc pas ce document chez nous, mais auprès du vendeur travissmith1. Stuvia facilite les paiements au vendeur.
Est-ce que j'aurai un abonnement?
Non, vous n'achetez ce résumé que pour €18,87. Vous n'êtes lié à rien après votre achat.