Thursday, 5 July 2018

Prog 8 Data File Handling Program to store input in a text file and store words starting with vowels


//Program to store input in a text file and store words starting with vowels
//in another file
#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("File3.txt",ios::out);
                fout1<<str;
                fout1.close();

                fin1.open("File3.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 File3.txt:\n";
                cout<<".......................\n\n";

                fin1.open("File3.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