26.2k views
3 votes
In mathematics, "quadrant I" of the cartesian plane is the part of the plane where x and y are both positive. Given a variable, p that is of type POINT-- a structured type with two fields, x and y, both of type double-- write an expression that is true if and only if the point represented by p is in "quadrant I".

User Chandi
by
6.7k points

1 Answer

0 votes

Answer:

#include <iostream>

using namespace std;

struct Cartesian {

double x;

double y;

};

int main() {

// creating a pointer p of type struct Cartesian

struct Cartesian *p = new Cartesian ;

cout << " Enter x: ";

// accessing the structure variable x by arrow "->"

cin >> p->x;

cout << "Enter y: ";

// accessing the structure variable y by arrow "->"

cin >> p->y;

// expression to check whether x and y lie in Quadrant 1

if (p->x > 0 && p->y > 0) {

cout << "X and Y are in Quadrant 1 ";

}

else

{

cout << "x And y are not in Quadrant 1";

}

// deleting the struct pointer p

delete p;

return 0;

}

Step-by-step explanation:

in order to locate memory in heap, keyword "new" is used in C++ so,

struct Cartesian *p = new Cartesian ;

in order to access data members of the structure using pointer we always use an arrow "->". otherwise a dot oprerator is used to access data members.

in order to check whether x and y lie in 1st quadrent, we must use && operator in our if condition. so

if (p->x > 0 && p->y > 0)

&& will return true iff x and y both are +ve.

deleting the struct pointer p is important beacuse we are allocating memory in heap so heap memory should be used a resource and must be release when not needed otherwise it can cause memory leakage problems. so

delete p;

User Shimon S
by
5.3k points