Pages

Menu driven C++ program for writing, reading a file and writing vowels in another file

#include<fstream.h>
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<process.h>
#include<ctype.h>
void main()
{
   clrscr();
   int n,choice, flag;
   fstream file1,file2;
   char str[256];
   char ch;
   do
   {
      clrscr();
      cout<<"\n---MENU---\n1.Write text to the first file"
   <<"\n2.Read text from first file\n3.Write vowels to the second file"
   <<"\n4.Display the second file\n5.Exit";
      cout<<"\nEnter your choice : ";
      cin>>choice;
      switch(choice)
      {
  case 1: file1.open("smp1.txt",ios::out);
   cout<<"\nEnter the text : ";
   gets(str);
   file1<<str;
   file1.close();
   cout<<"\nFile1 Created successfully";
   break;
  case 2: file1.open("smp1.txt",ios::in);
   while(file1)
   {
      file1.get(ch);
      cout<<ch;
   }
   file1.close();
   break;
  case 3: file1.open("smp1.txt",ios::in);
   file2.open("smp2.txt",ios::out);
   while(file1.eof()==0)
   {
      file1.get(ch);
      if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u'||ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U')
         file2.put(ch);
   }
   file1.close();
   file2.close();
   cout<<"\nFile 2 is created with vowels from File 1";
   break;
  case 4: file2.open("smp2.txt",ios::in);
   cout<<"\nLower case vowels : ";
   flag=0;
   while(file2)
   {
      file2.get(ch);
      if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')
      {
         cout<<ch;
         flag=1;
      }
   }
   if(flag==0)
      cout<<"\nNo lower case vowels";
   cout<<"\nUpper case vowels : ";
   flag=0;
   file2.close();
   file2.open("smp2.txt",ios::in);
   while(file2)
   {
      file2.get(ch);
      if(ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U')
         {
     cout<<ch;
     flag=1;
         }
   }
   if(flag==0)
      cout<<"\nNo upper case vowels";
   break;
  case 5: exit(0);
 default: cout<<"\nWrong choice!!!";
   break;
      }
      cout<<"\nPress any key to continue";
      getch();
     } while(1);
    }


5 comments:

  1. This blog is really great.This site is very helpful and informational : click here

    ReplyDelete
  2. Great blog.you put Good stuff.All the topics were explained briefly.so quickly understand for me.I am waiting for your next fantastic blog.Thanks for sharing.Any coures related details learn...

    Java Training in Bangalore|

    ReplyDelete
  3. I simply wanted to write down a quick word to say thanks to you for those wonderful tips and hints you are showing on this site"Devops Training in Chennai"

    ReplyDelete
  4. It’s great to come across a blog every once in a while that isn’t the same out of date rehashed material. Fantastic read.
    I’ve bookmarked your site, and I’m adding your RSS feeds to my Google account.
    java training in bangalore

    ReplyDelete
  5. I have to voice my passion for your kindness giving support to those
    people that should have guidance on this important matter.


    Selenium Training in Bangalore

    ReplyDelete