Write a program that uses a method called quadrant that accepts as parameters a
ID: 3768254 • Letter: W
Question
Write a program that uses a method called quadrant that accepts as parameters a pair of double values representing an (x, y) point and
returns the quadrant number for that point. Recall that quadrants are numbered as integers from 1 to 4 with the
upper-right quadrant numbered 1 and the subsequent quadrants numbered in a counterclockwise fashion:
Notice that the quadrant is determined by whether the x and y coordinates are positive or negative numbers. Return 0
if the point lies on origin (point 0,0). return a -1 if the point is on the x axis, return -2 if the point is on the y axis.
For example, the call of quadrant(-2.3, 3.5) should return 2 and the call of
quadrant(4.5, -4.5) should return 4.
The values for x and y should be entered by the user, and the where the point is located should be output by another method
Name the class project3
Explanation / Answer
#include<iostream.h>
#include<conio.h>
class project3
{
public:
int quadrant(double x, double y)
{
if(x==0 && y==0)
return 0;
if(x==0 )
return -1;
if(y==0)
return -2;
if(x>0 && y>0)
return 1;
if(x<0 && y>0)
return 2;
if(x<0 && y<0)
return 3;
if(x>0 && y<0)
return 4;
}
};
void main()
{
project3 o;
double x,y;
cout<<"Enter x co-ordinate";
cin>>x;
cout<<"Enter y co-ordinate";
cin>>y;
double d=o.quadrant(x,y);
cout<<"Point is in "<<d<<" Quadrant";
getch();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.