Computer Science and Programming

Rowan University
Prof. Gregory Safko

Lab 5

Assigned: February 24, 2003

Due February 26, 2003

 


1. Letters (letters.cpp)

Write a function isLetter that accepts an argument of type char and returns a bool value. The function should return true if the character is a letter ('A' through 'Z', and 'a' through 'z'), false otherwise.

Hint: remember that the #include file <cctype> contains some useful functions. Open it up (it's full name is cctype.h), and snoop through it. Is there a function in there that can help you determine if the character is a letter or not?

 

Write a suitable main program to demonstrate your function, similar to the following:

(User input is underlined here for illustration only.)

 

Please enter a character: M
M is a letter
Press any key to continue


Please enter a character: $
$ is not a letter
Press any key to continue


The prototype should look like  bool isLetter(char a);

 


2. Consonants (cons.cpp)

Write a function isConsonant that accepts an argument of type char and returns a bool value. The function should return true if the character is a consonant (i.e. not a vowel), false otherwise.

Write a suitable main program to demonstrate your function similar to the following: 

(User input is underlined here for illustration only.)

 

Please enter a character: M
M is a consonant
Press any key to continue


Please enter a character: e
e is not a consonant
Press any key to continue


Please enter a character: 7
7 is not a consonant
Press any key to continue


 

The prototype should look like  bool isConsonant(char a);

You are permitted to use the functions isLetter and isVowel (from your previous assignments)


3. Find a vowel in a string (findvowl.cpp)

Write a function foundVowel that accepts an argument of type string and returns a int value. The function should return the position of the first vowel found in the string, otherwise it should return something numeric that says it wasn't found.

Write a suitable main program to demonstrate your function similar to the following: 

(User input is underlined here for illustration only.)

 

Please enter a string: Hello, World
The first occurrence of a vowel is found at position 1
Press any key to continue


Please enter a string: Ouch
The first occurrence of a vowel is found at position 0
Press any key to continue


Please enter a string: Rhythm
A vowel is not found in this string
Press any key to continue


Hint: You should construct your foundVowel function so that it returns something that lets you know that a vowel was not found in the string (perhaps a -1 ?) 


 

Back to the main course page