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

2's Complement of 2Byte Number

This program will work out the 2's Complement of a 2 Byte Number. As Microprocessor can perform 8 bits at a time in Accumulator, so we follow the foloowing Algo Fetch the 2 Byte Number in a Register Pair Bring Least Significant Byte of the Number from last Register into A (Accumulator) Make Complement of A and add 1 Store back the Updated LSByte into its source Register Bring MSByte of the Number from another Register into A Make Complement of A and add 1 if carry was genetrated at the time of LSByte opeartion Store back the Updated MSByte into its source Register Store the Result to a Memory location Suppose, Argument Number is stored in Location 1000H and 1001H Memory Location and store the value in 2000H and 2001H Memory Locations. Memory Location Hex Code Label Mnemonics Comment 3050 3051 3052 2A 00 10 START: LHLD 1000H ;Load the HL Register Pair with the content of Memory Location 1000H and 1001H 3053 7D MOV A, L ;Move the Content of L to A ( Accumulator ) 3054 2F

Flip-Flop Conversion

Flip-Flop is a memory element. You can say a basic element. It is a circuit that can hold a binary state (0 or 1 as low or high volts) until an input to change that state. We have many flip-flops as SR Flip-Flop (Set Reset) D Flip-Flop (Data) JK Flip-Flop T Flip-Flop (Toggle) Those Flip-Flops are available in market in IC Package Form. Now You have a circuit that uses 1 JK and 1 D Flip-Flop and 3 NOT Gates. So you have to buy three ICs- one for JK, one for D and other for NOT Gate. Ultimately you will see that a flip flop in IC of JK, a flip-flop in D IC and 3 NOT gates are not used. Now, if you convert a JK flip flop into D flip flop then you didn’t have to pay for the D flip flop IC. So, your circuit will be made by 2 ICs in place of 3 and in cheap cost. This article is for that reason. How the Flip-Flops are converted from one to other. Procedure: 1. Write Qt and Qt+1 Table with 4 combination of 0 and 1. 2. Write columns for inputs of destination Flop-Fl op. 3. Write the ce

How to set Set-Top Box to Resume automatically to last Channel after switch on?

How to set customised automatic Resume Channel to last viewed in Set-Top Box?  Introduction In the era of Digitally fast growing life WiFi enabled smart devices and also voice controlled smart devices are trying to be companion of every human being. But, all human do not change their habit at the same time. It may be cause of mental attachment or financial limits or unwillingness or though as unnecessary. What ever the reason may be, there exists the old technology, like IR(Infrared), RF(Radio Frequency), etc. So, this article for them who are using "Un-smart" TV like me in this time of Smart World. I was searching for a solution to set my Set-top Box of Videocon DTH (controlled by a RF Remote) to resume the last viewed channel when I power on my TV anytime. Suppose, I was watching NAT-Geo and switch off my (Un-smart) TV, even switch off the plug power at board. Now, after some time / on the next day, when I switch on my TV it will directly tune to the last viewed channel, i.