Hands-on 3a

Strings

Start code: session3-start.tar.gz

  • Download the start code and unpack it in your working area (directory Project):
$ tar xzvf session3-start.tar.gz
  • Inspect, compile and run the program palindrome.cxx.

  • Check that it works on simple example.

  • Copy it as a second version palindrome_sentence.cxx and modify it that will not check word palindrome, but sentence palindrome itself: such as

    • « A man, a plan, a canal : Panama. »
    • « Pull up if I pull up. »
    • « Sums are not set as a test on Erasmus. »
  • Hints:

    • Use std::getline() function to read the whole input sentence

    • In order to be able to use the given function (IsPalindrom), reduce the sentence to a word: remove all non alphabetical characters: spaces, punctuation, etc.

    • Comparing strings and characters is case sensitive (a != A); std::tolower() function can be used to change all letters in the sentence to lower case

      #include <string>
      
      char letter1 = 'A';
      char letter2 = tolower(letter1);