AIM:-Consider problem statement given in 2.3, perform following functionalities: a. Initialize X and Y with default value 0. b. Addition of two point is addition of its member X and Y respectively. Provide addPoints function to implement this. i,e, P1=(2, 5), P2=(4, 1), result point (2+4, 5+1)=(6, 6) c. The point which is far from the origin is considered as max point. Implement function which will return point object from given two points. (note: implement using return by reference).

 

Input:-

 

#include<iostream>
#include<math.h>
using namespace std;

class xy
{
   int x,y,p1x,p2x,p1y,p2y,d1=0,d2=0;

   public:

   xy(int x1,int y1)
   {
     x=x1;
     y=y1;
   }


   void setp1(int px1,int py1)
   {
     p1x=px1;
     p1y=py1;
   }

   void setp2(int px2,int py2)
   {
    p2x=px2;
    p2y=py2;
   }

   void cal()
   {
    x=p1x+p2x;
    y=p1y+p2y;
   }
  
   void display()
   {

    cout<<"("<<p1x<<","<<p1y<<")"<<"+"<<"("<<p2x<<","<<p2y<<")"<<"="<<"("<<x<<","<<y<<")" ;
    cout<<"\n";
   }
 
   int  cal1()
   {
     
     d1=sqrt((p1x-x)*(p1x-x)+(p1y-y)*(p1y-y));
     d2=sqrt((p2x-x)*(p2x-x)+(p2y-y)*(p2y-y));
    
   }

  void  display1()
  {
   	if(d1>d2)
   	{
    	cout<<"\np1 is max";
   	}
   	else if(d2>d1)
   	{
     	 cout<<"\np2 is max";
   	}
           else
   	{
    	 cout<<"\np1=p2";
   	}
           cout<<"\n";
  }

};

int main()
{
  xy x(0,0);
  x.setp1(5,5);
  x.setp2(5,5);
  x.cal();
  x.display();
  x.cal1();
  x.display1();

return 0;
}


Output:-

(5,5)+(5,5)=(10,10)

p1=p2

Advertisements