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>
using namespace std;
class Vowel
{
private:
string inputString;
public:
// the constructor member function to assign the value
Vowel(string inputString){
this->inputString=inputString;
}
//destructor
~Vowel(){}
int getNumberVowels() {
int numberVowels=0;
string vowels = "AEIOUY";
for (int i = 0; i < this->inputString.size(); i++){
for (int j = 0; j < vowels.size(); j++)
{
if (toupper(this->inputString[i]) == vowels[j])
{
numberVowels++;
}
}
}
return numberVowels;
}
};
int main()
{
string inputString;
cout<<"Enter the string: ";
getline(cin,inputString);
Vowel vowel(inputString);
cout<<"\nThe number of vowels present in the given string: "<<vowel.getNumberVowels()<<"\n\n";
system("pause");
return 0;
}
Comments
Leave a comment