Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Problem 2. (2D Point) Define a data type Point in point.py that represents a point in 2D. The data type must support the following API:
Problem 2. (2D Point) Define a data type Point in point.py that represents a point in 2D. The data type must support the following API: method Point (x, y) .distanceTo(q) str (p) descriptioin a new point p from the given r and y values the Euclidean distance between p and q the string representation of p as '(x, y)' python3 point.py 0 110 p1 = (0.0, 1.0) p2- (1.0, 0.0) d (p1, p2) 1.41421356237 import stdio import sys class Point: Represents a point in 2-dimensional space. def init_(self, x, y): Constructs a new point given its x and y coordinates. InII I self. x - self ._y = def distanceTo (self, other): Returns the Euclidean distance between self and other. def Str-(self): Returns a string representation of self. InII I # Test client [DO NOT EDIT]. Reads floats x1, y1, x2, y2 from command line, # constructs two Point objects from them, and writes them along with the Euclidean distance between the two. def _main): x1, y1, x2, y2 map (float, sys.argy,l1:]) p1 Point(x1, yl) p2 = Point ( x2, y2) stdig.writeln( "p1-' str(p1)) stdig.writeln('p2str(p2)) stdi2.MTiteln ("d(pl, p2) + str(pl.distanceTo ( p2 ) ) ) if name main main() Problem 2. (2D Point) Define a data type Point in point.py that represents a point in 2D. The data type must support the following API: method Point (x, y) .distanceTo(q) str (p) descriptioin a new point p from the given r and y values the Euclidean distance between p and q the string representation of p as '(x, y)' python3 point.py 0 110 p1 = (0.0, 1.0) p2- (1.0, 0.0) d (p1, p2) 1.41421356237 import stdio import sys class Point: Represents a point in 2-dimensional space. def init_(self, x, y): Constructs a new point given its x and y coordinates. InII I self. x - self ._y = def distanceTo (self, other): Returns the Euclidean distance between self and other. def Str-(self): Returns a string representation of self. InII I # Test client [DO NOT EDIT]. Reads floats x1, y1, x2, y2 from command line, # constructs two Point objects from them, and writes them along with the Euclidean distance between the two. def _main): x1, y1, x2, y2 map (float, sys.argy,l1:]) p1 Point(x1, yl) p2 = Point ( x2, y2) stdig.writeln( "p1-' str(p1)) stdig.writeln('p2str(p2)) stdi2.MTiteln ("d(pl, p2) + str(pl.distanceTo ( p2 ) ) ) if name main main()
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started