Question

In: Computer Science

-> > Use recursion to write a C++ function for determining if a strings has more...

-> > Use recursion to write a C++ function for determining if a strings has more vowels than consonants. Please include the pseudo code so that I can understand better with simple English as much as possible.

Solutions

Expert Solution

Program is easy to understand. Also output is attached as image.

#include<iostream>
using namespace std; 
// Function to check a character for Vowel
bool isVowel(char ch)
{
    // To handle lower case 
    ch = toupper(ch);
    return (ch=='A' || ch=='E' || ch=='I' || ch=='O' || ch=='U');
}

//Function to count total number of vowels
int countVovels(string s, int n)
{
    if (n == 1){return isVowel(s[n-1]);}
    return countVovels(s, n-1) + isVowel(s[n-1]); 
}
bool isConsonant(char ch) 
{ 
    ch = toupper(ch); 
    return !(ch == 'A' || ch == 'E' ||  
            ch == 'I' || ch == 'O' ||  
            ch == 'U') && ch >= 65 && ch <= 90; 
} 
int totalConsonants(string str, int n) 
{ 
    if (n == 1) 
        return isConsonant(str[0]); 
  
    return totalConsonants(str, n - 1) +  
           isConsonant(str[n-1]); 
} 
int main()
{
    string s = "pqwerdtub";
    int v=countVovels(s, s.length());
    int c=totalConsonants(s, s.length());

    cout <<"Total No. of Vowels-"<<v<< endl;
    cout <<"Total No. of Consonants-"<<c<< endl;

    if(v>c){cout<<"No. of Vowels are more than the No. of Consonants."<<endl;}
    else{cout<<"No. of Vowels are not more than the No. of Consonants."<<endl;} 
    return 0;

}

Related Solutions

Lab #3 – Recursion on Strings Lab Objectives • Be able to write a recursive Java...
Lab #3 – Recursion on Strings Lab Objectives • Be able to write a recursive Java method for Java strings • Be able to make use of exploit natural conversion between strings and integers • Be able to write a driver to call the methods developed for testing Deliverables Submit the report in Word or PDF format with the results of every task listed below. They should show screen capture of your results. The problem String as a sequence of...
C++ only Write a function decimalToBinaryRecursive that converts a decimal value to binary using recursion. This...
C++ only Write a function decimalToBinaryRecursive that converts a decimal value to binary using recursion. This function takes a single parameter, a non-negative integer, and returns a string corresponding to the binary representation of the given value. Your function should be named decimalToBinaryRecursive Your function should take a single argument An integer to be converted to binary Your function should not print anything Your function should use recursion instead of a loop. Note that if you try to use a...
Python3 *Use Recursion* Write a function called smallest_sum(A,L) where A is the value and L is...
Python3 *Use Recursion* Write a function called smallest_sum(A,L) where A is the value and L is a list of ints. smallest_sum should return the length of the smallest combinations of L that add up to A if there are no possible combinations then float("inf") is returned. Examples smallest_sum(5, [2, 3]) == 2 smallest_sum(313, [7, 24, 42]) == 10 smallest_sum(13, [8, 3, 9, 6]) == float(‘‘inf’’) No Loops and map/reduce functions are allowed
Use recursion function to derive computation time for Binary Search by drawing a recursion tree diagram...
Use recursion function to derive computation time for Binary Search by drawing a recursion tree diagram and using algebra calculation.
C++ Recursion, Change the delete_node function in the header file to a recursive delete_node function, main...
C++ Recursion, Change the delete_node function in the header file to a recursive delete_node function, main is already set. Hint: It might be helpful to modify the function so that it uses a separate recursive function to perform whatever processing is needed. //////////////////////////////////////////////////////////////header.h////////////////////////////////////////////////////////////////////////////////////////////// #ifndef HEADER_H_ #define HEADER_H_ #include <iostream> using namespace std; template <class T> class LL { private:    struct LLnode    {        LLnode* fwdPtr;        T theData;    };    LLnode* head; public:    LL();...
Please, use C++ for this question. (b) Write the definition of displayBox() function. The function will...
Please, use C++ for this question. (b) Write the definition of displayBox() function. The function will display a matrix of integers from 1 to 4 such that the first row will contain four 1s, the second row will contain four 2s, the third row will contain four 3s and the fourth row will contain four 4s. Function must use nested loops to display each column and row heading as well as the numbers. The function has no parameters and no...
Write a function to concatenate two strings using pointer notation
Write a function to concatenate two strings using pointer notation
How to rewrite the bin() function below using recursion instead of a for loop in C?...
How to rewrite the bin() function below using recursion instead of a for loop in C? #include <stdio.h> #include <stdlib.h> #include <math.h> #include <stdint.h> char* bin(int x, int i); int main(int argc, char **argv) { char* binstr = bin(10, 0); printf("%s\n", binstr); free(binstr); return 0; } char* bin(int x, int i){ int bits = log10((double) x)/log10(2)+1; char* ret = malloc((bits+1)*sizeof(char)); for(int i = 0; i < bits; i++){ ret[bits-i-1] = (x & 1) ? '1' : '0'; x >>= 1;...
In this programming assignment, you will write C code that performs recursion. For the purpose of...
In this programming assignment, you will write C code that performs recursion. For the purpose of this assignment, you will keep all functions in a single source file main.c. Your main job is to write a recursive function that generates and prints all possible password combinations using characters in an array. In your main() function you will first parse the command line arguments. You can assume that the arguments will always be provided in the correct format. Remember that the...
In this programming assignment, you will write C code that performs recursion. For the purpose of...
In this programming assignment, you will write C code that performs recursion. For the purpose of this assignment, you will keep all functions in a single source file main.c. Your main job is to write a recursive function that generates and prints all possible password combinations using characters in an array. In your main() function you will first parse the command line arguments. You can assume that the arguments will always be provided in the correct format. Remember that the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT