26.1k views
5 votes
A point in the x−y plane is represented by its x-coordinate and y coordinate. Design the class Point that can store and process a point in the x−y plane.

- We should then perform operations on a point, such as showing the point, setting the coordinates of the point, printing the coordinates of the point, returning the x-coordinate, and returning the y-coordinate,
- Write a test program to test various operations on a point.

The class Point should contoin the following methods and data members:
1. protected members x and y
2. defoult constructor
3. constructor with parameters
4. setPoint(x)
5. getX()
6. getY()
7. tostring()
8. equals (x)
9. makeCopy (x)
10. getcopy()
11. printPoint()

The outrout should show the following:
- Initialize myPoint =[5.00,4.00]
- Initialize yourPoint =[0.00,0.00]
- Print both of these objects
- Set yourpoint to [5.00,45.00] and print it
- Determine if the 2 points are equal or not
- Change the myPoint coordinates to [6.00,9.00]
- Print this new myPoint object
- Copy myPoint into yourPoint and then print the yourPoint object
- Print your program to test the class Point
- Paste the output after the program
- Print the Point class

1 Answer

6 votes

Final answer:

To design a class called Point that can store and process a point in the x-y plane, you can define the class with the necessary data members and methods. The class should have protected members x and y to store the coordinates of the point, and methods such as setPoint, getX, getY, toString, equals, makeCopy, getCopy, and printPoint.

Step-by-step explanation:

To design a class called Point that can store and process a point in the x-y plane, you can start by defining the class with the necessary data members and methods. The class should have protected members x and y to store the coordinates of the point.

It should also have a default constructor, a constructor with parameters to set the coordinates, a setPoint method to change the coordinates, getX and getY methods to return the coordinates, a toString method to print the coordinates, an equals method to check if two points are equal, a makeCopy method to make a copy of a point, and a getCopy method to return the copy of the point.

Here is an example implementation of the Point class in Python:

class Point:
def __init__(self, x=0.0, y=0.0):
self.x = x
self.y = y

def setPoint(self, x, y):
self.x = x
self.y = y

def getX(self):
return self.x

def getY(self):
return self.y

def __str__(self):
return '[%.2f, %.2f]' % (self.x, self.y)

def equals(self, other):
return self.x == other.x and self.y == other.y

def makeCopy(self):
return Point(self.x, self.y)

def getCopy(self):
return self.makeCopy()

def printPoint(self):
print(self)

User Ivan Sas
by
7.9k points