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

design and implement a class called point ( cpp file is at the bottom) Requireme

ID: 3728691 • Letter: D

Question

design and implement a class called point ( cpp file is at the bottom)

Requirements for point:

1a) a .h header file and .cpp implementation file named Point with Pre and Post Conditions for each member function clearly written in the .h file.

1b) All member functions that should not change the calling object should be const. All parameters that do not get changed should be const. All Point objects passed in should be const reference (i.e. const Point& pointPassedIn)

1c) The point object must have the appropriate state variables. Look at the above figure to determine how many state variables it takes to accurately represent a point and the appropriate data type.

2) A Constructor with default values that either initializes each point to what is passed in, or, if a value is not passed in, intializes the value to 0. This should work as follows

Point firstPoint;//firstPoint’s (x,y)=(0,0)

Point firstPoint(2.3);//firstPoint’s (x,y)=(2.3, 0)

Point firstPoint(2.3,-3.2) //firstPoint’s (x,y)=(2.3, -3.2)

3) An explicitly defined Copy constructor which initializes a point object to be a copy of an existing point object. DEFINE THIS EXPLICITLY (even though you technically do not have to in C++).

5) Getters for the x and y coordinates of a point. These must be named get_x() and get_y() and return a value of the appropriate data type

6) Setters for the x and y coordinates of a point. These must be named set_x(____) and set_y(____) and take in the appropriate parameter value

7) Translation: translate(___,___), Translating a point is equivalent to adding a fixed pair of numbers (x,y) to the cartesian coordinates of the point. So if I translate my point, lets call it pointA at (x,y), by (X,Y) pointA will now be located at coordinates (x+X, y+Y)

8) Scaling: scale(___): Scaling a point is equivalent to multiplying both coordinates of a point by some constant. So if I have pointA at (x,y) and I scale it by m, pointA will now be located at coordinates (m*x,m*y)

9) Reflection:
reflect_x(): This reflects the point over the x-axis. If I have pointA at (x,y), after reflecting over the x-axis pointA will now be located at coordinates (x,-y).

reflect_y(): will reflect the point over the y-axis. If I have pointA at (x,y) after reflecting over the y-axis pointA will now be located at coordinates (-x,y)

10) Rotation:
Must include cmath for this.

11) Overload the assignment operator (=). This must be explicitly defined (even though C++ gives you a default operator =’s if you do not define one).

12) Overload the comparison operator (==). This must be overloaded as a NON-MEMBER. Two points are deemed the same if they are at the same coordinates. Note you do not const a non-member.

13) Overload cin as a FRIEND function. if I have pointA and say cin>>pointA and user types in 12.4 and 13.2 either separated by a space or enter, pointA should now be at the coordinate (12.4,13.2).

14) Overload cout as a FRIEND function. if I have pointA at coordinate (12.4,13.2) and say cout<<pointA the following should be outputted (and nothing more!— no need for endlines etc.)
(12.4,13.2)

output should look like

https://drive.google.com/file/d/18aRTBCkehClWJIPyne-DuDrg5NxwYhAV/view

Explanation / Answer

here is your .h and .cpp file : ---------->>>>>>>>>

Point.h: -------->>>>>>.

#ifndef __POINT__H
#define __POINT__H
#include<iostream>
#include<cmath>

using namespace std;

class Point{
double x;
double y;

public:
  //x and y shoud be a real value
  //if x is not passed it will take 0
  //if y is not passed it will take 0
  Point(double x = 0,double y = 0);
  //copy constructor
  Point(const Point &oth);
  //gettter method
  double get_x()const;
  double get_y()const;
  //setter method
  void set_x(double x);
  void set_y(double y);
  
  //translation this method add the passed values to appropriate
  //coordinates x and y
  void translate(double X,double Y);
  //scale the point to given parameter
  void scale(int m);
  
  //reflextion
  //reflection of x
  void reflect_x();
  //reflection of y
  void reflect_y();
  
  //rotation
  void rotate(double angle,double cx = 0,double cy = 0);
  
  //explicitly define operator =
  Point& operator=(const Point &oth);
  friend ostream& operator<<(ostream &out,const Point &oth);
  friend istream& operator>>(istream &in,Point &oth);
};

bool operator==(const Point &oth1,const Point &oth2);

#endif

Point.cpp : ------------>>>>>>>>>

#include "Point.h"

Point::Point(double x,double y){
this->x = x;
this->y = y;
}
Point::Point(const Point &oth){
*this = oth;
}
Point& Point::operator=(const Point &oth){
x = oth.x;
y = oth.y;

return *this;
}
void Point::set_x(double x){
this->x = x;
}
void Point::set_y(double y){
this->y = y;
}
double Point::get_x()const{
return x;
}
double Point::get_y()const{
return y;
}
void Point::translate(double X,double Y){
x = x+X;
y = y+Y;
}
void Point::reflect_x(){
x = x*(-1);
}
void Point::reflect_y(){
y = y*(-1);
}
void Point::scale(int m){
x = x*m;
y = y*m;
}
ostream& operator<<(ostream &out,const Point &oth){
out<<"("<<oth.get_x()<<", "<<oth.get_y()<<")";
return out;
}
istream& operator>>(istream &in,Point &oth){
double a,b;
in>>a>>b;
oth.set_x(a);
oth.set_y(b);

return in;
}
void Point::rotate(double angle,double cx,double cy){
double s = sin(angle);
double c = cos(angle);

// translate point back to origin:
x -= cx;
y -= cy;
// rotate point
double xnew = x * c - y * s;
double ynew = x * s + y * c;

// translate point back:
x = xnew + cx;
y = ynew + cy;
}

bool operator==(const Point &oth1,Point &oth2){
if(oth1.get_x() == oth2.get_x() && oth1.get_y() == oth2.get_y()){
  return true;
}

return false;
}