Question #174151

Design the class Vowel to find the number of vowels present in the given string. Define the constructor member function to assign the values and destructor member function to destroy the data objects.


Expert's answer

class Vowel
{
public:
    Vowel(string str) : s(str) {}
    
    ~Vowel() {}
    
    int Count()
    {
        int vowels = 0;
        for (int i = 0; i < s.length(); ++i)
        {
            switch (s[i])
            {
                case 'a':
                case 'e':
                case 'i':
                case 'o':
                case 'u':
                case 'y':
                    ++vowels;
                    break;
            }
        }
        return vowels;
    }
    
private:
    string s;
}
LATEST TUTORIALS
APPROVED BY CLIENTS