Skip to main content

Class Point:: It holds co-ordinates of a point in format (x,y)

A class Named "Point" which stores the Co-ordinates of a point in (x,y) Format.
This Class Contains::
O Constructor with default arguments
O Copy Constructor
O Function to display which Co-ordinate a Point belongs to
O Function to get value of x of a point
O Function to get value of y of a point
O Function to get the Radious Vector (r) of a point
O Function to get the Theta of a point
O Overloaded Operator - to find out distance between two points
O Overloaded Operator >> to take input
O Overloaded operator << to display a point
O Destructor
#include<iostream.h>
#include<math.h>

class point{

 //Data Members

 int x,y;    //They hold the value of X and Y co-ordinate of a Point.

 public:

 //Member Functions

 point(int t1=0, int t2=0)  //Constructor with default arguments.
 {
  x=t1;
  y=t2;
 }

 point(point &t)  //Copy Constructor
 {
  x=t.x;
  y=t.y;
 }

 int coordinate(void);  //It returns the point's Co-ordinate, e.g., 1, 2, 3, or 4th.

 int getx(void){ return x; }  //It returns the value of X co-ordinate of a point.

 int gety(void){ return y; }  //It returns the value of Y co-ordinate of a point.

 double r(void){ return sqrt((x*x)+(y*y)); }  //It returns the Radius Vector of a point.

 double theta(void){ return atan(y/x); }  //It returns the Vectorial Angle of a point.

 double operator -(point &t)  //Overloading of operator -- to find the distance between two points.
 {
  return sqrt(pow(x-t.x,2)+pow(y-t.y,2));
 }

 friend istream& operator >> ( istream &in, point &t );  //Take input a point using the line cin>>point_object;

 friend ostream& operator << ( ostream &out, point &t);  //Give output of a point using the line cout<<point_object;

 ~point(void)  //Destructor
 {
  cout<<"\nThis point is destructed";
 }

};


int point:: coordinate(void)
{
 int a;
 if(y>=0)
  if(x>=0) a=1; else a=2;
 else
  if(x<0) a=3; else a=4;
 return a;
}

istream& operator >> (istream &in, point &t)
{
 cout<<"\nINPUT X::";
 in>>t.x;
 cout<<"INPUT Y::";
 in>>t.y;
 return in;
}

ostream& operator << (ostream &out, point &t)
{
 out<<"( "<<t.x<<","<<t.y<<" )";
 return out;
}


void main()
{
 point a(-3,-4);
 cout<<"\nPoint:: "<<a;
 cout<<"\nThe Co-ordinate of this Point:: "<<a.coordinate();
 cout<<"\nValue of X Co-ordinate:: "<<a.getx();
 cout<<"\nValue of Y Co-ordinate:: "<<a.gety();
 cout<<"\nPolar Co-ordinates(in r,theta form):: ( "<<a.r()<<","<<a.theta()<<" )";
 point b;
 cin>>b;
 cout<<"\nDistance of point "<<a<<" from "<<b<<" :: "<<a-b;
 point c(b);
 cout<<"\nCopy of "<<b<<" is "<<c;
}

Comments

Popular posts from this blog

টুক করে বকখালি

বকখালি অবস্থান:  দেশ: ভারতবর্ষ রাজ্য: পশ্চিমবঙ্গ জেলা: দক্ষিণ ২৪ পরগনা কি কি দেখার ?                 বিশাল সমুদ্র..... আরে, Bay of Bengal.... পুরো দীঘার ছোট edition... বিস্তৃত সমুদ্র সৈকত..... বেশ ঘন ম্যানগ্রোভ অরণ্য... আর যেটা খুব ভালো লাগে সেটা হল.... এখানে দীঘার মত এত ভীরভাট্টা নেই.... বেশ নিরিবিলি..... যারা একাকী একটা দিন নিভৃতে কাটাতে চান তাঁদের জন্য ব্যাপক জায়গা। (বা দুজনে নিভৃতে কাটাতে চান....)                  একটা Crocodile Park আছে ওখানে.....পশ্চিমবঙ্গ বন দপ্তর দ্বারা নির্মিত..... Bus Stand এর কাছেই। ভালই সাজানো গোছানো.....২ টাকা করে Entry Fee.... ওর মধ্যে একটা পুকুর আছে, যার ঘাট বাঁধানো । কিছুক্ষণ ওখানে বসতেও খুব ভালই লাগে..... বেশ গাছের ছায়া.... মৃদু মন্দ শীতল হাওয়া..... উফ: প্রাণটা যেন জুড়িয়ে যায়..... যেন মনে হয় প্রকৃতির কোলে মাথা রেখে একটু শান্তিতে ঘুমিয়ে নিই.... একটা Tube Well ও আছে.....

Majay Byatha