Users Online
· Guests Online: 152
· Members Online: 0
· Total Members: 188
· Newest Member: meenachowdary055
· Members Online: 0
· Total Members: 188
· Newest Member: meenachowdary055
Forum Threads
Newest Threads
No Threads created
Hottest Threads
No Threads created
Latest Articles
Articles Hierarchy
C# Program to Convert Characters of a String to Opposite Case
C# Program to Convert Characters of a String to Opposite Case
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
Comments
No Comments have been Posted.
Post Comment
Please Login to Post a Comment.