Page 290 - Computer_Science_F5
P. 290
Output: Chapter Four: Object oriented programming with C++
FOR ONLINE READING ONLY
Figure 4.60: The program demonstrating the use of casting in C++
The following Program Example 4.32 will help you to learn how to write a program
that changes, letter case using built-in function. Follow the commands properly and
practice them. This will demonstrates a C++ program that changes letter case using
built-in function. The output is shown in Figure 4.61.
Program Example 4.32:
A C++ program to change letter case using built-in function
#include<iostream>
#include<cctype>
using namespace std;
int main()
{
char ch;
cout<<”Enter a character: “;
cin>>ch;
cout<<”You have entered: “<<ch<<endl;
cout<<endl;
if(islower(ch))
{
cout<<”It is lowercase letter “<<endl;
cout<<”Its equivalent uppercase letter is “<<static_cast<char>(toupper(ch))<<endl;
}
else if(isupper(ch))
{
cout<<”It is an uppercase letter “<<endl;
cout<<”Its equivalent lowercase letter is “<<static_cast<char>(tolower(ch))<<endl;
}
if(isdigit(ch))
{
cout<<”It is digit character “<<endl;
}
return 0;
}
281
Student’s Book Form Five
Computer Science Form 5.indd 281 23/07/2024 12:34

