100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
University of British Columbia CPSC 110 LAB 1 $2.99   Add to cart

Exam (elaborations)

University of British Columbia CPSC 110 LAB 1

 84 views  0 purchase
  • Course
  • Institution

University of British Columbia CPSC 110 LAB 1

Preview 2 out of 6  pages

  • October 15, 2021
  • 6
  • 2021/2022
  • Exam (elaborations)
  • Questions & answers
avatar-seller
CPSC 110 LAB 1

HtDF Lab

P3
A (much too) simple scheme for pluralizing words in English is to add an
s at the end unless the word already ends in s.

Design a function that consumes a string, and adds s to the end unless
the string already ends in s.

;; String -> String
;; Adds an s to end of given word, unless word already ends in s
(check-expect (pluralize "hello") "hellos")
(check-expect (pluralize "has") "has")
(check-expect (pluralize "") "")




m
er as
;(define (pluralize str) "") ;stub




co
eH w
;(define (pluralize str)




o.
; (... str)) ;template
rs e
ou urc
(define (pluralize str)
(if (string=? str "")
""
o

(if (string=? "s" (string-ith str (- (string-length str) 1)))
aC s

str
vi y re


(string-append str "s"))))

P4
Design a function called nth-char-equal? that consumes two strings
ed d




and a natural and produces true if the strings both have length greater
ar stu




than n and have the same character at position n.

Note, the signature for such a function is:
;; String String Natural -> Boolean
is




The template for such a function is:
Th




(define (nth-char-equal? s1 s2 n)
(... s1 s2 n))
sh




;; String String Natural -> Boolean
;; Produces true if string-length of s1 and s2 are greater than n and have the same character at position
n
(check-expect (nth-char-equal? "hello" "goodbye" 10) false)
(check-expect (nth-char-equal? "hello" "bell" 6) false)
(check-expect (nth-char-equal? "time" "bath" 3) false)
(check-expect (nth-char-equal? "candy" "mandy" 3) true)


This study source was downloaded by 100000805705997 from CourseHero.com on 10-14-2021 20:45:30 GMT -05:00


https://www.coursehero.com/file/46578028/CPSC-110-LAB-1docx/

, ;(define (nth-char-equal? s1 s2 n) false) ;stub

;(define (nth-char-equal? s1 s2 n)
; (... s1 s2 n)) ;template

(define (nth-char-equal? s1 s2 n)
(if (> (string-length s1) n)
(if (> (string-length s2) n)
(string=? (substring s1 (- n 1) n) (substring s2 (- n 1) n))
false)
false))


Balloon Lab




m
; Balloon popping




er as
co
;; CONSTANTS ==========================




eH w
o.
(define WIDTH 500)
(define HEIGHT 500)
rs e
ou urc
(define MTS (empty-scene WIDTH HEIGHT))

(define BALLOON-COLOUR "red")
o

(define POP-IMAGE (overlay (text "POP!" 80 "black")
(radial-star 30 (/ WIDTH 10) (/ WIDTH 2) "solid" "yellow")))
aC s
vi y re



(define CTR-X (/ WIDTH 2))
(define CTR-Y (/ HEIGHT 2))
ed d




(define SPEED 2)
ar stu




(define MAX-SIZE (/ WIDTH 2))

;; DATA DEFINITIONS ============================
is




;; Balloon is one of:
Th




;; - Number[1, MAX-SIZE]
;; - false
;; interp. number is the radius of balloon in screen pixels, false means balloon is popped
sh




(define B1 1)
(define B2 false)
(define B3 10)
(define B4 MAX-SIZE)

(define (fn-for-balloon b)
(cond [(and (number? b)


This study source was downloaded by 100000805705997 from CourseHero.com on 10-14-2021 20:45:30 GMT -05:00


https://www.coursehero.com/file/46578028/CPSC-110-LAB-1docx/

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 solutions. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

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

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

83637 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
$2.99
  • (0)
  Add to cart