# Assume that a new type called POINT has been defined– it is a structure consisting of two fields, x and y , both of type double. Assume two variables p1 and p2 of type POINT have been declared . Assume that p1 has already been initialized. Write some code that makes p2 the reflection of p1 : in other words, give p2’s x field the value of p1’s y field, and give p2’s y field, the value of p1’s x field.

4

### CHALLENGE:

Assume that a new type called POINT has been defined– it is a structure consisting of two fields, x and y , both of type double . Assume two variables p1 and p2 of type POINT have been declared . Assume that p1 has already been initialized . Write some code that makes p2 the reflection of p1 : in other words, give p2’s x field the value of p1’s y field, and give p2’s y field, the value of p1’s x field.

### SOLUTION:

```
POINT temp;

temp.x = p1.x;
temp.y = p1.y;

p1.x = p2.y;
p1.y = p2.x;

p2.x = temp.y;
p2.y = temp.x;

```

• joey says:

use without quotes

• Matthew Maennche says:

Joey, I have updated the post. Thank You for your feedback.

• Derek says:

POINT temp;

temp.x = p1.x;
temp.y = p1.y;

p1.x = p2.x;
p1.y = p2.y;

p2.x = temp.x;
p2.y = temp.y;

works

• Student says:

POINT temp;

temp.x = p1.x;
temp.y = p1.y;

p1.x = p2.x;
p1.y = p2.y;

p2.x = temp.x;
p2.y = temp.y;