Write a function in a C++ to count the number of vowels present in a text file “NOTES.TXT”.

void countVowels()
{
ifstream fin(“NOTES.TXT”);
char ch;
int count=0;
while(!fin.eof())
{
fin.get(ch);
if (isalpha(ch))
{
switch(ch)
{
case 'a': case 'A': case 'e':                                        case 'E': case 'o': case 'O':
                                case 'u': case 'U': case 'i': 
                                case 'I':
count++;
break;
}
}
}
fin.close();
cout<<"There are "<<count<<" vowels in NOTES.TXT file.";
}

void main()
{
countVowels();
}




No comments

Post your comments

Powered by Blogger.