Question: ------------------------------c++---------------------------------------c++----------------------------------------------c++-------------------------------------------- Question 4 (40 Points) Please create a triangle array that contains the edge lengths of a triangle as integers. Take an integer n from

 ------------------------------c++---------------------------------------c++----------------------------------------------c++-------------------------------------------- Question 4 (40 Points) Please create a triangle array that

------------------------------c++---------------------------------------c++----------------------------------------------c++--------------------------------------------

Question 4 (40 Points) Please create a triangle array that contains the edge lengths of a triangle as integers. Take an integer n from the user that represents the number of triangles and allocate dynamic memory for your triangles. Hint: You can allocate memory for your triangles by using malloc function Assign random numbers for the lengths of edges of the triangles. Your triangles must satisfy the following constraints: 1 G, G; + > b; and b; +6 > ai (5) where az, bi, ci, i = 1, ..., n represent the edge lengths of the triangles. Main part: You must sort triangles by their areas from the smallest one to the largest one in allocated memory. Hint: The best way to calculate ab area of the triangle with sides a, b and c is Heron's formula: A= (s - a)(s c)(s - c) where s = = (a + b + c)/2 (6) To print your output use the following lines of codes: for (int i = 0; i

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!