This C++ Program which changes the case of the given alphabetical character. The program takes a character as an input and exits if the given character is not an alphabet. The case of the given alphabet is changed on the basis of whether the case of given alphabet is lowercase or uppercase.
Here is source code of the C++ program which changes the case of the given alphabetical character. The C++ program is successfully compiled and run on a Linux system. The program output is also shown below.
/*
* C++ Program to Change the Case of given Alphabetical Character
*/
#include<iostream>
#include<cctype>
using namespace std;
int main()
{
char c;
cout << "Enter the character : ";
cin >> c;
if (!isalpha(c))
cout << c << " is not an alphabetical character." << endl;
else
{
int case_val;
if (c >= 'a' && c <= 'z')
{
c = c - 'a' + 'A';
case_val = 1;
}
else if (c >= 'A' || c <= 'Z')
{
c = c + 'a' - 'A';
case_val = 0;
}
cout << c << " is the " << ( (case_val == 1) ? "upper" : "lower" )
<< " case of given character " << endl;
}
}
$ g++ main.cpp $ ./a.out Enter the character : a A is the upper case of given character $ ./a.out Enter the character : A a is the lower case of given characte
Sanfoundry Global Education & Learning Series – 1000 C++ Programs.
advertisement
advertisement
If you wish to look at all C++ Programming examples, go to C++ Programs.
If you find any mistake above, kindly email to [email protected]Related Posts:
- Check C++ Books
- Practice Programming MCQs
- Practice Computer Science MCQs
- Apply for C++ Internship
- Check Computer Science Books