C++ Examples

WAP in C++ Program to Count Number of unique characters of two given strings

The Program in C++ Program to Count Number of unique characters of two given strings is given below:

#include <iostream>
#include <string>
#include <set>

using namespace std;

int countUniqueCharacters(string str1, string str2)
{
    set<char> s;
    for (char c : str1) {
        s.insert(c);
    }
    for (char c : str2) {
        s.insert(c);
    }
    return s.size();
}

int main()
{
    string str1, str2;
    cout << "Hello Codeauri Family,Enter the first string here : ";
    getline(cin, str1);
    cout << "Hello Codeauri Family,Enter the Second string here: ";
    getline(cin, str2);

    cout << "Well, the Number of unique characters are: " << countUniqueCharacters(str1, str2) << endl;
    return 0;
}

Output:

Hello Codeauri Family,Enter the first string here : possibility
Hello Codeauri Family,Enter the Second string here: chances
Well, the Number of unique characters are: 13

Pro-Tips💡

This program uses the countUniqueCharacters function to count the number of unique characters of two given strings str1 and str2.

The function uses a set to store the unique characters and a loop to insert each character from both strings into the set.

The size of the set is then returned as the result.

The main function takes two input strings from the user and calls the countUniqueCharacters function to get the number of unique characters, then outputs the re

Learn C-Sharp ↗

C-sharp covers every topic to learn about C-Sharp thoroughly.

Learn C Programming ↗

C-Programming covers every topic to learn about C-Sharp thoroughly.

Learn C++ Programming↗

C++ covers every topic to learn about C-Sharp thoroughly.

Codeauri is Code Learning Hub and Community for every Coder to learn Coding by navigating Structurally from Basic Programming to Front-End Development, Back-End Development to Database, and many more.

Related Posts

C# Program to Find Sum of Rows & Columns of a Matrix

The Program in C# Program to Find Sum of Rows & Columns of a Matrix is given below: Output: Hello Codeauri Family,enter the number of rows and columns…

C# Program to Calculate Determinant of Given Matrix

The Program in C# Program to Calculate Determinant of Given Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns of the matrix…

C# Program to Find Sum of right Diagonals of a Matrix

The Program in C# Program to Find Sum of right Diagonals of a Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns…

C# Program to Find Transpose of Given Matrix

The Program in C# Program to Find Transpose of Given Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns in the matrix:22Enter…

C# Program for Multiplication of two square Matrices

The Program in C# Program for Multiplication of two square Matrices is given below: Output: Hello Codeauri Family, enter the number of rows/columns in the matrices:2Enter the elements…

C# Program to Delete Element at Desired position From Array

The Program in C# Program to Delete Element at Desired position From Array is given below: Output: Hello Codeauri Family, enter the number of elements in the array:4Enter…

Leave a Reply

Your email address will not be published. Required fields are marked *

Your Journey into Code Begins Now: Discover the Wonders of Basic Programming

X