Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ASSIGNMENT l09-f
- Student's Quest ID: s383yang
- **** Testing Results **********************************************************
- 25/25 Total Mark
- ** Question 2: 3/3
- ** Question 3: 5/5
- ** Question 4: 8/8
- ** Question 5: 9/9
- (Question 2, Test 01, 1 marks): Checking if (switch-case "") produces "":
- Passed
- (Question 2, Test 02, 1 marks): Checking if (switch-case "aBc") produces
- "AbC": Passed
- (Question 2, Test 03, 1 marks): Checking if (switch-case "cS115 is FUN!") pro-
- duces "Cs115 IS fun!": Passed
- (Question 3, Test 01, 1 marks): Checking if (longest-string-length (cons ""
- empty)) produces 0: Passed
- (Question 3, Test 02, 1 marks): Checking if (longest-string-length (cons "hi"
- (cons "a" empty))) produces 2: Passed
- (Question 3, Test 03, 1 marks): Checking if (longest-string-length (cons ""
- (cons "sad" (cons "unhappy" empty)))) produces 7: Passed
- (Question 3, Test 04, 1 marks): Checking if (longest-string-length empty) pro-
- duces 0: Passed
- (Question 3, Test 05, 1 marks): Checking if (longest-string-length (cons "dog"
- (cons "cat" (cons "lol" empty))) produces 3: Passed
- (Question 4, Test 1, 1 marks): Checking if (any-senior? empty) produces false:
- Passed
- (Question 4, Test 2, 1 marks): Checking if (any-senior? (list (list 'cat
- "Ziggy" 6) (list 'dog "Tucker" 1)
- (list 'cat "Max" 5) (list 'snake "Slytherin" 2))) produces false: Passed
- (Question 4, Test 3, 1 marks): Checking if (any-senior? (list (list 'cat
- "Ziggy" 6) (list 'dog "Tucker" 1)
- (list 'cat "Max" 5) (list 'snake "Slytherin" 12))) produces true: Passed
- (Question 4, Test 4, 1 marks): Checking if (any-senior? (list (list 'cat "Zig-
- gy" 8))) produces false: Passed
- (Question 4, Test 5, 1 marks): Checking if (any-senior? (list (list 'turtle
- "Clyde" 10))) produces true: Passed
- (Question 4, Test 6, 1 marks): Checking if (any-senior? (list (list 'dog
- "Tucker" 12))) produces true: Passed
- (Question 4, Test 7, 1 marks): Checking if (any-senior? (list (list 'cat
- "Ziggy" 6) (list 'dog "Tucker" 10)
- (list 'cat "Max" 15) (list 'snake "Slytherin" 12))) produces true: Passed
- (Question 4, Test 8, 1 marks): Checking if (any-senior? (list (list 'cat
- "Ziggy" 16) (list 'dog "Tucker" 10)
- (list 'cat "Max" 15) (list 'snake "Slytherin" 12))) produces true: Passed
- (Question 5, Test 1, 1 marks): Checking if (sort-points empty) produces empty:
- Passed
- (Question 5, Test 2, 1 marks): Checking if (sort-points (list (list 2 1) (list
- 0 0) (list 0 3) (list -2 4))) produces (list (list 0 0) (list -2 4) (list
- 0 3) (list 2 1)): Passed
- (Question 5, Test 3, 1 marks): Checking if (sort-points (list (list 1 2)))
- produces (list (list 1 2)): Passed
- (Question 5, Test 4, 1 marks): Checking if (sort-points (list (list 1 2) (list
- 6 -1))) produces (list (list 1 2) (list 6 -1)): Passed
- (Question 5, Test 5, 1 marks): Checking if (sort-points (list (list 0 1) (list
- -3 -2))) produces (list (list -3 -2) (list 0 1)): Passed
- (Question 5, Test 6, 1 marks): Checking if (sort-points (list (list 1 2) (list
- 0 3))) produces (list (list 0 3) (list 1 2)): Passed
- (Question 5, Test 7, 1 marks): Checking if (sort-points (list (list -1 2)
- (list 1 0) (list 2 -1) (list -2 1) (list 0 1))) produces (list (list -2 1)
- (list -1 2) (list 0 1) (list 1 0) (list 2 -1)): Passed
- (Question 5, Test 8, 1 marks): Checking if (sort-points (list (list 0 0) (list
- -4 0) (list 12 -4) (list 1 6)
- (list 10 10) (list -2 -1) (list -3 -2))) produces (list (list -3 -2) (list -4
- 0) (list -2 -1) (list 0 0)
- (list 1 6) (list 12 -4) (list 10 10)): Passed
- (Question 5, Test 9, 1 marks): Checking if (sort-points (list (list 0 0) (list
- -4 0) (list 12 -4) (list 1 0) (list 1 6)
- (list 10 10) (list 2 -1) (list -2 -1) (list -3 -2))) produces (list (list -3
- -2) (list -4 0) (list -2 -1) (list 0 0) (list 1 0) (list 2 -1)
- (list 1 6) (list 12 -4) (list 10 10)): Passed
- **** l09q2.rkt *****************************************************************
- ;; 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 l09q2) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f () #t)))
- ;; Q2
- (define (change char)
- (cond
- [(char-upper-case? char) (char-downcase char)]
- [(char-lower-case? char) (char-upcase char)]
- [else char]))
- (define (switch-case str)
- (list->string (map change (string->list str))))
- **** l09q3.rkt *****************************************************************
- ;; 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 l09q3) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f () #t)))
- ;; Q3
- (define (longest-string-length los)
- (foldr max 0 (map string-length los)))
- **** l09q4.rkt *****************************************************************
- ;; 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 l09q4) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f () #t)))
- ;; Q4
- ;; An Pet is a (list Sym Str Bool), where
- ;; * the first value is the type of animal
- ;; * the second value is the associated value.
- ;; * the third value is its age in years
- (define test (list (list 'cat "mimi" 6)
- (list 'cat "Duck" 1)
- (list 'dog "Taz" 0)))
- (define (greaterthan lst)
- (cond
- [(>= (third lst) 10) true]
- [else false]))
- (define (any-senior? buddies)
- (ormap greaterthan buddies))
- **** l09q5.rkt *****************************************************************
- ;; 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 l09q5) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f () #t)))
- ;; Q5
- ;; An Point is a (list Num Num), where
- ;; * the first value is the x-coordinate
- ;; * the second value is the y-coordinate
- (define test (list (list 2 1) (list 0 0)
- (list 0 3) (list -2 4)))
- (define (less-than? p1 p2)
- (or (< (+ (first p1) (second p1)) (+ (first p2) (second p2)))
- (and (= (+ (first p1) (second p1)) (+ (first p2) (second p2)))
- (< (first p1) (first p2)))))
- (define (sort-points pts)
- (sort pts less-than?))
- **** End of graded assignment. *************************************************
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement