Ask Question

Write a program in C+ + that prompts the user to input a sequence of characters and outputs the number of vowels: Use the function we wrote in class that inputs a character and returns true (or 1) if the character is a vowel otherwise it returns a falsehere is what I have so far:

+5
Answers (1)
  1. 10 January, 09:36
    0
    The program to this question can be given as:

    Program:

    #include / /define header file

    #include

    //define header file

    using namespace std;

    //namespace std;

    bool search_Vowel (char cha) / /function definition.

    int main () / /main method.

    {

    int count=0, i; / /define variable.

    string value;

    value = "Enter a string value : ";

    cout<
    getline (cin, value); / /use getline function.

    for (i = 0; i
    {

    if (search_Vowel (value[i])) / /conditional statement.

    {

    count++; / /increase count.

    }

    }

    cout << "In the above string value, there are "<< count <<" vowels." <
    return 0;

    }

    Output:

    Enter a string value:

    hello ... ! my name is dev.

    In the above string value, there are 6 vowels.

    Explanation:

    The above program description can be given as below:

    In the C+ + program, firstly we define the header file. After defining the header file we define a function that is "search_Vowel () ". In this function, we pass a char variable that is "cha". The data type of this function is string because it returns a string value. In this function use OR logical operator that checks if any value in the condition is true so, It will return a value. Then we define the main () function in this function we define a variable that is "i, count and value". In which variable i use in the loop and count variable used for count vowels. The value variable is used for taking input from the user. For input, we use the getline () function. Then we define the for loop in this loop we use the conditional statement in if block we call the search_Vowel in which we pass the value variable. In the above program, the count variable prints the count of vowels.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Write a program in C+ + that prompts the user to input a sequence of characters and outputs the number of vowels: Use the function we wrote ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers