Answer to Question #350400 in C++ for kristine

Question #350400

Write a C++ function that determines in which quadrant a line


drawn from the origin resides. The determination of the quadrant


is made using the angle that the line makes with the positive x


axis as follows:


Note: if the angle is exactly 0,90,180,270 degrees the


corresponding line does not reside in any quadrant but lies on an


axis.


Angle from the


positive x axis Quadrant


Between 0 and 90 degrees =1


Between 90 and 180 degrees =2


Between 180 and 270 degrees =3


Between 270 and 360 degrees = 4

1
Expert's answer
2022-06-14T08:42:55-0400
#include <iostream>
using namespace std;

int main(void) {
    
    int angle, quadrant = 0;
    
    cout<<"angle: ";
    cin>>angle;
    if(angle>=360)
        angle = angle%360;

    if(angle>0 && angle<90)
        quadrant = 1;
    else if(angle>90 && angle<180)
        quadrant = 2;
    else if(angle>180 && angle<270)
        quadrant = 3;
    else if(angle>270 && angle<360)
        quadrant = 3;    
    else if(angle==0||angle==180)
        cout<<"The line does not reside in any quadrant but lies on an axis X"<<endl;    
    else if(angle==90||angle==270)
        cout<<"The line does not reside in any quadrant but lies on an axis Y"<<endl;            
     if(quadrant!=0)
        cout<<"quadrant: "<<quadrant<<endl;
    
  return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS