This is a C programing assignment Problem 2 write a c progra
This is a C++ programing assignment
Problem 2. write a c++ program which will take a filename from the command line and count the vowels contained therein. For the purposes of this problem, the vowels are a, e, i, o, u, and their uppercase equivalents. Choose your own files for testing. The graders will choose theirs, too.
Hint: if you declare a string
string vowels = \"aAeEiIoOuU\";
then the function call vowels.find(ch) will return a non-null pointer if ch is a vowel.
Solution
#include<iostream>
Using namespace std;
// Function to count the number of vowels.
void calculate()
{
fstream tfile;
clrscr();
tfile.open(\"file.TXT\", ios::in);
char arr[80];
char ch;
int i=0, sum=0, n=0;
while(tfile)
{
tfile.get(ch);
arr[i] = ch;
i++;
if (ch == \'a\' || ch == \'A\' || ch == \'e\' || ch == \'E\' || ch == \'i\' || ch == \'I\' || ch == \'o\' || ch == \'O\' ||
ch == \'u\' || ch == \'U\' )
{
i--;
sum = sum + i;
i = 0;
n++;
}
}
cout << \"Total no. of vowels : \" << n;
}
void main()
{
clrscr();
calculate();
getch();
}
