Answer to Question #179181 in C++ for Ajith

Question #179181

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-04-08T17:19:50-0400
#include <string>
#include <iostream>
 
using namespace std;
 
class Vowel
{
public:
	Vowel(string data_);
	~Vowel();
	string GetData() { return data; }
	int GetCount() { return count; }
private:
	string data;
	int count;
};
 
Vowel::Vowel(string data_) : data(data_), count(0)
{
	string vow = "AEIOUYaeiouy";
	for (int i = 0; i < data.size(); i++)
	{
		for (int j = 0; j < vow.size(); j++)
		{
			if (data[i] == vow[j])
			{
				count++;
				break;
			}
		}
	}
}
 
Vowel::~Vowel()
{
}
 
int main()
{
	string temp;
	cout << "Enter new string: ";
	cin >> temp;
	Vowel myObj(temp);
	cout << myObj.GetData() << " contains " << myObj.GetCount() << " vowels." << endl;
	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