In this short tutorial I would like to share with you a sample program in C++ that will ask the user to enter a sentence and then our program will count the number of occurrence of capital, small and digits in a given sentence in C++. The code is very short and easy to understand it uses while loop and one dimensional array in our program.
If you have some questions please send me an email at jakerpomperada@yahoo.com and jakerpomperada@gmail.com.
People here in the Philippines who wish to contact me can reach me at my mobile number 09173084360.
Sample Output of Our Program
Program Listing
#include <stdio.h>
#include <stdlib.h>
using namespace std;
int main() {
int upper = 0, lower = 0, digits=0;
char ch[120]; int i=0;
cout << "===========================================\n";
cout << " Capital, Small Letters and Digits Counter";
cout << "\n";
cout << "===========================================\n";
cout << "\n\n";
cout << "Enter A Sentence :=> ";
gets(ch);
while (ch[i] != '\0') {
if (ch[i] >= 'A' && ch[i] <= 'Z')
upper++;
if (ch[i] >= 'a' && ch[i] <= 'z')
lower++;
if (ch[i] >= '0' && ch[i] <= '9')
digits++;
i++;
}
cout <<"\n==============================";
cout << "\n";
cout << "======= Display Result ======= ";
cout << "\n==============================";
cout << "\n";
cout << "\n Number of Uppercase Letters : " << upper;
cout << "\n Number of Lowercase Letters : " << lower;
cout << "\n Number of Digits : " << digits;
cout << "\n\n";
system("pause");
}
DOWNLOAD SOURCE CODE HERE
No comments:
Post a Comment