The example in this article describes how to count the number of uppercase and lowercase letters, numbers, spaces, and other characters in C + + statistics. Share to everyone for your reference, specific as follows:
* * Author: Liu Tongbin * Completion date: November 28, 2012 * Version number: v1.0 * Input Description: * Problem Description: There is an article, there are three lines of text, each line has 80 characters.
The number of capitals, lowercase letters, numbers, spaces, and other characters in English are counted.
* Program Output: * Problem analysis: slightly * algorithm design: Slightly * * #include <iostream> using namespace std;
int main () {int i,j,upper,lower,digit,space,other;
Char text[3][80];
upper=lower=digit=space=other=0;
for (i=0;i<3;i++) {cout<<, please enter the "<<i+1<<" line: "<<endl; Gets (Text[i]);
What's the situation?
for (j=0;j<80&&text[i][j]!= '; j +] {if (text[i][j]>= ' A ' &&text[i][j]<= ' Z ') {
upper++;
else if (text[i][j]>= ' 0 ' &&text[i][j]<= ' 9 ') {digit++;
else if (text[i][j]>= ' a ' &&text[i][j]<= ' Z ') {lower++;
else if (text[i][j]= ') {space++;
else {other++; The number of uppercase letters in}} cout<< is: "<<upper<<endl <<" The lowercase number is: "<<lower<<endl << "Number of numbers is:" <<digit<<endl << "number of spaces:" <<space<<endl << "the number of other characters are:" <<
other<<endl;
return 0;
}
The screenshot of the running effect is as follows:
I hope this article will help you with C + + program design.