Below based on the following two classes Point 2D and Point
Below based on the following two classes Point 2D and Point 3D: Point 2D class: Two integer field x and y each with accessory (get) and (set) methods. A default constructor that creates a 2D point with 0 values. A constructor that takes 2 int values and creates a point object with the x and y values. A constructor that takes 2 int values and creates a point object with the x and y values. An overload == operator to determine whether two 2D points ate equal or not. An overload so that we can read a 2D point object from the input stream using an instruction similar to this: cin > > point 1; Point 3D class; Three integer fields: x, y and z each with (get) and mutator (set) methods. A default constructor that creates a 3D point with 0 values. A constructor that takes 3 int values and creates a 3D point object with the x, y and z values. An overload == operator to determine whether two 3D points arc equal or not. An overload so that we can read a 3D point object from the input stream a) Implement the Point 2D class. b) Implement the Point 3D class. This class should be derived from the Point 2D class.
Solution
Here is the code in C++ for above scenario
#include <iostream>
using namespace std;
class Point2D{
public:
int x,y;
Point2D(){
x=0;
y=0;
}
Point2D(int x1,int y1){
x=x1;
y=y1;
}
int operator==(const Point2D& b){
if(b.x==this.x && b.y){
return 0;
}
else {
return 1;
}
}
void operator>> (const Point2D& b){
cin>>x;
cin>>y;
}
void operator>> (const Point2D& b){
cin<<x;
cin<<y;
}
}
