Print the given 3 string after modifying and concatenating

Given three strings(without spaces). The task is to print the new string after modifying the three given string as follows:

  • Replace all the vowels present in the first string with “*”.
  • Don’t change anything in the second string.
  • Replace all the consonants in the third string with “$”.
  • Concatenate all of the three string to obtain the new string.


Input : how are you
Output : h*ware$ou

Input : geeks for geeks
Output : g**ksfor$ee$$

The idea is to traverse the first string and keep checking if any character is vowel or not. Replace the character in the first string which is vowel with “*”. Similarly, traverse the third string and keep checking if any character is not a vowel. If a character in the third string is not a vowel(then it is a consonant), replace it with ‘$’.

Finally, concatenate the three strings and print the newly concatenated string.





// CPP program to modify the given strings
#include <iostream>
#include <string.h>
using namespace std;
// Function to modify the given three strings
string modifyStr(string str1, string str2, string str3)
    // Modifying first string
    for (int i = 0; i < str1.length(); i++) {
        if (str1[i] == 'a' || str1[i] == 'e' || 
            str1[i] == 'i' || str1[i] == 'o' || 
            str1[i] == 'u')
            str1[i] = '*';
    // Modifying third string
    for (int i = 0; i < str3.length(); i++) {
        if (str3[i] != 'a' && str3[i] != 'e' && 
            str3[i] != 'i' && str3[i] != 'o' && 
            str3[i] != 'u')
            str3[i] = '$';
    // Concatenating the three strings
    return (str1 + str2 + str3);
// Driver code
int main()
    string str1 = "how";
    string str2 = "are";
    string str3 = "you";
    cout << modifyStr(str1, str2, str3);
    return 0;




My Personal Notes arrow_drop_up

If you like GeeksforGeeks and would like to contribute, you can also write an article using or mail your article to See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.