1

The question is to write a function that returns a bounding rectangle for a set of points in a two dimensional plane. SIZE is two. I know the points will come in this format {double, double} and I know how to create the bounding rectangle. I can't seem to grab the points though. I tried iterating like this.

Rectangle2D getRectangle(const double points[][SIZE], int s) {
for (int i = 0; i < s; i++) {
    for (int j = 0; j < SIZE; j++) {
        cout << points[s][SIZE] << endl;
    }
}
// will put these points in after i figure out the iteration.
Rectangle2D rekt(x, y, width, height);
return rekt;
}
2
  • what is x,y,width and height? Anyways in cout << points[s][SIZE] << endl; should be cout << points[i][j] << endl; (observe i & j), if you want to print matrix. Commented May 8, 2015 at 4:57
  • those are variables that im going to assign from the values the array should return. I should have left them out for clarity. I just need to figure out how to iterate correctly. Commented May 8, 2015 at 4:58

2 Answers 2

1

You are accessing the same element element every time, because s and SIZE remain constant. You have to access it like this points[i][j] . And I'm not sure, but i think you can't pass SIZE within the array argument, you should pass it as an additional parameter. Good luck ;)

Sign up to request clarification or add additional context in comments.

1 Comment

@McNabb ok, there I was not really sure ;)
1

Here you go.

for (int i = 0; i < s; i++) {
    for (int j = 0; j < SIZE; j++) {
        cout << points[i][j] << endl; //observe i,j
    }
}

In above case you are iterating row-wise. If you want to iterate column-wise then following will work.

for (int j = 0; j < SIZE; j++) {
   for (int i = 0; i < s; i++) {
            cout << points[i][j] << endl; //observe i,j
        }
    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.