3 Replies - 10506 Views - Last Post: 14 November 2007 - 03:01 PM Rate Topic: *---- 1 Votes

#1 sdrepau1   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 13-October 07

Triangle

Posted 13 October 2007 - 06:11 PM

Do not make any changes to the functions setUpWindow( ) and endProgram( ).

Modify the drawTriangle( ) function so that it returns the triangle that it drew to the caller (main).

Have main call a function named computeInfo that has one parameter, the triangle.

Define the computeInfo function. Its job is to compute and display the side lengths, perimeter and area of the triangle argument that is passed to it. The formulas needed can be found in exercises 8 and 10 on p.161 of the text book. Hint: the getPoints( ) method of the Polygon type will be very useful.

The computeInfo function should be decomposed so that it calls other functions to do parts of its job. You will need to think carefully about the interface (parameter(s) and return value(s)) of each of the functions that you add to the existing program.

My Code :

# Draw a triangle as directed by mouse clicks
from graphics import *
import math

# set up the graphics window
def setUpWindow():
win = GraphWin("Draw a Triangle")
message = Text(Point(100, 175), "Click on three points")
message.draw(win)
return win, message

# draw the triangle
def drawTriangle(win):
p1 = win.getMouse()
p1.draw(win)
p2 = win.getMouse()
p2.draw(win)
p3 = win.getMouse()
p3.draw(win)
GetX = dx , dy
dx = GetX(p2) - GetX(p1)
dxy = GetX(p3) - GetX(p1)
dy = GetX(p3) - GetX(p2)
sidelength = math.sqrt (dx ** 2 + dy ** 2)
s =(dx + dxy + dy) / 2
area = math.sqrt (s *(s - dx) * (s - dy) * ( s - dxy))
perimeter = p1 + p2 + p3
triangle = Polygon(p1, p2, p3)
triangle.setFill("red")
triangle.setOutline("black")
triangle.draw(win)
return drawTriangle (graphicsWindow)

# end the program
def endProgram(win, message):
message.setText("Click anywhere to quit.")
win.getMouse()
win.close()

# call functions in order needed
def main():
graphicsWindow, message = setUpWindow()
drawTriangle(graphicsWindow)
endProgram(graphicsWindow, message)
triangle =(sidelength,perimeter,area)
computeInfo(triangle)
getPoints()

main()

Is This A Good Question/Topic? 0
  • +

Replies To: Triangle

#2 girasquid   User is offline

  • Barbarbar
  • member icon

Reputation: 108
  • View blog
  • Posts: 1,825
  • Joined: 03-October 06

Re: Triangle

Posted 13 October 2007 - 10:02 PM

So...what's the problem?
Was This Post Helpful? 0
  • +
  • -

#3 KevinADC   User is offline

  • D.I.C Regular
  • member icon

Reputation: 27
  • View blog
  • Posts: 401
  • Joined: 23-January 07

Re: Triangle

Posted 13 October 2007 - 10:08 PM

he's hoping someone will be daft enough to do his school work for him.
Was This Post Helpful? 0
  • +
  • -

#4 DPR   User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 17
  • Joined: 20-December 06

Re: Triangle

Posted 14 November 2007 - 03:01 PM

You're only cheating yourself
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1