Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help writing a code in Python 2.7.14. The description of the code, as well as a template that is to be added to,

I need help writing a code in Python 2.7.14. The description of the code, as well as a template that is to be added to, is listed below. I am struggling a lot with understanding how to code this program, so any help is appreciated. Thanks.

Code description: image text in transcribed

Code template:

##########################################################

# the 2D point class

class Point(object):

# write your code for the point class here (and subsequently remove this comment)

##########################################################

# ***DO NOT MODIFY OR REMOVE ANYTHING BELOW THIS POINT!***

# create some points

p1 = Point()

p2 = Point(3, 0)

p3 = Point(3, 4)

# display them

print "p1:", p1

print "p2:", p2

print "p3:", p3

# calculate and display some distances

print "distance from p1 to p2:", p1.dist(p2)

print "distance from p2 to p3:", p2.dist(p3)

print "distance from p1 to p3:", p1.dist(p3)

# calculate and display some midpoints

print "midpt of p1 and p2:", p1.midpt(p2)

print "midpt of p2 and p3:", p2.midpt(p3)

print "midpt of p1 and p3:", p1.midpt(p3)

# just a few more things...

p4 = p1.midpt(p3)

print "p4:", p4

print "distance from p4 to p1:", p4.dist(p1)

Here is a screenshotof the template for reference:

Using the template provided, your task in this programming assignment is to implement a 2D point class in Python. You must provide/address the following in the class: A2D point is made up of an x-component and a -component. Each component is a floating point value .A constructor should initialize a point either with specified values for the x- and y-components or the point (0.0,0.0) as default, Instance variables should be appropriately named (ie., beginning with underscores) Accessors and mutators should provide read access of and write access to the instance variables; A function named dist should take two points as input and calculate and return the floating point distance between the two points, A function namedmidpt should take two points as input and calculate and return the midpoint of the two points; and Amagic function should provide a string representation of a point in the format (x.y) Note that you must not modify the main part of the program; therefore, your output should look eractly like the following code python 2Dpoints.py pl: C0.0,0.0) p2: (3.0,0.0 p3: (3.0,4.01 distance from pl to p2: 3.0 distance from p2 to p3: 4.0 distance from pl to p3: 5.0 midpt of pl and p2: (1.5, 0.0) midpt of p2 and p3: (3.0,2.0) midpt of pl and p3: (1.5,2.0) p4: (1.5,2.0 distance from p to pl: 2.5 You should probably use the main part of the program and the provided output to help you design the class properly To help clarify, here are some specifics and or constraints: (1) Make sure that your 2D point class addresses all of the requirements listed above; (2) Pay attention to the input(s) and output(s) of the fumctions dist andmidpt (i.e, make sure that your code precisely matches their descriptions above); (3) Use the decorator method discussed in class for accessors and mutators to properly wrap the (4) You must include a meaningful header, use good coding style, use meaningful variable names, and comment your source code where appropriate; (5) Your output should be eractly like the sample run shown above;and (6) You must submit your source code as a single py file

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

Cost Accounting A Managerial Emphasis

Authors: Charles T. Horngren, Srikant M.Dater, George Foster, Madhav

13th Edition

8120335643, 136126634, 978-0136126638

Students also viewed these Databases questions