Write a Program to concatenate strings in C++

Here we will write a simple program to Concatenate Strings in C++ without using any library functions. Let’s follow the simple approach below: Input 2 strings. Go to end of one string and add second after it. put NULL ” at the end of the string. Let’s write the C++ code for the same. Checkout … Read more

Program to find frequency of characters in a string C++

Finding frequency of characters in a string C++ is like:

Let the string is: I am Software engineer

The Frequency if character ‘e’ in this String is: 4

Program to find frequency of characters in a string C++

CODE:

#include <iostream>
#include <cstring>
using namespace std;

int main()
{
    char c[30],ch;
    int i,count=0;
    cout << "Enter a string: ";
    cin.getline(c, 1000);
    cout << "Enter a character to find frequency: ";
    cin >> ch;
    for(i=0;c[i]!='';++i)
    {
        if(ch==c[i])
        count++;
    }
    cout << "Frequency of " << ch << " = " << count;
    return 0;
}

 

OUTPUT:

frequency of characters in a string c++

Program to convert String to Uppercase C++

Write a Program to convert string to Uppercase C++.

PROGRAM:

#include<iostream>
using namespace std;

int main( )
{

    char str[80];
    cout<<"Enter a string:";
    gets(str);

    for(int i=0;str[i]!='';i++)
        str[i] = (str[i]>='a' && str[i]<='z')?(str[i]-32):str[i];
    cout<<str;

    return 0;
}

 

OUTPUT:

convert string to uppercase c++

Program to convert string to lowercase c++

Write a Program to convert string to lowercase C++ without using library function tolower( ).

PROGRAM:

#include<iostream>
using namespace std;

int main( )
{

    char str[80];
    cout<<"Enter a string:";
    gets(str);

    for(int i=0;str[i]!='';i++)
        str[i] = (str[i]>='A' && str[i]<='Z')?(str[i]+32):str[i];

    cout<<str;


    return 0;
}

 

OUTPUT:

convert string to lowercase c++