Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with this programming assignment. It is to be done in Python programming language. P.S. Please adhere to all of the detailed requirements

image text in transcribed

I need help with this programming assignment. It is to be done in Python programming language.

P.S. Please adhere to all of the detailed requirements and instructions. Your help will be most appreciated. Thanks

So one of the previous responses to this question did not adhere to the requirements which was to create the seperate code three distinct python files XXmain.py, XXtriangles.py & XXpoints.py.

Essentially the XXpoints.py will create a point object when given 2 values. These will be stored in the attributes named x and y. There will be two methods: getX and getY. There will be no setters; points will only be created with a constructor that receives an x and a y value.

and the XXtriangles.py will create a triangle object when given 3 point objects. Its attributes will be these three points, which can be retrieved with the getter getVertices, which will return a list of three points. It will also, within the constructor, determine the three side lengths and store those as side1, side2, and side3. (This means that the method sideLength can be in the constructor.) These values can be retrieved with the getter getSides, which will return a list of the three floats.

XXpoints.py and XXtriangles needs to implemented in the XXmain.py to produce the final output XXoutput6.txt from the input file input6.txt.

Also please use the value of epsilon in the file to be 0.0001 when evaluating features (VERY IMPORTANT)

...

Here is the previous response or code that you can modify to better suit the requirements detailed above. Thanks a lot.

import math

def sideLength(x1,y1,x2,y2):

return math.sqrt((x1-x2)**2+(y1-y2)**2)

def duplicatePts(x1,y1,x2,y2,x3,y3):

if( ((x1==x2)and(y1==y2)) or ((x1==x3)and(y1==y3)) or ((x2==x3)and(y2==y3))):

return True

else:

return False

def collinear(x1,y1,x2,y2,x3,y3):

if((x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2))==0):

return True

else:

return False

def findShortest(x1,y1,x2,y2,x3,y3):

l1 = sideLength(x1,y1,x2,y2)

l2 = sideLength(x1,y1,x3,y3)

l3 = sideLength(x2,y2,x3,y3)

return min(l1,l2,l3)

def perimeter(x1,y1,x2,y2,x3,y3):

l1 = sideLength(x1,y1,x2,y2)

l2 = sideLength(x1,y1,x3,y3)

l3 = sideLength(x2,y2,x3,y3)

return l1+l2+l3

def area(x1,y1,x2,y2,x3,y3):

return (x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2))*0.5

def right(x1,y1,x2,y2,x3,y3):

l1 = sideLength(x1,y1,x2,y2)

l2 = sideLength(x1,y1,x3,y3)

l3 = sideLength(x2,y2,x3,y3)

if((l1*l1==l2*l2+l3*l3) or (l2*l2==l1*l1+l3*l3) or (l3*l3==l2*l2+l1*l1) ):

return True

else:

return False

def acute(x1,y1,x2,y2,x3,y3):

l1 = sideLength(x1,y1,x2,y2)

l2 = sideLength(x1,y1,x3,y3)

l3 = sideLength(x2,y2,x3,y3)

if((l1*l1

return True

else:

return False

def obtuse(x1,y1,x2,y2,x3,y3):

l1 = sideLength(x1,y1,x2,y2)

l2 = sideLength(x1,y1,x3,y3)

l3 = sideLength(x2,y2,x3,y3)

if((l1*l1>l2*l2+l3*l3) or (l2*l2>l1*l1+l3*l3) or (l3*l3>l2*l2+l1*l1) ):

return True

else:

return False

def scalene(x1,y1,x2,y2,x3,y3):

l1 = sideLength(x1,y1,x2,y2)

l2 = sideLength(x1,y1,x3,y3)

l3 = sideLength(x2,y2,x3,y3)

if(l1!=l2 and l2!=l3 and l3!=l1):

return True

else:

return False

def isosceles(x1,y1,x2,y2,x3,y3):

l1 = sideLength(x1,y1,x2,y2)

l2 = sideLength(x1,y1,x3,y3)

l3 = sideLength(x2,y2,x3,y3)

if(l1==l2 or l2==l3 or l3==l1):

return True

else:

return False

def equilateral(x1,y1,x2,y2,x3,y3):

l1 = sideLength(x1,y1,x2,y2)

l2 = sideLength(x1,y1,x3,y3)

l3 = sideLength(x2,y2,x3,y3)

if(l1==l2 and l2==l3):

return True

else:

return False

def main():

f = open('input4.txt', 'r')

for line in f:

coord = []

for word in line.split():

coord.append(float(word))

if(duplicatePts(coord[0],coord[1],coord[2],coord[3],coord[4],coord[5])):

print("Duplicate Points")

elif(collinear(coord[0],coord[1],coord[2],coord[3],coord[4],coord[5])):

print("Points are collinear")

else:

minside = findShortest(coord[0],coord[1],coord[2],coord[3],coord[4],coord[5])

per = perimeter(coord[0],coord[1],coord[2],coord[3],coord[4],coord[5])

are = area(coord[0],coord[1],coord[2],coord[3],coord[4],coord[5])

print('Vertices is: ({},{}),({},{}),({},{})\t Shortest side is {}'.format(coord[0],coord[1],coord[2],coord[3],coord[4],coord[5],round(minside,2)))

print('Perimeter is: {}\t Area is {}'.format(round(per,2),round(are,2)))

if(equilateral(coord[0],coord[1],coord[2],coord[3],coord[4],coord[5])):

print("Equilateral",end='\t')

elif(isosceles(coord[0],coord[1],coord[2],coord[3],coord[4],coord[5])):

print("Isosceles",end='\t')

else:

print("Scalene", end = '\t')

if(right(coord[0],coord[1],coord[2],coord[3],coord[4],coord[5])):

print("Right",end=' ')

elif(obtuse(coord[0],coord[1],coord[2],coord[3],coord[4],coord[5])):

print("Obtuse",end=' ')

else:

print("Acute", end = ' ')

The main program will be named XXProg4.py. The file with the functions will be named XXtriFun.py. (XX, of course, represents your initials.) The list now contains only valid triangles. Go through the list and, for each triangle, if the data is valid, report on the following (see sample below). The output will be printed from the main program, not from within the functions. There will need to be three files submitted: XXmain.py, XXpoints.py and XXlriangles.py (VERY IMPORTANT List the vertices Length of the shortest side (2 decimal places) Perimeter (2 decimal places) Area (2 decimal places) Whether it is right, acute or obtuse Whether it is scalene, isosceles or equilateral (choose one only . . For XXpoints-py and XXtriangles.py use two classes(respectively): The point class will create a point object when given 2 values. These will be stored in the attributes named x and y. There will be two methods: getX and getY. There will be no "setters" points will only be created with a constructor that receives an x and a y value INPUT The main program will loop through a data file named input6.txt reading and processing each line of data. The data will be in this format The triangle class will create a triangle object when given 3 point objects. Its attributes will be these three points, which can be of three points. It will also, within the constructor, determine the three side lengths and store those as sidel, side2, and side3. (This means that the method sideLength can be in the constructor.) These values can be retrieved with the "getter" getSides, which will return a list of the three floats. retrieved with the " getter" getVertices, which will return a list X1 Y1 X2 Y2X3 Y3 It represents the )coordinates of the three vertices of a triangle, such as these: For each triangle, your program will first check to make sure each point is unique (no duplicates) and that the three points are not collinear 14 2.3 3.2 4.1 5.0 6.9 5 31 3.0 3. 1 OUTPUT ?Use an epsilon of 0.0001 when evaluating features. (VERY IMPORTANT) Your output file will be named XXoutput6.txt, following this format: Vertices: (14, 2.3), 3.2, 4.1), (5.0, 6.9) Shortest side is 255 Perimeter is 11.72 The triangle class will also include "ALL" of these methods, with the appropriate return value: Area is 0.90 Obtuse duplicatePts boolean collinear n indShortest float perimeter float float boolean boolean isosceles bn equilateral bln right acute obtuse The triangle objects which are created with be put into a list named myTriangles Once you have created the entire list (in other words, not as you create each triangle). you will first check to see if it is a "legal" triangle (are there duplicate or collinear points). If it is illegal, delete that triangle from the list and report the deletion to an output file. (Give the vertices and the reason. either duplicate points or collinear points.)

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

Beginning ASP.NET 4.5 Databases

Authors: Sandeep Chanda, Damien Foggon

3rd Edition

1430243805, 978-1430243809

More Books

Students also viewed these Databases questions

Question

20. Prove Theorem 5.6.4.

Answered: 1 week ago