Exercises 7
Comments and questions to John Rowe.
These exercises are assessed. In all cases
hand in your code and the printout of the final
result.
The aim is to gain experience of messing around with text. As
always, you may use any example functions in the lecture notes but you
should make sure you understand what they are doing. Notice that when
we say "write a function to .." that is what we mean!!
- Inside main() declare two character
arrays (which can be used used to store modifiable strings)
of the same length.
- Write a simple menu function to return one of a number
of choices. Add each of the folowing choices one at a time,
make sure each is working correctly before starting on the next.
For each choice have a separate function called from main()
to perform the action. Have the whole "menu and perform the action"
code inside an infinite loop.
Each option, except quit, will involve reading in a string.
For simplicity use strings without spaces but use the underscore
character '_' instead of a space.
- Menu options:
- Quit the program.
- Print out the number of upper case letters in the string.
- Safely copy the first string to the second, and
in the copied string replace each character that is neither a letter
or a number with a star "*".
- See if the string contains the substring "wobble".
- See if the string is alphbetically before, after or the same as
string "bobble".
- Safely set the second string to be:
"You entered: " followed by the original string, for example:
"You entered: hello, world".
In each case by "safely" we mean to only copy as much of the string
as can be safely held in the destination. Make sure you
provide some output showing that it does work safely.
- Now modify your code so that when you read in a character
string it then gets modified to replace every underscore with
a space.
How convenient is this for the user? [Not very!]. We will
see another approach next week.