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

Question #156848

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). For example:

a. (0, 0) is the origin

b. (4, 0) is on the x-axis

c. (0, -3) is on the y-axis

d. (-2, 3) is in the 2nd quadrant

Print the output for 7 different inputs; the origin, x-axis, y-axis, 1st quadrant, 2nd quadrant, 3rd quadrant or 4th quadrant.


1
Expert's answer
2021-01-21T16:14:54-0500
#include <iostream>

using namespace std;

int main() {
    cout << "x: ";
    int x = 0;
    cin >> x;
    cout << "y: ";
    int y = 0;
    cin >> y;
    if (x == 0 && y == 0) {
        cout << "the origin" << endl;
    }
    if (x == 0 && y != 0) {
        cout << "the y-axis" << endl;
    }
    if (x != 0 && y == 0) {
        cout << "the x-axis" << endl;
    }
    if (x > 0 && y > 0) {
        cout << "1st quadrant" << endl;
    }
    if (x < 0 && y > 0) {
        cout << "2nd quadrant" << endl;
    }
    if (x < 0 && y < 0) {
        cout << "3rd quadrant" << endl;
    }
    if (x > 0 && y < 0) {
        cout << " 4th 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