|
|
|
|
|
|
|
// Precondition:
// All parameters are assigned
// Postcondition:
// upperCount, lowerCount, digitCount, blankCount, puncCount,
// and leftOverCount have been summed, and the percentage of
// the sum for each counter (except leftOverCount) has been
// output
{
int total; // Total number of characters in the file
total = upperCount + lowerCount + digitCount +
blankCount + puncCount + leftOverCount;
cout << Percent that are uppercase letters:
<< float(upperCount) / float(total) * 100.0 << endl;
cout << Percent that are lowercase letters:
<< float(lowerCount) / float(total) * 100.0 << endl;
cout << Percent that are decimal digits:
<< float(digitCount) / float(total) * 100.0 << endl;
cout << Percent that are blanks:
<< float(blankCount) / float(total) * 100.0 << endl;
cout << Percent that are end-of-sentence punctuation:
<< float(puncCount) / float(total) * 100.0 << endl;
} |
|
|
|
|
|
|
|
|
Testing: To be tested thoroughly, the CategoryCount program must be run with all possible combinations of the categories of characters being counted. Listed below is the minimum set of cases that must be tested. |
|
|
|
|
|
|
|
|
1. All the categories of characters are present. |
|
|
|
|
|
|
|
|
2. Four of the categories are present; one is not. (This alone requires five test runs.) |
|
|
|
|
|
|
|
|
3. Only characters that fall into one of the five categories are present. |
|
|
|
|
|
|
|
|
4. Other characters are present. |
|
|
|
|
|
|
|
|
The percentages listed below came from a sample run of the program on a large text file. To save space, we show only the percentages, not the echo print of the input. |
|
|
|
|
|
|
|
|
Percent that are uppercase letters: 2.05
Percent that are lowercase letters: 82.32
Percent that are decimal digits: 0.05
Percent that are blanks: 7.03
Percent that are end-of-sentence punctuation: 1.27 |
|
|
|
|
|