C++ program to find the number of vowels in a text file
Answers
Answered by
1
We will make a C++ program which will create a function named calculate( ) which wil calculate the number of vowels in a text file named “para.txt”
Below is the program which will use file handling concept. Here we will create a C++ program using function. This function will calculate the number of vowels in a text file "para.txt". The coding to implement above features can be given as :
------------------------
#include
#include
#include
#include
// Function to count the number of vowels.
void calculate()
{
fstream tfile;
clrscr();
tfile.open("PARA.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();
}
---------------------
Below is the program which will use file handling concept. Here we will create a C++ program using function. This function will calculate the number of vowels in a text file "para.txt". The coding to implement above features can be given as :
------------------------
#include
#include
#include
#include
// Function to count the number of vowels.
void calculate()
{
fstream tfile;
clrscr();
tfile.open("PARA.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();
}
---------------------
Answered by
0
this could be the proper answer
Attachments:
Similar questions