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;
}
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;