Answer to Question #174185 in C++ for Harini.M

Question #174185


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


1
Expert's answer
2021-03-27T13:42:12-0400
#include <iostream>
#include <string>
#include <cctype>
using namespace std;


class Vowel{
private:
    string inputWords;
public:
    Vowel(){}
    //the constructor member function to assign the values
    Vowel(string inputWords){
        this->inputWords=inputWords;
    }
    //destructor member function to destroy the data objects.
    ~Vowel(){}
    int vowelCount(){
        int vowels=0;
        for(int i = 0; i < this->inputWords.length(); ++i){
            char letter=tolower(this->inputWords[i]);
            if(letter=='a' || letter=='e' || letter=='i' || letter=='o' || letter=='u')
            {
                ++vowels;
            }
        }
        return vowels;
    }
};


int main (){
    string inputWords;
    cout<<"Enter your words: ";
    getline(cin,inputWords);
    Vowel vowel(inputWords);
    cout<<"\nThe number of vowels present in the given string: "<<vowel.vowelCount()<<"\n\n";


    system("pause");
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS