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.
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
class Vowel{
private:
string inputString;
public:
Vowel(){}
//the constructor member function to assign the values
Vowel(string inputString){
this->inputString=inputString;
}
//destructor member function to destroy the data objects.
~Vowel(){}
int findNumberVowels(){
int vowels=0;
for(int i = 0; i < this->inputString.length(); ++i){
char letter=tolower(this->inputString[i]);
if(letter=='a' || letter=='e' || letter=='i' || letter=='o' || letter=='u')
{
++vowels;
}
}
return vowels;
}
};
int main (){
string inputString;
cout<<"Enter string: ";
getline(cin,inputString);
Vowel vowel(inputString);
cout<<"\nThe number of vowels present in the given string: "<<vowel.findNumberVowels()<<"\n\n";
system("pause");
return 0;
}
Comments
Leave a comment