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

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();...
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...
Make a function in C that allows for the user to enter in 2 separate strings....
Make a function in C that allows for the user to enter in 2 separate strings. The first string that is entered is then made equal to the second string, but any duplicate characters (the same character appearing twice or more in a row) should only be copied once to the output string. Lastly the function displays how many duplicate characters were found.
Write a program in C++ that will make changes in the list of strings by modifying...
Write a program in C++ that will make changes in the list of strings by modifying its last element. Your program should have two functions: 1. To change the last element in the list in place. That means, without taking the last element from the list and inserting a new element with the new value. 2. To compare, you need also to write a second function that will change the last element in the list by removing it first, and...
/*Use recursion in the function: void getDigit( int num) /* Try this program and implement the...
/*Use recursion in the function: void getDigit( int num) /* Try this program and implement the function void getDigit( intnum) so that it displays the digits in a given number. For example, the number, 1234 consist of 1, 2, 3 and 4. This is an exercise to demonstate the use of a recursive function and the use of recusrion in C++ */ #include #include using namespace std; int main() {      int num;      cout <<"Enter an integer: ";     ...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT