Write a C++ program to count all the vowels in a given string

  • برمجة سي بلس بلس
  • برمجة

Write a C++ program to count all the vowels in a given string

Sample Output:

Original string: eagerer, number of vowels -> 4

Original string: eaglets, number of vowels -> 3

Original string: w3resource, number of vowels -> 4

الأجوبة

#include <iostream>

using namespace std;

int Vowel_Count(string text) {
  int ctr = 0;
  for(int i = 0; i < int(text.size()); i++){
    if (text[i] == 'a' || text[i] == 'e' || text[i] == 'i' || text[i] == 'o' || text[i] == 'u')
      ++ctr;
    if (text[i] == 'A' || text[i] == 'E' || text[i] == 'I' || text[i] == 'O' || text[i] == 'U')
      ++ctr;
  }
  return ctr;

}

int main() {
        cout << "Original string: eagerer, number of vowels -> " << Vowel_Count("eagerer") << endl;
        cout << "\nOriginal string: eaglets, number of vowels -> " << Vowel_Count("eaglets") << endl;
        cout << "\nOriginal string: w3resource, number of vowels -> " << Vowel_Count("w3resource") << endl;
        cout << "\nOriginal string: After eagling the Road Hole on Thursday, he missed an 8-footer for birdie Friday., number of vowels -> ";
		cout << Vowel_Count("After eagling the Road Hole on Thursday, he missed an 8-footer for birdie Friday.") << endl;
        return 0;
}
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...