Sunday 9 September 2012

CPP program for finding number of vowels in string

#include<iostream.h>
#include<stdio.h>
#include<string.h>
#include<conio.h>
#include<fstream.h>
#include<iostream.h>
  void main()
    {
      char name[100],ch;
      int vcount=0;
      clrscr();
      cout<<"enter the string:"<<endl;
      gets(name);
      fstream f;
      f.open("vowel.v",ios::out);
    //  f.write((char *)&name,sizeof(name));
    f<<name;
      f.close();
      fstream f1;
      f1.open("vowel.v",ios::in);
      while(f1)
    {
      f1.get(ch);
      if(ch>='A'||ch<='Z'||ch>='a'||ch<='z')
       {
        switch(ch)
          {
        case 'A':
        case 'E':
        case 'I':
        case 'O':
        case 'U':
        case 'a':
        case 'e':
        case 'i':
        case 'o':
        case 'u':vcount++;
          }
       }
      }
      f1.close();
      cout<<"number of vowels in string are:"<<endl;
      cout<<vcount;
      getch();
     }

No comments:

Post a Comment