Lab 19

Strings and String Functions

CS211 Lab Policy:

Instructions:

Create one program named Lab19 that includes code to solve each of the following small problems.  Save your program in a file named Lab19.m. .

  1. Write code that gets two strings from the user and then tells the user whether the strings are: 1) identical including the case of all letters, 2) the same when letter case differences are ignored, or 3) different even when case differences are ignored.
     
  2. It is common to use the string processing functions to manipulate file names.

    Add code to Lab19() that gets a file name from the user.  If the entered file name does not contain any extension (it does not include a period), append the string '.m' to the end of the file name.  Then use the exist() function to check if the file exists in MATLAB's search path (check for a return value of 2).  If the file is found, display a message that tells the user that the file exists in the search path.  Otherwise, display a message saying the file does not exist in the search path.  In both cases, include the full file name in the message displayed to the user.
     
  3. A palindrome is a word or phrase that is spelled the same forwards or backwards (like "a", "bb", and "ma'am"). 
     
    1. Write a sub-function named Is_palindrome() with one string input argument and one logical output argument.  The function should return true if the input argument is a palindrome (ignoring case) and false otherwise.  Place this function after the end of function Lab19(). (Hint: look up the fliplr() MATLAB function using the help system.)
       
    2. Add code to Lab19() that gets a string from the user, calls your Is_palindrome() function and then reports whether or not the user-entered string is a palindrome (ignoring case). 
       
  4. Many clever long palindromes include spaces and punctuation marks which are ignored for the purposes of counting the text as a palindrome.  For example, "I prefer pi." and "A man, a plan, a canal - Panama!" are considered palindromes. 
     
    1. Write a subfunction named Just_letters with one input argument and one output argument.  The function should return the input string with all characters, except letters, removed.  For example, when called with the input argument string:

          'a man, a plan, a canal - panama!'

      the function Just_letters should return the string:

          'amanaplanacanalpanama'

      (Hint: You can write this operation with a single assignment statement using the isstrprop() function in combination with the find() function.)
       
    2. Add code to function Lab19() that is identical to your code for Part 3 above, but call Just_letters before calling Is_palindrome, so that spaces and punctuation marks are not considered when reporting whether or not the user input string is a palindrome.

Turn-in:

Submit your Lab19.m file.