Prev Up Next
Go backward to 6.1 Compiling
Go up to 6 Labs
Go forward to 6.3 Change

6.2 Triangles

This lab is a modification of problem 1-26 from Cooper.

I want you to compute the area of a triangle two different ways, checking intermediate values, and comparing the final results. This problem requires only sequential code. It needs no procedures or functions other than the builtin sqrt function.

Make sure that you prompt the user of your program with good description of what you are asking for with each value read. Please verify your triangle coordinates by echoing back the values that you have read into your program. Also provide detailed descriptions for each of your results.

The corners of the triangle will be input as two points on a grid, the first corner of the triangle, point A will be at the origin (or 0,0) (Ax=0, Ay = 0). This will reduce the amount of input required.

Check your program with Bx = 0, By = 3, Cx = 4, and Cy = 0. The areas should be: A1 = A2 = 6.

The origin is corner A. (Ax=0, Ay = 0). The next point input, point B is represented by an X and a Y value (Bx, By). The last point C will be located by Cx, Cy.

With these values compute, print and verify the following:

  1. The length of the side, Lab = sqrt((Ax-Bx)2 + (Ay-By)2)
  2. The length of the side, Lbc = sqrt((Bx-Cx)2 + (By-Cy)2)
  3. The length of the side, Lca = sqrt((Cx-Ax)2 + (Cy-Ay)2)
  4. The area by method 1: A1 = abs(((AxBy-AyBx)+(BxCy-ByCx)+(CxAy-CyAx))/2)
  5. The perimeter of the triangle: P = Lab + Lbc + Lca
  6. One half of the perimeter of the triangle: S = P/2
  7. The area by method 2: A2 = sqrt( S(S-Lab)(S-Lbc)(S-Lca) )
  8. Also print out the difference in the two areas: A1-2 = A1 - A2
Mark your output with: Place the lab in the instructor hand in box in BUS R6E, the "terminal room".
Instructor: ltaber@pima.edu** Red's Home page** The Pima College Site

Prev Up Next