+92 332 4229 857 99ProjectIdeas@Gmail.com

How to check whether a character is an alphabat, a small alphabat, a capital alphabat or a digit (C++ Tutorial)


Checking whether a character is an alphabat, a small alphabat, a capital alphabat or a digit
The below mentioned functions serve the purpose:
IsAlphabat() accepts a character and returns true if the character is an alphabat and retuns false if the character is not an alphabat.
The range of decimal value of an alphabat: 65-90 AND 97-122
IsAlphabatSmall() accepts a character and returns true if the character(alphabat) is small and returns false if the character is not small.
The range of decimal value of a small alphabat: 97-122
IsAlphabatCapital() accepts a character and returns true if the character(alphabat) is capital and returns false if the character is not capital.
The range of decimal value of a capital alphabat: 65-90
IsDigit() accepts a character and returns true if the character is a digit and retuns false if the character is not a digit.
The range of decimal value of a digit: 48-57


Example (C++)
#include "stdafx.h"
#include "iostream"
#include "conio.h"

using namespace std;

bool IsAlphabat( char ch )
{
      if ( ( ch >= 65 & ch <= 90 ) | ( ch >= 97 & ch <= 122 ) )
            return true;
      return false;
}

bool IsAlphabatSmall( char ch )
{
      if ( ch >= 97 & ch <= 122 )
            return true;
      return false;
}

bool IsAlphabatCapital( char ch)
{
      if ( ch >= 65 & ch <= 90 )
            return true;
      return false;
}

bool IsDigit( char ch )
{
      if ( ch >= 48 & ch <= 57 )
            return true;
      return false;
}

int main()
{
      cout << IsAlphabat('A') << endl;                //    1
      cout << IsAlphabatCapital('A') << endl;         //    1
      cout << IsAlphabatSmall('A') << endl;                 //    0
      cout << IsDigit('A') << endl;                   //    0

      cout << endl << endl;

      cout << IsAlphabat('a') << endl;                //    1
      cout << IsAlphabatCapital('a') << endl;         //    0
      cout << IsAlphabatSmall('a') << endl;                 //    1
      cout << IsDigit('a') << endl;                   //    0

      cout << endl << endl;

      cout << IsAlphabat('0') << endl;                //    0
      cout << IsAlphabatCapital('0') << endl;         //    0
      cout << IsAlphabatSmall('0') << endl;                 //    0
      cout << IsDigit('0') << endl;                   //    1
     
      _getche();
      return 0;
}

0 comments: