Point in Rectangle Write a program that determines whether points specified by t
ID: 3618115 • Letter: P
Question
Point in RectangleWrite a program that determines whether points specified by the user are inside or outside of a rectangle also specified by the user.
Use integer coordinates. ?? X coordinates increase from left to right. ?? Y coordinates increase from top to bottom.
User Interface ?? Get coordinates of the rectangle from the user. ?? If invalid, output error message and let user tryagain. ?? Keep trying indefinitely, until user gets it right. ?? Repeatedly ask user for coordinates of a point. ?? Let user enter 0 0 to quit. ?? Say whether point is inside or outside the rectangle. ?? Consider the boundary inside. ?? Keep asking for another point until the user enters 0 0.
Specification ?? Use structs to represent points and rectangles.
#include <stdio.h>
int main() { double x, y, w, h, x1, y1;
printf("Enter the rectangle's top-leftcoordinates, width and height:"); scanf("%lg, %lg, %lg, %lg", &x, &y,&w, &h);
printf("Enter the points coordinates:"); scanf("%lg, %lg", &x1, &y2);
if ((x1 >= x) && (x1<= (x+w) )&& (y1 >= y) && (y1 <= (y + h) ) ) { printf("The point is insidethe rectangle."); } else { printf("The point is outsidethe rectangle."); }
return 0; }
Can someone help me with this ? #include <stdio.h>
int main() { double x, y, w, h, x1, y1;
printf("Enter the rectangle's top-leftcoordinates, width and height:"); scanf("%lg, %lg, %lg, %lg", &x, &y,&w, &h);
printf("Enter the points coordinates:"); scanf("%lg, %lg", &x1, &y2);
if ((x1 >= x) && (x1<= (x+w) )&& (y1 >= y) && (y1 <= (y + h) ) ) { printf("The point is insidethe rectangle."); } else { printf("The point is outsidethe rectangle."); }
return 0; }
Can someone help me with this ?
Explanation / Answer
#include <iostream>
using namespace std;
int main()
{
double x, y, w, h, x1,y1;
cout<<"Enter the rectangle's top-leftcoordinates, width and height:"<<endl;
cin>>x>>y>>w>>h;
cout<<"Enter the pointscoordinates:"<<endl;
cin>>x1>>y1;
if ((x1 >= x) &&(x1<= (x+w) ) && (y1 >= y) && (y1 <= (y +h) ) )
{
cout<<"The point falls inside therectangle."<<endl;
}
else
{
cout<<"The point falls outside therectangle."<<endl;
}
return 0;
}