Assignment 5
Up Assignment 1 Assignment 2 Assignment 3 Assignment 4 Assignment 5 Assignment 6 Assignment 7 Assignment 8 Assignment 9 Assignment 10

 

Arrays

Due: Tuesday, Oct 16, 5:00 PM

 

  1. Do Exercise 7.1 in the "Special Section: Recursion Exercises" section of Chapter 7.  Write your program as a Windows Application in which the user types a string into a TextBox and presses a Button to see if it is a palindrome.
    Hints:
    1. Think recursively!  There are two base cases: a string of length 0 and a string of length 1.  In the recursive case, a string of length n>1 is a palindrome iff the first character is equal to the last, and the inner string (i.e. ignoring the first and last characters) is a palindrome.
    2. Convert the user input (of type string) into a character array (of type char[]), and index into this array to look at any given character in the string.  A string s may be converted into a character array like this:
          char[] a = s.ToCharArray();
      So if s == "hello", then a[0] == 'h', a[1] == 'e', and so on.
    3. The only care you need to take in the above is that the problem statement says to ignore spaces and punctuation.  Write a method "isValid" that takes a char argument and returns the bool "true" if it is not a blank character (i.e. '  ') or punctuation (which we can define as a period, comma, semi-colon, colon, or apostrophe), and "false" otherwise.  Your main recursive method will need to call this method as it examines each character.