Program in C++ to delete the Pattern

Started by thiruvasagamani, Aug 06, 2008, 11:08 AM

Previous topic - Next topic

thiruvasagamani

Program in C++ to delete the pattern

Here is the sample code try this

#include<iostream.h>
#include<conio.h>

class text
{
   public :
      char ch[100];
      void readtext();
      void printtext();
};

class pattern : public text
{
   private :
      int count;
   public  :
      void deletepattern(char pat[], char result[]);   
};

void text::readtext()
{

   for(int i=0; (ch=cin.get())!='$'; i++);
   ch='\0';
   
}

void text::printtext()
{
   cout<<"Given text"<<endl;
   for(int i=0; ch ; cout.put(ch), i++);
   cout<<endl;
}

void pattern::deletepattern(char pat[], char result[])
{
   for(int i=0,m=0; ch; i++)
   {
      for(int j=0, k=i; ch[k]==pat[j] && pat[j]!='\0'; j++, k++);
      
      if(pat[j]=='\0')
      {
         
         i=k-1;
      }
      else
         result[m++]=ch;
   
   }
   result[m]='\0';

}

void main (void)
{
   pattern tp;
   char pat[20], str[100];
   cout<<"Enter String"<<endl;
   tp.readtext();
   
   cout<<"Enter pattern"<<endl;
   cin>>pat;
   
   tp.deletepattern(pat,str);
   cout<<"Result"<<endl;
   cout<<str<<endl;   
   getch();
Thiruvasakamani Karnan