Answered step by step
Verified Expert Solution
Link Copied!

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:

image text in transcribed

image text in transcribed

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advanced Oracle Solaris 11 System Administration

Authors: Bill Calkins

1st Edition

0133007170, 9780133007176

More Books

Students also viewed these Databases questions

Question

1. What is a security? LOP8

Answered: 1 week ago

Question

2. What are the two main functions of the financial system? LOP8

Answered: 1 week ago