(Searching for Characters) Write a program based on the program of Exercise 22.25 that inputs several lines of text and uses function strchr to determine the total number of occurrences of each letter of the alphabet in the text. Uppercase and lowercase letters should be counted together. Store the totals for each letter in an array, and print the values in tabular format after the totals have
been determined.
What will be an ideal response?
```
#include
#include
#include
#include
using namespace std;
const int SIZE1 = 80;
const int SIZE2 = 26;
int main()
{
char text[ 3 ][ SIZE1 ];
char *searchPtr;
int characters[ SIZE2 ] = { 0 };
cout << "Enter three lines of text:\n";
for ( int i = 0; i <= 2; i++ )
cin.getline( &text[ i ][ 0 ], SIZE1 );
// convert letters to lowercase
for ( int k = 0; k <= 2; k++ )
for ( int j = 0; text[ k ][ j ] != '\0'; j++ )
{
char c = static_cast< char >( tolower( text[ k ][ j ] ) );
text[ k ][ j ] = c;
} // end for
// run through the alphabet
for ( int q = 0; q < SIZE2; q++ )
{
for ( int j = 0; j <= 2; j++ )
{
searchPtr = &text[ j ][ 0 ];
while ( searchPtr = strchr( searchPtr, 'a' + q ) )
{
characters[ q ]++; // increment each time the character occurs
searchPtr++;
} // end while
} // end inner for
} // end outer for
cout << "\nThe total number of occurrences of each character:\n";
for ( int w = 0; w < SIZE2; w++ )
cout << setw( 3 ) << static_cast< char >( 'a' + w ) << ':'
<< setw( 3 ) << characters[ w ] << '\n';
return 0;
} // end main
```
Enter three lines of text:
The first line of text
The second line of text
The third line of text
The total number of occurrences of each character:
a: 0
b: 0
You might also like to view...
Carefully define mutator and accessor functions of a class.
What will be an ideal response?
A ________ enables individuals to select from a list but does not enable individuals to type anything that is not in the list
A) multivalue field B) list box C) combo box D) control type
For each file that a program uses, a distinct ____ must be created.
A. path mode B. I/O stream object C. transmission path D. file stream object
What are the templates available using the Data Collector Sets tool, and what does each template do?
What will be an ideal response?