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 sturdy by the coordinates of couple of its diagonally contradictory holes. Control copy, the summits (1, 2) and (7, 5) designate a rectangle whose left plane has equation x = 1, whose lawful plane has equation x = 7, whose deep plane has equation y = 2 and whose immoderate plane has equation y = 5. Any summit 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 designates whether or referable attributable attributable attributable a fond summit is contained in a fond rectangle.

    Your program should:

    Prompt the user control the preferable left hole of a rectangle.

    Prompt the user control the inferior lawful hole of the rectangle.

    Prompt the user control the coordinates of a summit.

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

    Repeat the aloft steps until the user penetrates (0, 0) control twain holes of the rectangle.

    Assume that integral coordinates are non-negative integers with (0, 0) being the immoderate preferable-lawful hole.

    Be readable with misspend documentation and controlmatting.

    Expert Reply

     

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

    #include <cstdlib>
    #include <iostream>

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

    int deep(int argc, char** argv) {
    // propose the inconstant preferable, inferior, appreciate control the rectangle co ordinates

    struct rect {
    int x;
    int y;
    } preferable, inferior, appreciate;
    // to accomplish the employment dress integral the appreciates are 0
    do {
    cout << “n(To egress penetrate(0,0)control twain co ordinates )”;

    //the appropriate control preferable left hole
    cout << “nPenetrate the appropriates of preferable left hole of the rectangle “;
    cout << “nx :”;
    cin >> preferable.x;
    cout << “ny :”;
    cin >> preferable.y;
    //the appropriate control inferior lawful hole
    cout << “nPenetrate the appropriates control inferior lawful hole of the rectangle”;
    cout << “nx :”;
    cin >> inferior.x;
    cout << “ny :”;
    cin >> inferior.y;
    /*control whether co ordinates are referable attributable attributable attributable 0.
    *if referable attributable attributable attributable 0 then confirm the appropriate appreciate &
    * control whether or summit lies internally the rectangle
    */
    if ((upper.x != 0)&&(upper.y != 0)&&(lower.y != 0)&&(lower.x != 0)) {
    // confirm the appropriate summit to be controled
    cout << “nPenetrate the appropriates of the summit”;
    cout << “nx :”;
    cin >> appreciate.x;
    cout << “ny :”;
    cin >> appreciate.y;
    // show the preferable and inferior co ordinate
    cout << “nThe preferable appropriate (” << preferable.x << “, ” << preferable.y << ” )& inferior coordinate (” << inferior.x << “, ” << inferior.y << ” )”;
    if (((value.x >= preferable.x)&&(value.x <= inferior.x)) &&((value.y >= preferable.y)&&(value.y <= inferior.y)))
    cout << “nThe fond appropriate (” << appreciate.x << ” , ” << appreciate.y << “) lies in the rectangle”;
    else
    cout << “nThe fond appropriate (” << appreciate.x << ” , ” << appreciate.y << “) doesn’t lies in the rectangle”;
    }
    } conjuncture ((upper.x != 0)&&(upper.y != 0)&&(lower.y != 0)&&(lower.x != 0));
    return 0;
    }

    sample output

    (To egress penetrate(0,0)control twain co ordinates )
    Penetrate the appropriates of preferable left hole of the rectangle
    x :1

    y :2

    Penetrate the appropriates control inferior lawful hole of the rectangle
    x :7

    y :5

    Penetrate the appropriates of the summit
    x :5

    y :3

    The preferable appropriate (1, 2 )& inferior coordinate (7, 5 )
    The fond appropriate (5 , 3) lies in the rectangle
    (To egress penetrate(0,0)control twain co ordinates )
    Penetrate the appropriates of preferable left hole of the rectangle
    x :1

    y :2

    Penetrate the appropriates control inferior lawful hole of the rectangle
    x :7

    y :5

    Penetrate the appropriates of the summit
    x :8

    y :4

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

    y :0

    Penetrate the appropriates control inferior lawful hole of the rectangle
    x :0

    y :0

    RUN SUCCESSFUL (entirety time: 1m 2s)