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