/*
Write a C++ Program to create a text file "File1.txt" and store the input details as given below. Create another file "File2.txt" to store the words starting with vowels. Display the contents of both the files
with number of vowels
A generator simplifies creation of iterators .
It generates a sequence of values, one at a time .
It can take parameters like a function .
Then yields a value instead of returning a value .
It looks like a function but behaves like an iterator .
Which can be invoked like a function .
*/
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<fstream.h>
void main()
{ int count=0;
clrscr();
cout<<"\n\t\t\ *************************************************\n";
getch();
clrscr();
cout<<"-----------------------------------------------------";
cout<<"\nPROGRAM TO STORE CONTENTS IN A TEXT FILE AND";
cout<<"\nSTORE WORDS STARTING WITH VOWELS IN ANOTHER FILE.";
cout<<"\n---------------------------------------------------\n";
getch();
char str[500]="A generator simplifies creation of iterators .\nIt generates a sequence of values, one at a time .\nIt can take parameters like a function .\nThen yields a value instead of returning a value .\nIt looks like a function but behaves like an iterator .\nWhich can be invoked like a function .";
ifstream fin1,fin2;
ofstream fout1,fout2;
fout1.open("File1.txt",ios::out);
fout1<<str;
fout1.close();
fin1.open("File1.txt",ios::in);
fout2.open("File2.txt",ios::out);
while(!fin1.eof())
{
fin1>>str;
if(str[0]=='a'||str[0]=='A'||str[0]=='e'||str[0]=='E'||str[0]=='i'||str[0]=='I'||str[0]=='o'||str[0]=='O'||str[0]=='u'||str[0]=='U')
{
fout2<<str<<" "; count++;
}
}
fin1.close();
fout2.close();
clrscr();
cout<<"Contents of File1.txt:\n";
cout<<".......................\n\n";
fin1.open("File1.txt",ios::in);
while(!fin1.eof())
{
fin1.getline(str,81,'\n'); cout<<str<<endl<<endl;
}
fin1.close();
cout<<"\n\nContents of File2.txt (words starting with vowels):"<<endl;
cout<<".......................................................\n\n";
fin2.open("File2.txt",ios::in);
while(!fin2.eof())
{
fin2>>str; cout<<str<<" ";
} cout<<"\nNo. of words:"<<count;
fin2.close();
getch();
}
Output:
.
No comments:
Post a Comment