String and File Assignment
Marks 30
1. Write a function that takes a string and returns the number
of capital letters in the string. Save
as str1.t (3 marks)
2. Write a program that reads from a file called story.dat(Doc Folders\Mackinnon\ICS 3M\String), replaces all occurrences of he
with he/she, and outputs to a file called story.out.
Save as str1.t (4 marks)
3. Write a function called rep that takes a string, and returns
a string. The initial string will have a number at the beginning. The result
will be the rest of the string repeated a number of times equal to the initial
number. Save as str1.t (4 marks)
Output
e.g. put rep("4you") youyouyouyou
4. Write a program that eliminates all spaces from a file. Your
program will ask for the file, open it then output to the screen. Save as
str1.t (4 marks)
5. Write a function called mirror that takes a string and
returns a string. The result will be the original string plus the string in
reverse. Save as str1.t (5 marks)
Result
e.g. mirror("them") themmeht
mirror("is") issi
6. Write a procedure called elim that
takes a string and a letter. The first string will change. In
place of all occurrences of the letter place an *. Save as str1.t (5
marks)
7. Write a boolean
function called palindrome that takes a string and results true if it is a
palindrome, or false if it is not. A palindrome is a word that is spelled the
same foward as it is backward. You are to ignore all
spacing, punctuation and case in your comparison. Save as str1.t (5 marks)
Result
e.g. palindrome(“Racecar”) true
palindrome(“Madam I’m Adam”) true
palindrome(“dog”) false