Saturday, 16 May 2015

U4P4

Define Class named point which represents 2-D Point, i.e P(x, y). Define Default Constructor to initialize both data member value 5, parameterized constructor to initialize member according to value supplied by user and Copy constructor. Define Necessary Function and Write a program to test class Point.

Code : 
 #include<iostream.h>  
 #include<conio.h>  
 class point  
 {  
      public:  
      int x,y;  
      point()  
      {  
           x=5;  
           y=5;  
      }  
      point(int a,int b)  
      {  
           x=a;  
           y=b;  
      }  
      point(point &p)  
      {  
           x=p.x;  
           y=p.y;  
      }  
      void show()  
      {  
           cout<<"(X,Y) : ("<<x<<","<<y<<")"<<endl<<endl;  
      }  
 };  
 void main()  
 {  
      clrscr();  
      cout<<"Default Constructor Value :\n";  
      point p1;  
      p1.show();  
      cout<<"\nParameterized Constructor Value :\n";  
      point p2(8,3);  
      p2.show();  
      cout<<"\nCopy Constructor Value :\n";  
      point p3(p2);  
      p3.show();  
      getch();  
 }  


Output :

No comments:

Post a Comment