Isupper Function In C++ - C++ Programming Tutorial
C++ Course / Functions / Isupper Function In C++

Isupper Function In C++

BLUF: Mastering Isupper Function In C++ is a critical step in becoming a proficient C++ developer. This lesson provides a deep dive into the syntax, performance considerations, and real-world applications of this concept.
Key Performance Insight: Isupper Function In C++

C++ is renowned for its efficiency. Learn how Isupper Function In C++ enables low-level control and high-performance computing in the tutorial below.

The core of the C++ coding language revolves around the principles of object-oriented programming (OOP). Due to its well-defined framework, individuals can easily grasp and create program constructs. Additionally, the succinct nature of functions in C++ ensures that the idea is easily comprehensible and can be implemented throughout an executing program.

One essential function in C++ is the isupper function, a pre-defined function that eliminates the need for extensive coding. By utilizing the isupper function, you can ascertain if a character or string consists of uppercase letters. In C++, uppercase letters from A to Z correspond to ASCII values between 65 and 90. It's important to note that the behavior of the isupper function is unspecified if the input character or string 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:

Example

Int isupper(int arg);

Now, we will discuss the implementation and syntax of the isupper function. Initially, we will specify an integer variable, followed by declaring the function using the isupper name. Subsequently, an integer parameter will be provided within the parentheses of the function.

Parameters:

There are the subsequent parameters in the isupper method. These include:

It is necessary to verify if the input string contains uppercase letters before converting it to an integer or reaching the end of the file.

Return Value:

If the input string or character value is in capital letters, the function will return 1; otherwise, it will return 0.

Example 1:

In this part, we will build a simple illustration of the C++ function isupper. Prior to writing code for the program, you will need a C++ Integrated Development Environment (IDE). Once the C++ compiler is up and running, we can proceed with developing the program.

We typically begin by integrating the fundamental program components once the compiler is initiated. These components are encapsulated within the C++ language modules. Instead of manually crafting the module with numerous lines of code, we can easily import them with a single line of code. The "#" symbol signals the compiler to load the module in advance, while the "include" directive is used to incorporate the module into the program.

Now, we will incorporate the "iostream" module to receive input from the user and display it back. Following the "iostream" module, we will introduce the module "#include cctype" to access character-related functions within the program. Subsequently, we have implemented the "using namespace std" directive to prevent the need for redundant references to objects, methods, and parameters within the program's scope.

Code:

Example

#include <iostream>

#include <cctype>

using namespace std;

int main()
{
    char ch = 'B';
    if (isupper(ch))
cout<<ch<<" is an uppercase letter";
    else
cout<<ch<<" is not an uppercase letter";
    return 0;
}

Output:

Output

B is an uppercase letter

Explanation:

In this instance, we will commence the primary function to implement the actual logic or issue of the program. Subsequently, proceed with coding by initiating the bracket of the main function. Next, we declare a variable of character type and initialize it with a character value. The character type variable is always enclosed in either single or double quotation marks. Following that, we have initiated the if-else statement to ascertain if the character variable represents an uppercase letter. This verification is achieved by incorporating the isupper function within the if-else block. The output is displayed using the cout function, which is a predefined method in the C++ language.

Returning zero to the main function signifies that the program executed successfully and accomplished its goal.

Example 02:

Let's start crafting the second illustration for the isupper function. Typically, we import the libraries connected to the program at the outset to access the functionalities within the current program. For example, when we aim to exhibit the program, we need to employ the cout function. Hence, we will utilize the "iostream" library to manage the input and output of program data. Subsequently, the character functionality within the program comes into play following the inclusion of an additional library. We will opt for the "cctype" library for this purpose. Following that, the "namespace std" directive will be implemented to prevent the repetition of names across the entire program.

Code:

Example

#include <iostream>
#include <cctype>

using namespace std;

int main ()
{
  char ch[20] = "JtP";
  int count = 0;
  int i = 0;

  while(ch[i])
  {
    if(isupper(ch[i]))
    count++;
i++;
  }

cout<<"Here in this " << count << " uppercase letters in "<<ch<< ".";  
  return 0;
}

Output:

Output

Here in this 2 uppercase letters in JtP.

Explanation:

In this instance, the program execution commences with the invocation of the main function. Subsequently, we define a character variable "ch" with a length of 20 and initialize it with the string "JtP". Additional integer variables, namely "count" and "i", are introduced with initial values of 0 assigned to both.

Following this, the while statement was utilized to iterate until the character "ch[i]" was no longer empty. We check if ch[i] represents an uppercase letter. If the initial character is uppercase, the count of uppercase letters in the string will increment by 1. The while loop terminates once "ch[i]" becomes empty. Subsequently, the cout function displays the total count of uppercase letters in the input string. Upon closing the main function's brace, we return 0 to signify the completion of the program's execution.

Conclusion

In this tutorial, we explored the usage of the isupper function in C++. This function is employed to identify uppercase letters within a string and to ascertain if the entire string consists of uppercase letters. Subsequently, we created several illustrative examples, providing detailed explanations for each line to enhance our understanding of the isupper function.

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience