Create a struct point to represent a point in cartesian coordinate system
provide member functions
default constructor
input
output
distance(returns the distance between two point objects, the function takes one object as an argument)
is zero(determines if a point is the center)
midlepoint (computes the middle point of an object from origin and returns the answer in a point object)
is equal to(compare two points)
isGreater than (compares two point in terms of the distance from the center)
#include <bits/stdc++.h>
using namespace std;
struct Point{
  int x;
  int y;
  Point(){
    Â
  }
  void distance(Point p){
    cout<<"\nEnter x2: ";
    cin>>p.x;
    cout<<"\nEnter y2: ";
    cin>>p.y;
    double dist= sqrt(pow(p.x - x, 2) +pow(p.y - y, 2) * 1.0);
    cout<<"\nDistance: "<<dist;
  }
  Â
 Â
};
void is_equal_to(Point p1, Point p2){
   if(p1.x==p2.x && p1.y==p2.y)Â
    cout<<"\nThe two points are equal";
   else
    cout<<"\nThe two points are not equal";
}
void isGreater_than(Point p1, Point p2){
    int a=p1.x+p1.y;
    int b=p2.x+p2.y;
    if(a>b){
      cout<<"\nThe first point is greater.";
    }
    else if(b>a){
      cout<<"\nThe second point is greater.";
    }
    else
      cout<<"\nThe two points are equal.";
}
void isZero(Point p1){
    if(p1.x==0 && p1.y==0)
      cout<<"\nThe point is zero";
    else
      cout<<"\nThe point is not zero";
}
int main()
{
  Â
  return 0;
}
Comments
Leave a comment