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

Determination of Location Please write a C++ program that determines the locat j

ID: 638877 • Letter: D

Question

Determination of Location Please write a C++ program that determines the locat joli of user?input point in a 2D space. The Figure below shows four quadrants, origin. the x- and y-axis. Figure 1: Quadrants The program should at least (lo the following. 1. The program instructs the user to input the coordinates of point. 2. The pi gram determines if the point is in one of four quadrants. 3. The program determines if the point is at the origin. 4. The program determines if the point is the positive or negative part of x-axis. 5. The program determines if the point is in the positive or negative part of y-axis. 6. The program display the result properly.

Explanation / Answer

//Cpp program that prompts to enter x and y values of point
//on the 2d coordinate system and determines the quadrant,
//is the point at the origin , is the point on the negative of x
//axis and or the point on the negative y axis
#include<iostream>
using namespace std;
//funtion prototypes
int findQuadrant(int x,int y);
bool isAtOrigin(int x,int y);
bool isNegativeXaxis(int x);
bool isNegativeYaxis(int y);

int main()
{

   //declare variables to read x and y -positions
   int x ;
   int y;

   //read x and y values
   cout<<"Enter x and y -Positions "<<endl;
   cin>>x>>y;


   //calling the method findQuadrant with x and y values
   int quadrant=findQuadrant(x,y);
   if(quadrant!=-1)
       cout<<"QUADRANT OF the Point ,P("<<x<<" ,"<<y<<") is "<<quadrant<<endl;

   if(isAtOrigin(x,y))
       cout<<x<<" and "<<y<<" is at the origin"<<endl;
   else
       cout<<x<<" and "<<y<<" is not at the origin"<<endl;
  
   if(isNegativeXaxis(x))
       cout<<"The point "<<x<<" and "<<y<<" is on negative part of x-axis"<<endl;
   else
       cout<<"The point "<<x<<" and "<<y<<" is not on negative part of x-axis"<<endl;


   if(isNegativeYaxis(y))
       cout<<"The point "<<x<<" and "<<y<<" is on negative part of y-axis"<<endl;
   else
       cout<<"The point "<<x<<" and "<<y<<" is not on negative part of y-axis"<<endl;
  

   system("pause");
}

//The method findQuadrant that accepts x and y
//and returns the quadrant number.

int findQuadrant(int x,int y)
{

   int QUADRANT=-1;
   if(x>0 &&y>0)
       QUADRANT=1;
   else if(x<0 &&y>0)
       QUADRANT=2;
   else if(x<0 &&y<0)
       QUADRANT=3;
   else if(x>0 &&y<0)
       QUADRANT=4;
  

   return QUADRANT;
}

//The method isAtOrigin checks if the x and y at the origin
//and return true if the point at the origin.

bool isAtOrigin(int x,int y)
{
   return (x==0 && y==0);
}

//The method isNegativeXaxis that accept the x value
//and returns true if the point x on the negative side
bool isNegativeXaxis(int x)
{
   return x<0;
}
//The method isNegativeYaxis that accept the y value
//and returns true if the point y on the negative sid
bool isNegativeYaxis(int y)
{
   return y<0;
}


-------------------------------------------------------------------------------------------------------------------

Sample Op:

Enter x and y -Positions
0 0
0 and 0 is at the origin
The point 0 and 0 is not on negative part of x-axis
The point 0 and 0 is not on negative part of y-axis
--------------------------------------------------

Sample run

Enter x and y -Positions
1 1
QUADRANT OF the Point ,P(1 ,1) is 1
1 and 1 is not at the origin
The point 1 and 1 is not on negative part of x-axis
The point 1 and 1 is not on negative part of y-axis

--------------------------------------------------

Sample run

Enter x and y -Positions
1 -1
QUADRANT OF the Point ,P(1 ,-1) is 4
1 and -1 is not at the origin
The point 1 and -1 is not on negative part of x-axis
The point 1 and -1 is on negative part of y-axis

--------------------------------------------------

Sample run

Enter x and y -Positions
-1 1
QUADRANT OF the Point ,P(-1 ,1) is 2
-1 and 1 is not at the origin
The point -1 and 1 is on negative part of x-axis
The point -1 and 1 is not on negative part of y-axis
--------------------------------------------------

Sample run
Enter x and y -Positions
-1 -1
QUADRANT OF the Point ,P(-1 ,-1) is 3
-1 and -1 is not at the origin
The point -1 and -1 is on negative part of x-axis
The point -1 and -1 is on negative part of y-axis

Hope this helps you.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote