Answer to Question #191867 in C++ for Sivasurya

Question #191867

The teacher has fed up with the students making noise in the class room, so in order to make them quite, she thinks of a task - "Asks them to count the number of vowels in the name". So teachers said any one student name, and students have to tell the number of vowels in the name.


So, help the teacher by writing a program using functions to find the number of vowels in the name.


Input Format: Input consists of a string.


Output Format: Output consists of an integer saying the number of vowel in the given word.


Refer sample Input and Output for further specifications.


1
Expert's answer
2021-05-11T11:34:48-0400
#include <iostream>
#include <string>


using namespace std;




int getNumberVowels(string name) { 
	int numberVowels=0;
	string vowels = "AEIOUY";
	for (int i = 0; i < name.size(); i++){
		for (int j = 0; j < vowels.size(); j++)
		{
			if (toupper(name[i]) == vowels[j])
			{
				numberVowels++;
			}
		}
	}
	return numberVowels;
}


int main()
{
	string name;
	cout<<"Enter the student name: ";
	getline(cin,name);
	int numberVowels=getNumberVowels(name);
	cout<<"\nThe number of vowels in the name: "<<numberVowels<<"\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