Thursday, March 30, 2017

C plus plus program to change case of an alphabet without using library function.

All characters on the keyboard are given their own ASCII values. The list of ASCII values can be found at.ASCII Values

As we can see the ASCII values of the lower case alphabets and the upper case alphabets are different. The following a program which will convert any characters entered into its other case, that is if the entered character is lower case it will convert it to corresponding upper case and vice versa.

The ascii values of lower and upper case alphabets differt by a value of 32.



To find if the character is lower or upper case :

If the ASCII value of the entered alphabets lies between 65 and 90, its an upper case alphabet and we need to add 32 to get the corresponding lower case ASCII.



If the ASCII value of the entered alphabets lies between 97 and 122, its a lower case alphabet and we need to subtract 32 to get the corresponding upper case ASCII.



For any other ASCII values, it would not be an alphabet and there is no conversion needed.

The above steps are implemented in the function change_case function in the following program.



Save the program as change_case.cpp, compile and execute.


No comments:

Post a Comment