100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Other

CPSC110 problem set 4 solution

Rating
-
Sold
-
Pages
5
Uploaded on
05-01-2024
Written in
2023/2024

completed solution for problem set 4

Institution
Course









Whoops! We can’t load your doc right now. Try again or contact support.

Written for

Institution
Study
Course

Document information

Uploaded on
January 5, 2024
Number of pages
5
Written in
2023/2024
Type
Other
Person
Unknown

Subjects

Content preview

(@problem 1)
;;
;; The following func7on design may have errors in it. Please fix the error
;; or errors that you find. Any changes you make should preserve the exis7ng
;; design intent. NOTE THAT when fixing an error in exis7ng code the best
;; prac7ce is to change as liHle of the code as possible. That is because
;; in most organiza7ons someone will have to review any changes you make,
;; and changing only what you really mean to change will make that person's
;; job easier. Remember always that the goal is to be kind to your fellow
;; programmers.
;;
;; First uncomment the en7re func7on design, and then fix the error.
;; If you are unable to find and fix the error, leave it commented out.
;; Note that when fixing a bug in an exis7ng program your goal should
;; be to have a light touch. If there is a small simple way to fix
;; something then do it the small and simple way.
;;
;; Your solu7on must include @htdf, @signature, and @template-origin tags.

(@htdf stack)
(@signature Image Image -> Image)
;; stack images, widest on boHom, first on boHom if same width
(check-expect (stack (rectangle 10 5 "solid" "blue")
(rectangle 20 9 "solid" "red"))
(above (rectangle 10 5 "solid" "blue")
(rectangle 20 9 "solid" "red")))

(check-expect (stack (rectangle 20 5 "solid" "blue")
(rectangle 20 9 "solid" "red"))
(above (rectangle 20 9 "solid" "red")
(rectangle 20 5 "solid" "blue")))

(check-expect (stack (rectangle 20 5 "solid" "blue")
(rectangle 10 9 "solid" "red"))
(above (rectangle 10 9 "solid" "red")
(rectangle 20 5 "solid" "blue")))

;(define (stack i1 i2) i1) ;stub

(@template-origin Image)

(@template
(define (stack i1 i2)
(... i1 i2)))

, (define (stack i1 i2)
(if (>= (image-width i1) (image-width i2))
(above i2 i1)
(above i1 i2)))



(@problem 2)
;;
;; The following data design may have errors in it. Please fix the error or
;; errors that you find. Any changes you make should preserve the exis7ng
;; design intent. Again, change only the parts of the code you really need
;; to change.
;;
;; Your solu7on must include @htdd tag, @dd-template-rules tag, and a NOT
;; commented fn-for-site template.
;;


(@htdd Site)
;; Site is one of:
;; - "Vancouver"
;; - "Okanagan"
;; - "Robson"
;; - "CDM"
;; interp. a UBC site
;; <Examples are redundant for enumera7ons>

(@dd-template-rules one-of
atomic-dis7nct
atomic-dis7nct
atomic-dis7nct
atomic-dis7nct)

(define (fn-for-site s)
(cond [(string=? s "Vancouver") (...)]
[(string=? s "Okanagan") (...)]
[(string=? s "Robson") (...)]
[(string=? s "CDM") (...)]))
R147,40
Get access to the full document:

100% satisfaction guarantee
Immediately available after payment
Both online and in PDF
No strings attached

Get to know the seller
Seller avatar
skye3

Get to know the seller

Seller avatar
skye3 UBC
Follow You need to be logged in order to follow users or courses
Sold
5
Member since
1 year
Number of followers
1
Documents
9
Last sold
1 year ago

0,0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their exams and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can immediately select a different document that better matches what you need.

Pay how you prefer, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card or EFT and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions