function which given a point and a value of the area of a square as input parameter returns four squ

Posted by osabri on Stack Overflow See other posts from Stack Overflow or by osabri
Published on 2010-04-26T06:59:31Z Indexed on 2010/04/26 7:03 UTC
Read the original article Hit count: 320

Filed under:

in this code i don't understand why teacher used sometimes +value, - value;

/******************************************/
// function void returnSquares(POINT point, int value)
void returnSquares(POINT point, int value) {
    SQUARE tabSquares[4];       // table of squares that we are creating
    int i;

    // getting points of 4 squares
    // for first square input point is point C
    tabSquares[0].pointA.dimX = point.dimX - value;
    tabSquares[0].pointA.dimY = point.dimY + value;
    tabSquares[0].pointB.dimX = point.dimX;
    tabSquares[0].pointB.dimY = point.dimY + value;
    tabSquares[0].pointC.dimX = point.dimX;
    tabSquares[0].pointC.dimY = point.dimY;
    tabSquares[0].pointD.dimX = point.dimX - value;
    tabSquares[0].pointD.dimY = point.dimY; 

    // for 2nd square input point is point D
    tabSquares[1].pointA.dimX = point.dimX;
    tabSquares[1].pointA.dimY = point.dimY + value;
    tabSquares[1].pointB.dimX = point.dimX + value;
    tabSquares[1].pointB.dimY = point.dimY + value;
    tabSquares[1].pointC.dimX = point.dimX + value;
    tabSquares[1].pointC.dimY = point.dimY;
    tabSquares[1].pointD.dimX = point.dimX;
    tabSquares[1].pointD.dimY = point.dimY; 

    // for 3rd square input point is point A
    tabSquares[2].pointA.dimX = point.dimX;
    tabSquares[2].pointA.dimY = point.dimY;
    tabSquares[2].pointB.dimX = point.dimX + value;
    tabSquares[2].pointB.dimY = point.dimY;
    tabSquares[2].pointC.dimX = point.dimX + value;
    tabSquares[2].pointC.dimY = point.dimY - value;
    tabSquares[2].pointD.dimX = point.dimX;
    tabSquares[2].pointD.dimY = point.dimY - value;

    // for 4th square input point is point B
    tabSquares[3].pointA.dimX = point.dimX - value;
    tabSquares[3].pointA.dimY = point.dimY;
    tabSquares[3].pointB.dimX = point.dimX;
    tabSquares[3].pointB.dimY = point.dimY;
    tabSquares[3].pointC.dimX = point.dimX;
    tabSquares[3].pointC.dimY = point.dimY - value;
    tabSquares[3].pointD.dimX = point.dimX - value;
    tabSquares[3].pointD.dimY = point.dimY - value;


    for (i=0; i<4; i++) {
        printf("Square number %d\n",i); // now we print parameters of each point in current Square
        printf("point A x= %0.2f y= %0.2f\n",tabSquares[i].pointA.dimX,tabSquares[i].pointA.dimY); 
        printf("point B x= %0.2f y= %0.2f\n",tabSquares[i].pointB.dimX,tabSquares[i].pointB.dimY);
        printf("point C x= %0.2f y= %0.2f\n",tabSquares[i].pointC.dimX,tabSquares[i].pointC.dimY);
        printf("point D x= %0.2f y= %0.2f\n",tabSquares[i].pointD.dimX,tabSquares[i].pointD.dimY);
    }
}

© Stack Overflow or respective owner

Related posts about c