Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.91 KB | None | 0 0
  1. ASSIGNMENT l09-f
  2. Student's Quest ID: s383yang
  3.  
  4. **** Testing Results **********************************************************
  5.  
  6. 25/25 Total Mark
  7.  
  8. ** Question 2: 3/3
  9. ** Question 3: 5/5
  10. ** Question 4: 8/8
  11. ** Question 5: 9/9
  12.  
  13. (Question 2, Test 01, 1 marks): Checking if (switch-case "") produces "":
  14. Passed
  15. (Question 2, Test 02, 1 marks): Checking if (switch-case "aBc") produces
  16. "AbC": Passed
  17. (Question 2, Test 03, 1 marks): Checking if (switch-case "cS115 is FUN!") pro-
  18. duces "Cs115 IS fun!": Passed
  19. (Question 3, Test 01, 1 marks): Checking if (longest-string-length (cons ""
  20. empty)) produces 0: Passed
  21. (Question 3, Test 02, 1 marks): Checking if (longest-string-length (cons "hi"
  22. (cons "a" empty))) produces 2: Passed
  23. (Question 3, Test 03, 1 marks): Checking if (longest-string-length (cons ""
  24. (cons "sad" (cons "unhappy" empty)))) produces 7: Passed
  25. (Question 3, Test 04, 1 marks): Checking if (longest-string-length empty) pro-
  26. duces 0: Passed
  27. (Question 3, Test 05, 1 marks): Checking if (longest-string-length (cons "dog"
  28. (cons "cat" (cons "lol" empty))) produces 3: Passed
  29. (Question 4, Test 1, 1 marks): Checking if (any-senior? empty) produces false:
  30. Passed
  31. (Question 4, Test 2, 1 marks): Checking if (any-senior? (list (list 'cat
  32. "Ziggy" 6) (list 'dog "Tucker" 1)
  33. (list 'cat "Max" 5) (list 'snake "Slytherin" 2))) produces false: Passed
  34. (Question 4, Test 3, 1 marks): Checking if (any-senior? (list (list 'cat
  35. "Ziggy" 6) (list 'dog "Tucker" 1)
  36. (list 'cat "Max" 5) (list 'snake "Slytherin" 12))) produces true: Passed
  37. (Question 4, Test 4, 1 marks): Checking if (any-senior? (list (list 'cat "Zig-
  38. gy" 8))) produces false: Passed
  39. (Question 4, Test 5, 1 marks): Checking if (any-senior? (list (list 'turtle
  40. "Clyde" 10))) produces true: Passed
  41. (Question 4, Test 6, 1 marks): Checking if (any-senior? (list (list 'dog
  42. "Tucker" 12))) produces true: Passed
  43. (Question 4, Test 7, 1 marks): Checking if (any-senior? (list (list 'cat
  44. "Ziggy" 6) (list 'dog "Tucker" 10)
  45. (list 'cat "Max" 15) (list 'snake "Slytherin" 12))) produces true: Passed
  46. (Question 4, Test 8, 1 marks): Checking if (any-senior? (list (list 'cat
  47. "Ziggy" 16) (list 'dog "Tucker" 10)
  48. (list 'cat "Max" 15) (list 'snake "Slytherin" 12))) produces true: Passed
  49. (Question 5, Test 1, 1 marks): Checking if (sort-points empty) produces empty:
  50. Passed
  51. (Question 5, Test 2, 1 marks): Checking if (sort-points (list (list 2 1) (list
  52. 0 0) (list 0 3) (list -2 4))) produces (list (list 0 0) (list -2 4) (list
  53. 0 3) (list 2 1)): Passed
  54. (Question 5, Test 3, 1 marks): Checking if (sort-points (list (list 1 2)))
  55. produces (list (list 1 2)): Passed
  56. (Question 5, Test 4, 1 marks): Checking if (sort-points (list (list 1 2) (list
  57. 6 -1))) produces (list (list 1 2) (list 6 -1)): Passed
  58. (Question 5, Test 5, 1 marks): Checking if (sort-points (list (list 0 1) (list
  59. -3 -2))) produces (list (list -3 -2) (list 0 1)): Passed
  60. (Question 5, Test 6, 1 marks): Checking if (sort-points (list (list 1 2) (list
  61. 0 3))) produces (list (list 0 3) (list 1 2)): Passed
  62. (Question 5, Test 7, 1 marks): Checking if (sort-points (list (list -1 2)
  63. (list 1 0) (list 2 -1) (list -2 1) (list 0 1))) produces (list (list -2 1)
  64. (list -1 2) (list 0 1) (list 1 0) (list 2 -1)): Passed
  65. (Question 5, Test 8, 1 marks): Checking if (sort-points (list (list 0 0) (list
  66. -4 0) (list 12 -4) (list 1 6)
  67. (list 10 10) (list -2 -1) (list -3 -2))) produces (list (list -3 -2) (list -4
  68. 0) (list -2 -1) (list 0 0)
  69. (list 1 6) (list 12 -4) (list 10 10)): Passed
  70. (Question 5, Test 9, 1 marks): Checking if (sort-points (list (list 0 0) (list
  71. -4 0) (list 12 -4) (list 1 0) (list 1 6)
  72. (list 10 10) (list 2 -1) (list -2 -1) (list -3 -2))) produces (list (list -3
  73. -2) (list -4 0) (list -2 -1) (list 0 0) (list 1 0) (list 2 -1)
  74. (list 1 6) (list 12 -4) (list 10 10)): Passed
  75.  
  76.  
  77. **** l09q2.rkt *****************************************************************
  78. ;; The first three lines of this file were inserted by DrRacket. They record metadata
  79. ;; about the language level of this file in a form that our tools can easily process.
  80. #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)))
  81. ;; Q2
  82. (define (change char)
  83. (cond
  84. [(char-upper-case? char) (char-downcase char)]
  85. [(char-lower-case? char) (char-upcase char)]
  86. [else char]))
  87.  
  88. (define (switch-case str)
  89. (list->string (map change (string->list str))))
  90.  
  91. **** l09q3.rkt *****************************************************************
  92. ;; The first three lines of this file were inserted by DrRacket. They record metadata
  93. ;; about the language level of this file in a form that our tools can easily process.
  94. #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)))
  95. ;; Q3
  96.  
  97. (define (longest-string-length los)
  98. (foldr max 0 (map string-length los)))
  99.  
  100. **** l09q4.rkt *****************************************************************
  101. ;; The first three lines of this file were inserted by DrRacket. They record metadata
  102. ;; about the language level of this file in a form that our tools can easily process.
  103. #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)))
  104. ;; Q4
  105.  
  106. ;; An Pet is a (list Sym Str Bool), where
  107. ;; * the first value is the type of animal
  108. ;; * the second value is the associated value.
  109. ;; * the third value is its age in years
  110.  
  111. (define test (list (list 'cat "mimi" 6)
  112. (list 'cat "Duck" 1)
  113. (list 'dog "Taz" 0)))
  114.  
  115. (define (greaterthan lst)
  116. (cond
  117. [(>= (third lst) 10) true]
  118. [else false]))
  119.  
  120. (define (any-senior? buddies)
  121. (ormap greaterthan buddies))
  122.  
  123. **** l09q5.rkt *****************************************************************
  124. ;; The first three lines of this file were inserted by DrRacket. They record metadata
  125. ;; about the language level of this file in a form that our tools can easily process.
  126. #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)))
  127. ;; Q5
  128.  
  129. ;; An Point is a (list Num Num), where
  130. ;; * the first value is the x-coordinate
  131. ;; * the second value is the y-coordinate
  132.  
  133. (define test (list (list 2 1) (list 0 0)
  134. (list 0 3) (list -2 4)))
  135.  
  136. (define (less-than? p1 p2)
  137. (or (< (+ (first p1) (second p1)) (+ (first p2) (second p2)))
  138. (and (= (+ (first p1) (second p1)) (+ (first p2) (second p2)))
  139. (< (first p1) (first p2)))))
  140.  
  141. (define (sort-points pts)
  142. (sort pts less-than?))
  143.  
  144. **** End of graded assignment. *************************************************
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement