Question

C++ Write a recursive routine that will have a character array and an index as parameters...

C++
Write a recursive routine that will have a character array and an index as parameters and will return the count of all vowels (assume lowercase).
You may assume that the index starts out at the END of the array.

Homework Answers

Answer #1
#include <iostream>

using namespace std;

int count_vowels(char array[], int index);

int main() {
    char arr[] = {'H', 'e', 'l', 'l', 'O'};
    cout << count_vowels(arr, 4) << endl;
    return 0;
}

int count_vowels(char array[], int index) {
    if (index < 0) {
        return 0;
    } else {
        int count = count_vowels(array, index - 1);
        char ch = array[index];
        if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' || ch == 'A' || ch == 'E' || ch == 'I' ||
            ch == 'O' || ch == 'U')
            ++count;
        return count;
    }
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a recursive array that gives the min of an array C
Write a recursive array that gives the min of an array C
Write a c++ function which takes two parameters: an array of ints and an int size...
Write a c++ function which takes two parameters: an array of ints and an int size of the array and prints every element greater than 5 to the screen. You may assume that the parameters passed to the function are valid. Your function must have the following signature: void printSome(const int array[], int size);
C++ Write a program which accepts a character from the user. If the character is between...
C++ Write a program which accepts a character from the user. If the character is between 0 and 9, it will output that it's a digit. If the character is lowercase it will output that its a lowercase character. If it's an uppercase character it will output that it's uppercase. For all other cases it will output that it's neither a digit nor a letter. As an example of the output: Enter a digit or a letter: A You entered...
C++ Write a function that takes in 3 arguments: a sorted array, size of the array,...
C++ Write a function that takes in 3 arguments: a sorted array, size of the array, and an integer number. It should return the position where the integer value is found. In case the number does not exist in that array it should return the index where it should have been if it were present in this sorted array. Use pointer notation of arrays for this question. c++ code
Write a function in c using #include <stdio.h> that takes a one-dimensional integer array and returns...
Write a function in c using #include <stdio.h> that takes a one-dimensional integer array and returns the index of the first occurance of the smallest value in the array. Your function must be able to process all the elements in the array. Create a function prototype and function definition (after the main function). Your main function should declare a 100 element integer array. Prompt the user for the number of integers to enter and then prompt the user for each...
Write a recursive C++ function writeLine(ch,n) that writes a character repeatedly to form a line of...
Write a recursive C++ function writeLine(ch,n) that writes a character repeatedly to form a line of n characters. For example, writeLine('*', 5) produces the line *****. 2. Now write a iterative function writeBlock (ch,n,m) that uses writeLine(ch, n) to write m lines of n characters each. For example, writeBlock('*', 5, 3) produces the output ***** ***** ***** 3. provide a main() function for testing, if time and space allowed.
C++, Write an iterative routine that will have a queue and a loop to flip 2...
C++, Write an iterative routine that will have a queue and a loop to flip 2 coins: 0 for tails and 1 for heads. Add the values of the tosses of the two coins and put them onto the queue. Then dequeue the values one at a time and sum all the values. After the queue is empty, and print out the number of heads. Assume srand has already been done.
You may notice that the function strchr in the <cstring> library searches for a character within...
You may notice that the function strchr in the <cstring> library searches for a character within a string, and returns the memory address (pointer) to where that character first occurs. 1.) Write your own version of the strchr function, int findchr( char text[ ], char target) , which returns the index of the first occurrance of the character target if it occurs within the string text. If target does not occur within the string, a -1 is to be returned....
Write a function that returns the largest element of an array? Your function should accept a...
Write a function that returns the largest element of an array? Your function should accept a 1-D array as an input and return the largest number. You may assume all numbers are integers. CODE IN C++ PLEASE
1. Write a C++ program that implements the recursive function isMember as declared above. Pass an...
1. Write a C++ program that implements the recursive function isMember as declared above. Pass an array to the function by reference. Here are two sample runs of the program. The elements of the array are: 0 4 5 6 7 Enter the element you want to find: 6 Element is in the array Press any key to continue . . .
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT