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

C++ progamming Let (xj , yj ), j = 0, . . . , n ? 1 be an arbitrary set of n int

ID: 3910983 • Letter: C

Question

C++ progamming

Let (xj , yj ), j = 0, . . . , n ? 1 be an arbitrary set of n integer-valued coordinates. • Hence the values of xj and yj are integers. • In this question, we define the bounding rectangle as follows. 1. The rectangle has horizontal and vertical edges. 2. It is the smallest rectangle which encloses all the points (xj , yj ), j = 0, . . . , n ? 1. 3. Let the coordinates of the bounding rectangle be (u0, v0), (u1, v1), (u2, v2) and (u3, v3). (u0, v0) = bottom left corner (u1, v1) = bottom right corner (u2, v2) = top right corner (u3, v3) = top left corner • Write a function to compute the bounding rectangle of the points (xj , yj ), j = 0, . . . , n ? 1. • The function signature is given below. Note that the return type is int. int bounding_rect(int n, int x[], int y[], int u[], int v[]); • The return value is the area of the bounding rectangle. The formula for the area A is as follows: A = (u2 ? u0)(v2 ? v0). • Submit your function code as your solution. 1. Write the function only. 2. Do not write a main program. 3. Do not worry about header files (for math, etc.). Assume they are all given to you

Explanation / Answer

int bounding_rect(int n, int x[], int y[], int u[], int v[]) { // 2 points can only form a line, so dont consider less than 3 points if(n < 3) { return 0; } int min_x_left = x[0]; int min_x_right = x[0]; int min_y_up = y[0]; int min_y_down = y[0]; for(int i=0; i min_x_right) { min_x_right = x[i]; } if(x[i] min_y_up) { min_y_up = y[i]; } if(x[i]
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