Program to enter a poem and calculate number of vowel and consonants in string
Monday, March 02, 2020//program to enter a poem and to calculate number of vowel and consonants
#include<fstream.h>
#include<conio.h>
#include<process.h>
#include<ctype.h>
#include<string.h>
#include<stdio.h>
void main()
{ clrscr();
char ch[100],charc,charw[10];
int count1=0,count2=0;
ofstream ofile;
ofile.open("POEM.TXT",ios::out);
if(!ofile)
{ cout<<"\n File can't be open";
exit(1);
}
cout<<"\n Enter the poem:";
gets(ch);
ofile<<ch;
ofile.close();
ifstream ifile, ifile1;
ifile.open("POEM.TXT",ios::in);
if(!ifile)
{ cout<<"\n File can not read";
exit(1);
}
while(ifile>>charc)
{ charc=toupper(charc);
if(charc=='A'||charc=='E'||charc=='I'||charc=='O'||charc=='U')
count1++;
}
cout<<"\n Number of vowel="<<count1;
ifile.close();
ifile1.open("POEM.TXT",ios::in);
if(!ifile1)
{ cout<<"\n File can not read";
exit(1);
}
while(ifile1)
{ ifile1>>charw;
if(strcmpi(charw,"the")==0)
count2++;
}
cout<<"\n Number of 'the'="<<count2;
ifile1.close();
getch();
}
#include<fstream.h>
#include<conio.h>
#include<process.h>
#include<ctype.h>
#include<string.h>
#include<stdio.h>
void main()
{ clrscr();
char ch[100],charc,charw[10];
int count1=0,count2=0;
ofstream ofile;
ofile.open("POEM.TXT",ios::out);
if(!ofile)
{ cout<<"\n File can't be open";
exit(1);
}
cout<<"\n Enter the poem:";
gets(ch);
ofile<<ch;
ofile.close();
ifstream ifile, ifile1;
ifile.open("POEM.TXT",ios::in);
if(!ifile)
{ cout<<"\n File can not read";
exit(1);
}
while(ifile>>charc)
{ charc=toupper(charc);
if(charc=='A'||charc=='E'||charc=='I'||charc=='O'||charc=='U')
count1++;
}
cout<<"\n Number of vowel="<<count1;
ifile.close();
ifile1.open("POEM.TXT",ios::in);
if(!ifile1)
{ cout<<"\n File can not read";
exit(1);
}
while(ifile1)
{ ifile1>>charw;
if(strcmpi(charw,"the")==0)
count2++;
}
cout<<"\n Number of 'the'="<<count2;
ifile1.close();
getch();
}
0 Comments