Question

In: Computer Science

Write a program that prompts the user to input a string. The program then uses the...

Write a program that prompts the user to input a string. The program then uses the function substr to remove all the vowels from the string. For example, if str=”There”, then after removing all the vowels, str=”Thr”. After removing all the vowels, output the string. Your program must contain a function to remove all the vowels and a function to determine whether a character is a vowel.

You must insert the following comments at the beginning of your program and write our commands in the middle:

Write a C++ Program:

/*

// Name: Your Name

// ID: Your ID

// Purpose Statement:~~~

*/

#include <iostream>

#include <string>

using namespace std;

void removeVowels(string& str);

bool isVowel(char ch);

int main()

{

    string str;

    cout << "Enter a string: ";

    …

    …

         YOUR CODE HERE

    …

    …

return 0;

}

void removeVowels(string& str)

{

    int len = str.length();

    …

    …

         YOUR CODE HERE

    …

    …

}

bool isVowel(char ch)

{

    switch (ch)

    …

    …

         YOUR CODE HERE

    …

    …

}

Solutions

Expert Solution

Hi There, I have included the code snippet.Please let me know if you have any doubts.

#include <iostream>
#include <string>
#include <bits/stdc++.h> 

using namespace std;
string removeVowels(string str);
bool isVowel(char ch);

int main(){
    string strr;
    cout << "Enter a string: ";
    cin>>strr;
    cout<<removeVowels(strr)<<endl;
return 0;
}

// this function will remove vowels
string removeVowels(string str){ 
    int len = str.length();
    vector<char> vowels = {'a', 'e', 'i', 'o', 'u', 
                           'A', 'E', 'I', 'O', 'U'}; 
      
    for (int i = 0; i < len; i++)  
    { 
        if (find(vowels.begin(), vowels.end(), 
                      str[i]) != vowels.end())  
        { 
            str = str.replace(i, 1, ""); 
            i -= 2; 
        } 
    } 
    return str; 
} 
// this function will tell if a char is vowel or not.
bool isVowel(char ch){
    if(ch=='a' || ch=='e' || ch=='i' ||
                ch=='o' || ch=='u' || ch=='A' ||
                ch=='E' || ch=='I' || ch=='O' ||
                ch=='U'){
                    cout<<ch<<" is a vowel."<<endl;
                }
    else{
        cout<<ch<<" is a consonant."<<endl;
    }
return 0;
}

Related Solutions

Write a C++ Program Write a program that prompts the user to input a string. The...
Write a C++ Program Write a program that prompts the user to input a string. The program then uses the function substr to remove all the vowels from the string. For example, if str=”There”, then after removing all the vowels, str=”Thr”. After removing all the vowels, output the string. Your program must contain a function to remove all the vowels and a function to determine whether a character is a vowel. You must insert the following comments at the beginning...
Write a Python program which prompts the user to input a string. Then, print the string...
Write a Python program which prompts the user to input a string. Then, print the string in reverse to the terminal Sample output Please enter a word: "zeus" The reverse of zeus is suez Hint: There are several ways to accomplish this. Recall that a string is an itterable object and therefore can be used with a for loop
Write a Java program that prompts the user to input a word (String). The program must...
Write a Java program that prompts the user to input a word (String). The program must print the reversed word with all consecutive duplicate characters removed. The program must contain the following classes: - The StackX class (you can use the Java Stack class). - The Reverse class which must contain a private data field called “word” of type string, a constructor, and a void method called revNoDup(). The revNoDup() method must reverse the word and remove the consecutive duplicate...
Write a Java program that prompts the user to input a string and prints whether it...
Write a Java program that prompts the user to input a string and prints whether it is a palindrome. A palindrome is a string which reads the same backward as forward, such as Madam (disregarding punctuation and the distinction between uppercase and lowercase letters). The program must use the stack data structure. The program must include the following classes: The StackX class (or you can use the Java Stack class). The Palindrome class which must contain a method named palindrome()...
⦁   Write a Bash script that prompts for user input and reads a string of text...
⦁   Write a Bash script that prompts for user input and reads a string of text from the user. If the user enters a no null (no empty) string, the script should prompt the user to re-enter again the string; otherwise should display the string entered “. ⦁   Given an array of the following four integers (3, 5, 13, 14); write a Bash script to display the second and all elements in the array.    ⦁   Write a short Bas...
Write a MIPS assembly program that prompts the user first for a string, then for a...
Write a MIPS assembly program that prompts the user first for a string, then for a character. The program should then search the string for the character and print out the number of times the character appears in the string. You can use as many restrictions as you want, just be sure to list them. You must allocate space in the .data segment of your program for the user string.
JAVA: Write a program that prompts the user to input a type of medication and the...
JAVA: Write a program that prompts the user to input a type of medication and the output will be a list of side effects that can occur from that medication.
Write a program in c++ that prompts the user to input a coin collection of number...
Write a program in c++ that prompts the user to input a coin collection of number of quarters, dimes, nickels and pennies. The program should then convert the coin collection into currency value as dollars. The coin values should all be whole numbers and the resulting currency value should be displayed with two decimals. An example of user interaction is as follows: Coin Convertor Enter number of quarters: 3 Enter number of dimes: 1 Enter number of nickels: 4 Enter...
Write a program that prompts the user to input their first name from the keyboard and...
Write a program that prompts the user to input their first name from the keyboard and stores them in the variable "firstName". It does the same for last name and stores it in the variable "lastName". It then uses strcat to merge the two names, separates them by a space and stores the full name into a string variable called "fullName". In the end, the program must print out the string stored within fullName. ANSWER IN C LANGUAGE ! You...
Write a program that prompts the user to input a decimal number and outputs the number...
Write a program that prompts the user to input a decimal number and outputs the number rounded to the nearest integer.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT