CONSTRUC

Home >> Sem 2 >> C++ programs >> CONSTRUC

/* Write a Program to implement all types of constructor */
#include<iostream.h>
#include<conio.h>

class test
 {
      int a,sum,b;
   public :
      test()
       { }
       test(int p,int q)
        {
          a = p;
          b = q;
        }
       test(test &p)
        {
          a = p.a;
          b = p.b;
        }
      void show()
       {
         sum = a + b;
         cout<<"\n   "<<a<<" + "<<b<<" =  "<<sum;
       }

  };
void main()
 {
   int x,y;
   clrscr();
    cout<<"Enter any two integer values : ";
    cin>>x>>y;

      test t1(x,y);
    cout<<endl<<"First Object is created.";
      test t2(t1);
    cout<<endl<<"Second object is created.";
      test t3=t1;
    cout<<endl<<"Third object is created.";

    t1.show();
    t2.show();
    t3.show();

   getch();
 }