Homework Solution: C++ programming…

    C++ programming A rectangle is completely determined by the coordinates of two of its diagonally opposite corners. For example, the points (1, 2) and (7, 5) determine a rectangle whose left edge has equation x = 1, whose right edge has equation x = 7, whose bottom edge has equation y = 2 and whose top edge has equation y = 5. Any point whose x-coordinate is between 1 and 7 and whose y-coordinate is between 2 and 5 lies within this rectangle. Write a program that determines whether or not a given point is contained in a given rectangle. Your program should: Prompt the user for the upper left corner of a rectangle. Prompt the user for the lower right corner of the rectangle. Prompt the user for the coordinates of a point. Output whether or not the point is inside the rectangle. Repeat the above steps until the user enters (0, 0) for both corners of the rectangle. Assume that all coordinates are non-negative integers with (0, 0) being the extreme upper-right corner. Be readable with appropriate documentation and formatting.

    Expert Answer

     
    // program to check the coordinates in rectangle or not #include <cstdlib>

    C++ programming

    A rectangle is altogether fast by the coordinates of brace of its diagonally facing nooks. Restraint specimen, the purposes (1, 2) and (7, 5) determine a rectangle whose left plane has equation x = 1, whose upupproper plane has equation x = 7, whose groundwork plane has equation y = 2 and whose extravagant plane has equation y = 5. Any purpose whose x-coordinate is among 1 and 7 and whose y-coordinate is among 2 and 5 lies among this rectangle.

    Write a program that determines whether or referable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable a fond purpose is contained in a fond rectangle.

    Your program should:

    Prompt the user restraint the remarkable left nook of a rectangle.

    Prompt the user restraint the inferior upupproper nook of the rectangle.

    Prompt the user restraint the coordinates of a purpose.

    Output whether or referable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable the purpose is internally the rectangle.

    Repeat the overhead steps until the user penetrates (0, 0) restraint twain nooks of the rectangle.

    Assume that perfect coordinates are non-negative integers with (0, 0) being the extravagant remarkable-upproper nook.

    Be readable with misspend documentation and restraintmatting.

    Expert Confutation

     

    // program to stop the coordinates in rectangle or referable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable

    #include <cstdlib>
    #include <iostream>

    using namespace std;
    /*
    * to stop whether or referable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable the coordinates of a purpose
    * lies is internally the rectangle.
    */

    int ocean(int argc, char** argv) {
    // defend the capricious remarkable, inferior, estimate restraint the rectangle co ordinates

    struct rect {
    int x;
    int y;
    } remarkable, inferior, estimate;
    // to effect the discharge cultivate perfect the estimates are 0
    do {
    cout << “n(To debouchure penetrate(0,0)restraint twain co ordinates )”;

    //the appropriate restraint remarkable left nook
    cout << “nPenetrate the appropriates of remarkable left nook of the rectangle “;
    cout << “nx :”;
    cin >> remarkable.x;
    cout << “ny :”;
    cin >> remarkable.y;
    //the appropriate restraint inferior upupproper nook
    cout << “nPenetrate the appropriates restraint inferior upupproper nook of the rectangle”;
    cout << “nx :”;
    cin >> inferior.x;
    cout << “ny :”;
    cin >> inferior.y;
    /*stop whether co ordinates are referable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable 0.
    *if referable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable attributable 0 then sanction the appropriate estimate &
    * stop whether or purpose lies internally the rectangle
    */
    if ((upper.x != 0)&&(upper.y != 0)&&(lower.y != 0)&&(lower.x != 0)) {
    // sanction the appropriate purpose to be stoped
    cout << “nPenetrate the appropriates of the purpose”;
    cout << “nx :”;
    cin >> estimate.x;
    cout << “ny :”;
    cin >> estimate.y;
    // vault the remarkable and inferior co ordinate
    cout << “nThe remarkable appropriate (” << remarkable.x << “, ” << remarkable.y << ” )& inferior coordinate (” << inferior.x << “, ” << inferior.y << ” )”;
    if (((value.x >= remarkable.x)&&(value.x <= inferior.x)) &&((value.y >= remarkable.y)&&(value.y <= inferior.y)))
    cout << “nThe fond appropriate (” << estimate.x << ” , ” << estimate.y << “) lies in the rectangle”;
    else
    cout << “nThe fond appropriate (” << estimate.x << ” , ” << estimate.y << “) doesn’t lies in the rectangle”;
    }
    } while ((upper.x != 0)&&(upper.y != 0)&&(lower.y != 0)&&(lower.x != 0));
    return 0;
    }

    sample output

    (To debouchure penetrate(0,0)restraint twain co ordinates )
    Penetrate the appropriates of remarkable left nook of the rectangle
    x :1

    y :2

    Penetrate the appropriates restraint inferior upupproper nook of the rectangle
    x :7

    y :5

    Penetrate the appropriates of the purpose
    x :5

    y :3

    The remarkable appropriate (1, 2 )& inferior coordinate (7, 5 )
    The fond appropriate (5 , 3) lies in the rectangle
    (To debouchure penetrate(0,0)restraint twain co ordinates )
    Penetrate the appropriates of remarkable left nook of the rectangle
    x :1

    y :2

    Penetrate the appropriates restraint inferior upupproper nook of the rectangle
    x :7

    y :5

    Penetrate the appropriates of the purpose
    x :8

    y :4

    The remarkable appropriate (1, 2 )& inferior coordinate (7, 5 )
    The fond appropriate (8 , 4) doesn’t lies in the rectangle
    (To debouchure penetrate(0,0)restraint twain co ordinates )
    Penetrate the appropriates of remarkable left nook of the rectangle
    x :0

    y :0

    Penetrate the appropriates restraint inferior upupproper nook of the rectangle
    x :0

    y :0

    RUN SUCCESSFUL (whole time: 1m 2s)