CPSC 110 Study Guide - Winter 2018, Comprehensive Midterm Notes - Racket Programming Language, String Theory, Spider
CPSC 110
MIDTERM EXAM
STUDY GUIDE
Fall 2018
CPSC
Learning Syntax:
Athig that stats ith ; ill be regarded as notes that do not show up in DrRacket.
DrRacket
;; all values are expressions
;;
(+ 1 2)
# thing that follows the parenthesis has to be the name of the function
(+ (* 3 4) (+ 2 3))
Answer is 17
DrRacket
;; all values are expressions
;;
(+ (* 3 4) (+ 2 3))
(+ 12 (+ 2 3))
17
; ould podue 7s
;; evaluated to produce a result, in inside out left to right order
Example
c = sqrt ( a^2 + b^2)
(sqrt (+ (sqr 3) (sqr 4)))
Thee ae othe kids of alues: “tigs Ha doule uote folloed hat ou at
followed by double quote)
- Strings are self-evaluating
(string-apped Ha Potte
Takes the to stig ad oateates the = HaPotte
optios = Ha , Potte,
find more resources at oneclass.com
find more resources at oneclass.com
IMAGES
(require 2htdp/image)
etagle 5 solid lue
Canadian Flag Example:
(require 2htdp/image)
(beside (rectangle 30 50 "solid" "red")
(rectangle 60 50 "solid" "white")
(rectangle 30 50 "solid" "red"))
How do we make equations simpler?
(require 2htdp/image) ; make sure to have this line at the top, otherwise circle is undefined
;(above (circle 40 "solid" "red")
; (circle 40 "solid" "yellow")
; (circle 40 "solid" "green"))
; think of f(x) = 2 + x
; f(3) = 2 + x
(define (bulb c)
(circle 40 "solid" c))
(above (bulb "red")
(bulb "yellow")
(bulb "green"))
Another example:
(define (bulb c)
(circle 40 "solid" c))
(bulb (string-append "r" "ed"))
(bulb "red")
(circle 40 "solid" "red")
; 3 red bulbs should appear
Another Problem:
Make this equation less redundant:
(* 3.14 (sqr 3))
(* 3.14 (sqr 6))
(* 3.14 (sqr 2.5))
find more resources at oneclass.com
find more resources at oneclass.com
ferrari12 and 39375 others unlocked
23
CPSC 110 Full Course Notes
Verified Note
23 documents
Document Summary
A(cid:374)(cid:455)thi(cid:374)g that sta(cid:396)ts (cid:449)ith (cid:862);(cid:863) (cid:449)ill be regarded as notes that do not show up in drracket. ;; all values are expressions (+ 1 2) # thing that follows the parenthesis has to be the name of the function (+ (* 3 4) (+ 2 3)) ;; all values are expressions (+ (* 3 4) (+ 2 3)) (+ 12 (+ 2 3)) ;; evaluated to produce a result, in inside out left to right order. Example c = sqrt ( a^2 + b^2) (sqrt (+ (sqr 3) (sqr 4))) The(cid:396)e a(cid:396)e othe(cid:396) ki(cid:374)ds of (cid:448)alues: t(cid:396)i(cid:374)gs (cid:862)ha(cid:396)(cid:396)(cid:455)(cid:863) (cid:894)dou(cid:271)le (cid:395)uote follo(cid:449)ed (cid:271)(cid:455) (cid:449)hat (cid:455)ou (cid:449)a(cid:374)t followed by double quote) Takes the t(cid:449)o st(cid:396)i(cid:374)g a(cid:374)d (cid:272)o(cid:374)(cid:272)ate(cid:374)ates the(cid:373) = (cid:862)ha(cid:396)(cid:396)(cid:455)potte(cid:396)(cid:863) (cid:1007) optio(cid:374)s = (cid:862)ha(cid:396)(cid:396)(cid:455) (cid:862), (cid:862) potte(cid:396)(cid:863), (cid:862) (cid:862) f(3) = 2 + x. Images (require 2htdp/image) (cid:894)(cid:396)e(cid:272)ta(cid:374)gle (cid:1007)(cid:1004) 5(cid:1004) (cid:862)solid(cid:863) (cid:862)(cid:271)lue(cid:863)(cid:895)