Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Given the variables top, left, right, and bottom representing the coordinates

ID: 441895 • Letter: 1

Question

1. Given the variables top, left, right, and bottom representing the coordinates of a rectangle's upper left and lower right corners, and variables ptX and ptY, representing the coordinates of a point, write a condition to test if the point is outside the rectangle. Assume that x increases to the right and that y increases to the top. 2.Write a fragment of code that accepts integers from the user until a negative number is entered. The prompt should be "Enter a number (negative to quit):" Add up the numbers and print the sum (not including the negative number). Assume and use the following declarations

Explanation / Answer

Answer-1

#include <iostream>
using namespace std;

int main()
{
int top, left, right,bottom ;
int pX,pY;

cout<<" Enter left point :";
cin>>left;
cout<<" Enter top point :";
cin>>top;
cout<<" Enter right point :";
cin>>right;
cout<<" Enter bottom point :";
cin>>bottom;

if(right<left || top<bottom)
{
cout<<" Invalid coordinates";
return 0;
}

cout<<" Enter X point :";
cin>>pX;
cout<<" Enter Y point :";
cin>>pY;

if((pX>=left && pX<=right)&& (pY>=bottom && pY<=top))
{
cout<<" Point inside the rectangle";
}
else
{
cout<<" Point outside the rectangle";
}

return 0;
}

Answer-2

int sum = 0; int num;
do
{
cout << "Enter a number (negative to quit):"
cin >> num;
if(num>=0)
sum=sum+num;
}while(num >=0);

cout<<" sum is:"<<sum;