Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that generate random triangles and determine if they are acute.

ID: 3622060 • Letter: W

Question

Write a program that generate random triangles and determine if they are acute. The program has three files point.h, point.c, hw7p2.c:

point.h
This header file, which is given to you (do NOT alter any of its contents), declares the
following functions:
//point.h
void randPoint(int* ptr_x, int* ptr_y);
double distance(int x1, int y1, int x2, int y2);
int isAcute(int x1, int y1, int x2, int y2, int x3, int y3);

point.c
This source file, which should #include "point.h" and any other necessary library headers, implements the above functions:
randPoint(ptr x, ptr y)
   generates a random point (x,y), where both x and y are integers in the range [-
   10,10], and puts the values in the memory where ptr_x and ptr_y point to.
   Hint: rand()%21 generates a random number between 0 and 20.
distance(x1,y1,x2,y2)
   returns the distance between the two points (x1, y1) and (x2, y2)

     ((x1-x2)(x1-x2)+(y1-y2)(y1-y2))

isAcute(x1,y1,x2,y2,x3,y3)

   returns 1 if the triangle formed by the three points (x1, y1), (x2, y2), (x3, y3) is acute, otherwise it returns 0. A triangle is acute if and only if

   a*a+b*b>c*c, b*b+c*c>a*a, and c*c+a*a>b*b,

   where a, b, c are the distances between pairs of points.

hw7p2.c

This file, which should #include "point.h" and any other necessary library headers, has the main function that asks the user to input an integer as random seed. Then it uses the functions you defined in point.c to generate three random points, and tests if the triangle formed by them is acute. Repeat the test N=5 times.

A sample run is shown below:

(~)$ a.out

seed: 123

(0,10),(10,2),(5,0): not acute

(-9,8),(7,-1),(-2,9): not acute

(6,1),(5,-3),(-8,8): not acute

(2,2),(-2,-3),(1,7): not acute

(-5,5),(2,0),(4,7): acute

Explanation / Answer

Hope this helps. Let me know if you have any questions. Please rate. :) It says not to alter the header file (point.h), but since it wasn't given, I went ahead an implemented it myself to test this code. Feel free to use the header file that was given to you prior, and if anything doesn't match up, let me know and I can make modifications for you. I tried to stay exact with what you posted here though. ------------point.h (you can ignore)---------------- #ifndef H_POINTH #define H_POINTH //point.h void randPoint(int* ptr_x, int* ptr_y); double distance(int x1, int y1, int x2, int y2); int isAcute(int x1, int y1, int x2, int y2, int x3, int y3); #endif ---------------point.c------------------------------- #include "point.h" // required for "rand" function #include // required for "sqrt" function #include void randPoint(int* ptr_x, int* ptr_y) { int temp; temp = (rand() % 21) - 10; // random number between -10 and 10 (*ptr_x) = temp; temp = (rand() % 21) - 10; // random number between -10 and 10 (*ptr_y) = temp; } double distance(int x1, int y1, int x2, int y2) { double x = (x1 - x2) * 1.0; double y = (y1 - y2) * 1.0; return sqrt(x*x + y*y); } int isAcute(int x1, int y1, int x2, int y2, int x3, int y3) { // if any of these three conditions are false, return false (0) double a = distance(x1, y1, x2, y2); double b = distance(x1, y1, x3, y3); double c = distance(x2, y2, x3, y3); if (a*a + b*b
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote