Strings 1

A hands-on introduction to Racket’s string functions.

Write each of these functions. Include at least one check-expect that you write (in addition to mine).

  1. The function numage: number -> image takes in an integer and makes an image of that number in a purple 36 point font.

  2. The function first-five: string -> string gives the first five letters of the word.

     (check-expect (first-five "kangaroo") "kanga")
    
  3. The function chop-five: string -> string removes the first five letters of the word. It gives an error if the word does not have 5 letters.

     (check-expect (chop-five "kangaroo") "roo")
    
  4. The function tripl takes in a word and puts out the word three times, all stuck together.

     (check-expect (tripl "six") "sixsixsix")
    
  5. The function lendub : string -> number puts out a number that is twice as much as the number of characters in the string.

     (check-expect (lendub "six") 6)
     (check-expect (lendub "kangaroo") 16)
     (check-expect (lendub "8") 2)  ;; note: one character in "8"
    
  6. The function cupper : number(n) string -> number gives the length of the string, except the largest value that is output is n.

     (check-expect (cupper 3 "azure") 3)
     (check-expect (cupper 10 "azure") 5)
     (check-expect (cupper 5 "five") 4)
    
  7. The function fake-add : string string -> number adds two integers that are written as strings.

     (check-expect (fake-add "30" "20") 50)
     (check-expect (fake-add "5" "300") 305)
    
  8. The function add-prob: number number -> string produces a string for an addition math problem.

     (check-expect (add-prob 4 16) "4+16=20")
     (check-expect (add-prob 200 3) "200+3=203")
    
Last modified November 9, 2023: String exercises. (9811c0c)