Strings 2

One and two step string exercises.

Write each of these functions. Add at least one new check-expect of your own for each problem.

  1. Given a word with at least 3 letters, the tletter function gives the third letter.

     (check-expect (tletter "zebra") "b")
     (check-expect (tletter "stripe") "r")
    
  2. The wordshow function makes an image of a given string in 48 point black font.

     (wordshow "Chicken") =>
    

    Image of the word Chicken

  3. The winning-score : number -> image function takes in a number score and puts out an image the the following in 48 point black font.

    (winning-score 47) =>

    Output of (winning-score 47)

  4. Circular typing adds a new letter to the end of a string and at the same time removes a letter from the beginning, so the length stays the same.

     (check-expect (circular-type "dinosaur" "s") "inosaurs")
     (check-expect (circular-type "page" "d") "aged")
    
  5. The rletter function gives a random letter from the given word. Each appearance of a letter in the word is equally likely, so in “dad”, the “d” will be chosen twice as often as the “a”.

     (rletter "candy") => "c"
     (rletter "candy") => "y"
     (rletter "candy") => "a"
    
  6. Make an animation using a string model and some of the functions you wrote above. Use wordshow for the draw handler and circular-type for the key handler. Test it to make sure it works.

  7. Write a new mouse handler for your animation. The mouse handler selects a random letter from the string model, puts it on the end of the model, and removes the first letter so the length of the model stays the same.

    Example: Suppose that the original model is "candy" and the "a" is randomly selected. The new model would be "andya".