Language should be in C++ for visual basic or whichever program. Write a program
ID: 3873016 • Letter: L
Question
Language should be in C++ for visual basic or whichever program.
Write a program that takes the X-Y coordinates of a point in the Cartesian system and displays a message telling either an axis on which the point lies or the quadrant in which it is found. The program should include entries for points located at the origin of the coordinate system and points located on the positive or negative side of an axis. The program should display the original points and the answers based on the format shown in the following lines of outputs: (-1.0, -2.0) is in quadrant III (0.0, 2.5) is on positive Y axis (0.0, 0.0) is at the origin Test your program for the following points:Explanation / Answer
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
char ch='y'; //general character to iterate through the loop
float x,y; //to store the coordinates
while(ch=='y' || ch=='Y')
{
clrscr();
cout<<"Enter x coordinate : ";
cin>>x;
cout<<"Enter y coordinate : ";
cin>>y;
if(x==0.0 && y==0.0) //check if it lies on origin
cout<<"("<<x<<","<<y<<") is at the origin ";
else if(x==0.0 || y==0.0) //if not on origin but any of the axes(x or y)
{
if(x==0.0) //lies on y axis since x is 0
{
if(y>0.0) //positive y axis
cout<<"("<<x<<","<<y<<") is on positive Y axis";
else if(y<0.0) //negative y axis
cout<<"("<<x<<","<<y<<") is on negative Y axis";
}
else if(y==0.0) //lies on x axis since y is 0
{
if(x>0.0) //positive x axis
cout<<"("<<x<<","<<y<<") is on positive X axis";
else if(x<0.0) //negative x axis
cout<<"("<<x<<","<<y<<") is on negative X axis";
}
}
else if(x!=0.0 && y!=0.0) //lies in one of the quadrants
{
cout<<"("<<x<<","<<y<<") is in Quadrant ";
if(x>0.0 && y>0.0) //quadrant I as both x and y are positive
cout<<"I";
else if(x>0.0 && y<0.0) //quadrant IV as x is positive and y is negative
cout<<"IV";
else if(x<0.0 && y>0.0) //quadrant II as x is negative and y is positive
cout<<"II";
else //quadrant III as x is negative and y is negative
cout<<"III";
}
cout<<" Do you want to continue ?(y/n) ";
cin>>ch;
}
getch();
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.