Methods for the number of uppercase and lowercase letters, numbers, spaces, and other characters in C + + statistics _c language

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.