In C++ Write a function that converts an uppercase letter to lowercase. Use the
ID: 3696151 • Letter: I
Question
In C++
Write a function that converts an uppercase letter to lowercase. Use the following function header:
char toLowerCase(char ch)
If the character is not an uppercase letter, the method simply returns the character itself. For example, toLowerCase('B') returns b and toLowerCase('5') returns 5.
Write a test program that prompts the user to enter a character, invokes the function, and displays its return value.
<Output>
Enter a char: A
a
<End Output>
<Output>
Enter a char: 3
3
<End Output>
Explanation / Answer
#include <iostream>
#include <string>
using namespace std;
char toLowerCase(char ch)
{
putchar(tolower(ch));
cout<<endl;
cout<<"<End Output>";
}
int main()
{
char ch;
cout<<"<Output>"<<endl;
cout<<"Enter a char : ";
cin>>ch;
toLowerCase(ch);
return 0;
}
OUTPUT:
<Output>
Enter a char : D
d
<End Output>
<Output>
Enter a char : 6
6
<End Output>