Working with characters Write a C program which accepts a li
Working with characters:
Write a C++ program which accepts a line of text entered by the user. The whole message
must not be stored in the program – instead, it must be read a character at a time, and as
each character is read certain properties of the character observed and remembered for
later reporting. After the text is read in, the user must be given a choice of these
options:
1. Display length of message
2. Display numbers of each vowel (upper and lower case counted together)
3. Display numbers of upper and lower case letters
4. Quit
The result of the user’s selection must be displayed, and the menu repeated, until 4 for
Quit is chosen.
Requirements:
1. Read in the text entered by user using cin.get in a loop something like this:
do
{
cin.get(current_symbol);
// check properties of current_symbol and add up various counts as
//needed here...
} while (current_symbol != ’\ ’);
Note: The purpose of using cin.get(current symbol); rather than cin >> current symbol;
is so that spaces will not be skipped over, but rather treated just like any other character.
2. If an empty message is entered, the user should be prompted to enter a non-empty
message until they enter one which is at least 1 character long. (Any character that is
not a ’\ ’ would count, even a space.)
3. In counting the numbers of vowels, both upper and lower case letters should be
counted together (e.g. for “Edible egg” the count for e should be 3).
4. Use comments to show the main steps in the program, and to document variable
declarations.
5. A sample run of your program should look like:
Enter a message: Eucalyptus is evergreen.
Available choices:
1. Display length of message
2. Display numbers of vowels
3. Display numbers of upper and lower case letters
4. Quit
Enter the number of your choice: 2
Vowel counts:
A’s: 1, E’s: 5, I’s: 1, O’s: 0, U’s: 2
Enter the number of your choice: 1
Your message contained 24 character(s).
Available choices:
1. Display length of message
2. Display numbers of vowels
3. Display numbers of upper and lower case letters
4. Quit
Enter the number of your choice: 3
Number of letters: upper case 1, lower case 20.
Available choices:
1. Display length of message
2. Display numbers of vowels
3. Display numbers of upper and lower case letters
4. Quit
Enter the number of your choice: 4
Solution
#include<stdio.h>
int main() {
int upper = 0, lower = 0;
char ch[80];
int i;
printf(\"\ Enter The String : \");
gets(ch);
i = 0;
while (ch[i] != \'\') {
if (ch[i] >= \'A\' && ch[i] <= \'Z\')
upper++;
if (ch[i] >= \'a\' && ch[i] <= \'z\')
lower++;
i++;
}
printf(\"\ Uppercase Letters : %d\", upper);
printf(\"\ Lowercase Letters : %d\", lower);


