Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Exam (elaborations)

CPSC110 Pset2 Solution

Rating
-
Sold
-
Pages
5
Grade
A
Uploaded on
16-11-2025
Written in
2025/2026

This is the correct and the latest solution for pset 2.

Institution
Module

Content preview

;​; DO NOT PUT ANYTHING PERSONALLY IDENTIFYING BEYOND YOUR CWL IN THIS​
​FILE.​
​;; YOUR CWLs WILL BE SUFFICIENT TO IDENTIFY YOU.​
​;;​
​(require spd/tags)​
​(require 2htdp/image)​

​(@assignment psets/pset-02);Do not edit or remove this tag​


(​ @problem 1)​
​;;​
​;; The following function design may have errors in it. Please fix the error​
​;; or errors that you find. Any changes you make should preserve the existing​
​;; design intent. NOTE THAT when fixing an error in existing code the best​
​;; practice is to change as little of the code as possible. That is because​
​;; in most organizations 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 entire function 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 existing 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 solution must include @htdf, @signature, and @template-origin tags.​
​;;​
​(@htdf stack)​
​(@signature Image Image -> Image)​
​;; stack images, widest on bottom, first on bottom 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 existing​
​;; design intent. Again, change only the parts of the code you really need​
​;; to change.​
​;;​
​;; Your solution 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 enumerations>​

​(@dd-template-rules one-of​
​atomic-distinct​
​atomic-distinct​
​atomic-distinct​
​atomic-distinct)​

​(define (fn-for-site s)​
​(cond [(string=? s "Vancouver") (...)]​
​[(string=? s "Okanagan") (...)]​
​[(string=? s "Robson") (...)]​
​[(string=? s "CDM") (...)]))​

Written for

Institution
Study
Module

Document information

Uploaded on
November 16, 2025
Number of pages
5
Written in
2025/2026
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

$10.32
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
06shyun1211

Get to know the seller

Seller avatar
06shyun1211 University of British Columbia
Follow You need to be logged in order to follow users or courses
Sold
1
Member since
4 months
Number of followers
0
Documents
8
Last sold
3 weeks ago

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Trending documents

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 revision notes.

Didn't get what you expected? Choose another document

No problem! You can straightaway pick a different document that better suits what you're after.

Pay as you like, start learning straight away

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

Student with book image

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

Alisha Student

Frequently asked questions