September 17, 2012 / IST / Language.

/* Q3-> WAP In C++ Using Class To Copy And Concatenate Strings*/

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
#include<process.h>
class strcpcat                  //class declaration
{
   private:
	   char s1[10],s2[10],s3[20];
	   int i,j;                        //private members
   public:
	   strcpcat();
	   void gtstng(int);
	   void cpystng();       //member functions
	   void catstng();
	   void dispstng();
};
strcpcat::strcpcat()
{
  for(i=0;i<10;i++)            //constructor defination
    { s1[i]=s2[i]=0;}
}
void strcpcat::gtstng(int sn)
{ if(sn==1)
  {
   cout<<"\nEnter The First String:";
   gets(s1);
  }                                  //function to get lines
  else if(sn==2)
  { cout<<"\nEnter The Second String:";
   gets(s2);
  }
}
void strcpcat::cpystng()
{                           //function to copy lines
   strcpy(s3,s1);
}
void strcpcat::catstng()
{
  strcat(s1,s2);                 //function to concatenate lines
  strcpy(s3,s1);
}
void strcpcat::dispstng()
{
  cout<<"\nThe Line After Processing Is:";
  for(i=0;s3[i]!=NULL;i++)             //function to display lines
    cout<<s3[i];
}
void main()                    //main function
{
  strcpcat ob;
  int ch;
  char choice;
  do
  {clrscr();
   cout<<"\n\n\t\t\tSTRING COPY AND CONCATENATE";
   cout<<"\n\t\t\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^";
   cout<<"\n\n1.Copy Line";
   cout<<"\n2.Concatenate Two Lines";           //menu
   cout<<"\n3.Display Line";
   cout<<"\n4.Exit";
   cout<<"\n\nWhat Do You Want To Do:";
   cin>>ch;
       switch(ch)
	    {     case 1: ob.gtstng(1);ob.cpystng();break;
		  case 2: ob.gtstng(1);ob.gtstng(2);
			  ob.catstng();break;
		  case 3: ob.dispstng();break;    //calling functions
		  case 4: exit(0);
		  default:cout<<"\nPlease Enter A Valid Choice(1-3)!!!";
	    }
   cout<<"\nDo You Want To Continue(Y/N):";
   cin>>choice;
  }while(choice=='Y'||choice=='y');
}                              //end of the program