Recitation 6: Manipulating strings

 

Exercise 1.

Ask the user to type in a string. Print the string backwards.

 

Exercise 2.

Palindrome is a word that is the same when read backwards. Some examples are: ewe, anna, hannah, lonelytylenol.

Write a program that will read a string and print appropriately "This is a palindrome" or "This is not a palindrome"

 

Exercise 3.

Write a function FirstChar that uses two arguments - a string s and a char c and returns the position of the first occurrence of char c in the string s. Write a program that will test this function five times.

 

Exercise 4.

Write a function that will return the location of the first letter (i.e. 'a' through 'z' or 'A' through 'Z') in a string typed in by the user. Write a program that will test this function.

 

Exercise 5.

Write a function that will count the number of occurrences of a given character in a given string. Test this function.

 

Exercise 6.

Ask the user to type in a string. Print the first letter of every word in this string.

(Try it with the sentence: Your eyes seem so incredibly red.)

 

Exercise 7.

Write a program that will count the words in a string.

 

Exercise 8.

Write a program that will compute the average length of a word.

 

Exercise 9.

Write a program that will replace every occurrence of a space with a *.

 

Exercise 10.

Write a program that will replace every letter of a string with its successor.