Answer to Question #156653 in C++ for Raihan Afryna binti Raizam

Question #156653

Write a program that prompts the user to input the x-y coordinate of a point in a Cartesian plane.

The program should then output a message indicating whether the point is the origin, is located

on the x-axis or y-axis, or appears in particular quadrant (1st quadrant, 2nd quadrant, 3rd quadrant

or 4th quadrant).


1
Expert's answer
2021-01-19T12:33:07-0500
 #include <iostream>

using namespace std;

int main()
{
	int x, y;
	cout << "Enter x and y: ";
	cin >> x >> y;

	if (x == 0 && y == 0)
		cout << "Point is the origin";
	else if (y == 0) //if y is 0 then x != 0 otherwise point would be the origin
		cout << "Point located on x-axis";
	else if (x == 0)
		cout << "Point located on y-axis";
	else if (y > 0) {
		if (x > 0)
			cout << "Point is a part of first quadrant";
		else
			cout << "Point is a part of second quadrant";
	}
	else { /*we don't need to check if y < 0 because we already know that
			y != 0 and y isn't positive*/
		if (x < 0)
			cout << "Point is a part of third quadrant";
		else
			cout << "Point is a part of fourth quadrant";
	}
	cout << endl;

	return 0;
}

I'm not sure if it okay for you to use "using namespace std", usually it's okay for learning purposes, but if it's not, then that line should be removed and:

how code should be changed:
cin to std::cin
cout to std::cout
end to std::endl

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

Raihan
20.01.21, 06:34

Thank you!!!!

Leave a comment

LATEST TUTORIALS
New on Blog