isupper() function in C++The foundation of the C++ programming language is based on the concepts of object-oriented programming (OOP). Because C++ offers a clear structure, the user can develop and understand the program's concepts with ease. Furthermore, as functions are compact pieces of code, the concept has been made clear in C++ so that it can be used anywhere in a running program. One of the crucial C++ functions is the isupper() function, which is also predefined, saving us from having to write a large number of lines to implement it. You can use the isupper() method to determine whether a string or character is in upper-case letters or not. The capital letters from A to Z have ASCII values ranging from 65 to 90 in C++. The behavior of the isupper() function is undefinable if the input string or character value cannot be represented as an unsigned char or if it is not at the EOF (End of File). Syntax:It has the following syntax: Let's now talk about the isupper() function's implementation and writing style. First, we will take an integer type, after which we will write the isupper() function's name. After that, we will pass an integer-type parameter inside the function braces. Parameters:There are the following parameters in isupper() function. These are as follows: arg: It is the input string value or character value that needs to be checked for upper-case letters before being cast to an int or reaching the end of the file. Return Value:If the input string or character value is in uppercase letters, we will receive 1 in return, and else we will receive 0. Example 1:In this section, we'll construct the most basic example of the C++ function isupper(). A C++ IDE is required before we can begin coding to create and run the program. We will start implementing the program after launching the C++ compiler. We always start by incorporating the core program modules after starting the compiler. These modules are bundled in the C++ language modules. We simply need to type one line of code to include these modules instead of dozens of lines of code to construct the module. The "#" indicator informs the translator to load the module first before using the phrase "include" to add the module to the program. Now, we will take the module "iostream" to accept user data and show it to the user. After the "isostrem" module, we'll include the second module "#include cctype" in the program because we need to use the character function in the existing program. After that, we used the "using namespace std" directive to avoid objects, methods, and parameters from repeatedly referencing the same scope throughout the entire program. Code: Output: B is an uppercase letter Explanation: In this example, we will begin the main function to implement the program's true logic or problem. After that, write the code by launching the main() function bracket. Now, we contain the character type variable declaration and the character value's initialisation. Single or double quotation marks are always used to store the character type variable. After that, we have begun the if-else statement to determine whether the character variable is in an upper-case letter or not. We did so by including the isupper() method in the if-else. We printed the output using the cout() method. The predefined method in the C++ language is called cout(). Returning 0 to the main function indicates that the program ran effectively and achieved its objective. Example 02:Let's begin composing the isupper() function's second example. We normally include the modules that are linked to the program initially to use the operations in the existing program. For instance, if we want to display the program, we must use the cout() declaration. Therefore, we will utilise the "iostream" package to input and output program data. After that, the character function in the program is used after adding one more module. We will make use of the "cctype" module for that. After that, the "namespace std" directive will be used to avoid using the same name throughout the entire program. Code: Output: Here in this 2 uppercase letters in JtP. Explanation: In this example, the actual program code will be started by launching the main() method. After that, we declare the character type variable "ch" with a size of 20 and a value of the string "JtP". We have added two more integer-type variables, "count" and "i", and we have set 0 in each of them. After that, the while loop was employed to continue until the character string "ch[i]" was not null. We determine whether or not ch[i] is an upper-case string. If the first character is an uppercase character, the string will increase by 1. The compiler ends the while loop when the character string "ch[i]" is null. Afterwards, the cout() method publishes the input character string's total amount of upper-case letters. After closing the bracket around the main() method, we will return 0 to it to signal the end of the program's execution. ConclusionIn this article, we learnt how to utilize the isupper() function of the C++ language, which is used to determine how many letters are in upper case letters and whether the input string is in upper case letters or not. After that, we also constructed some examples, explaining each line as we wanted to learn more about the isupper() method. Next Topicnpos in C++ |