100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
Summary CPSC 110 PSET 8 SOLUTION $20.49   Add to cart

Summary

Summary CPSC 110 PSET 8 SOLUTION

3 reviews
 1869 views  22 purchases
  • Course
  • Institution

CPSC 110 PSET 8 SOLUTION

Preview 2 out of 6  pages

  • July 11, 2021
  • 6
  • 2020/2021
  • Summary

3  reviews

review-writer-avatar

By: luckyisepicpanda2222 • 2 year ago

review-writer-avatar

By: kahin604425 • 2 year ago

review-writer-avatar

By: trojan089 • 2 year ago

avatar-seller
;; 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)))

(@template fn-composition use-abstract-fn)

(define (sum-squares lon)
(foldr + 0 (map sqr lon)))


(@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)

, (check-expect (all-a-contain? (list "assignment") "eight") false)
(check-expect (all-a-contain? (list "attend" "radio" "antenna" "listen" "study")
"ten")
true)
(check-expect (all-a-contain? (list "art" "bin" "action" "tin") "in") false)
(check-expect (all-a-contain? (list "art" "artery" "ban" "action" "tin")
"art")
false)

(@template fn-composition use-abstract-fn)

(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.
;;

(@htdf brown-cat-names)
(@signature (listof Cat) -> (listof String))

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying these notes from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller travissmith1. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for $20.49. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

73216 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy study notes for 14 years now

Start selling
$20.49  22x  sold
  • (3)
  Add to cart