Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In c++ A point in the x-y plane is represented by its x -coordinate and y -coord

ID: 3670582 • Letter: I

Question

In c++ A point in the x-y plane is represented by its x-coordinate and y-coordinate. Design a class, pointType, that can store and process a point in the x-y plane. You should then perform operations on the point, such as showing the point, setting the coordinates of the point, returning the x-coordinate, and returning the y-coordinate. Overload operator (==) to compare if two points are the same. Also, write a test program to test the various operations on the point.

There are 3 files in this program pointType.h, pointType.cpp and YourlastName_P2.cpp. pointType.h contains the declaration of the class. pointType.cpp contains the implementation of the class. YourlastName_P2.cpp is the driver or test program contains main function, which creates and manipulates the objects of pointType class. In the driver program, each member function should be tested at least once.

Explanation / Answer

FIle : pointType.h

class pointType
{
   public:
       int x;
       int y;
   public:
       pointType();
   public:
       int getX();
       int getY();
       void setX(int x);
       void setY(int y);
       bool operator==(pointType pt);
};

File : pointType.cpp

#include "pointType.h"
#include<stdio.h>
#include<iostream>

using namespace std;
int pointType::getX()
{
   return x;
}
int pointType::getY()
{
   return y;
}
void pointType::setX(int x)
{
   this->x=x;
}
void pointType::setY(int y)
{
   this->y=y;
}
bool pointType::operator==(pointType pt)
{
   if(pt.getX()==this->getX()&&pt.getY()==this->getY())
   {
       return true;
   }
   else
   {
       return false;
   }
}

File : YourLastName_2.cpp

#include "pointType.cpp"
#include<stdio.h>
#include<iostream>

using namespace std;

int main()
{
   int x,y;
   cout<<"Enter X : ";
   cin>>x;
   cout<<" Enter Y : ";
   cin>>y;
   pointType point;
   point.setX(x);
   point.setY(y);
   cout<<" Value of X : "<<point.getX();
   cout<<" Value of Y : "<<point.getY();
   pointType pt;
   pt.setX(3);
   pt.setY(4);
   cout<<point.operator==(pt);
   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote