C++ program that would create display and count words,vowel and digits present in a file

So are u searching for a c++ based program that would work on the properties of files,you have visited the right place. This is a program that works on the switch case property which handles a set of data in the file simultaneously. Through this program we shall learn how to use the different functions of a file like opening closing or updating it. A very helpfull program to learn about a file in dept. This is a c++ based program that would help in creating a file in the first switch option means it will give you an option of writing text documents in the file. The second switch option is to count the number of vowels or words or digits present in the text presently written in a pre created file. The vowels, words or digits are encountered with the help of "if" case once they are encoutered these are stored in a seperate variable and displayed seperately. The third switch option is to display contents present in the file. This was all about the program so without wasting much time lets start with the program. The disscused program is as follows:
#include<fstream.h>
#include<stdio.h>
#include<conio.h>
#include<ctype.h>
#include<process.h>
void main()
{
clrscr();
int n,j;
fstream ofile,afile;
char str[100];
char ch,ch1;

do
{
cout<<"\n\t1.Create Text\n\t2.Count vowels/words/digits\n\t3.Show Text\n\t4.Exit";
cin>>ch;
switch(ch)
{
    case '1' :
ofile.open("smp.txt",ios::out);
cout<<"\n Enter The Text ";
gets(str);
ofile<<str;
ofile.close();
break;
    case '2' :
char tmp1;
int v=0,d=0,w=0;
afile.open("smp.txt",ios::in);
while(!afile.eof())
{
afile.get(tmp1);

if(tmp1=='a'||tmp1=='e'||tmp1=='i'||tmp1=='o'||tmp1=='u')
v++;
if(isdigit(tmp1))
d++;
if(tmp1==' '||tmp1=='.')
w++;

}
afile.close();
cout<<"\n No of Vowels: "<<v;
cout<<"\n No of digits: "<<d+1;
cout<<"\n No of words: "<<w;
break;
    case '3' :
char tmp2;
afile.open("smp.txt",ios::in);
ofile.open("spl.txt",ios::out);
while(!afile.eof())
{
afile.get(tmp2);
if(tmp2==' ')
{
ofile<<'#';
}
else
{
ofile<<tmp2;
}
}
afile.close();
ofile.close();

cout<<"\nFormatted text:\t";
afile.open("spl.txt",ios::in);
while(afile)
{
afile.get(ch);
cout<<ch;
}
afile.close();
break;
    case '4' : exit(0);
}
cout<<"\n\t DO U want to continue ";
cin>>ch1;
  }while(ch1=='Y'||ch1=='y');
getch();
}

Share this

Related Posts

Previous
« Prev Post