Magic Square Code

Operator Overloading:
You need to overload the operators : '+' , '-', '!' to swap the matrix as follows:
'-' : to swap all the horizontal numbers in the matrix, symmetrical around the center.
8 1 6
3 5 7
4 9 2

becomes,

6 1 8
7 5 3
2 9 4

'!' : to swap all the vertical number in the matrix, symmetrical around the center.

8 1 6
3 5 7
4 9 2

becomes,

4 9 2
3 5 7
8 1 6

'+': to swap all the horizontal and vertical numbers in the matrix, symmetrical around the center.

8 1 6
3 5 7
4 9 2

becomes,

2 9 4
7 5 3
6 1 8




Help me in these
Last edited on
You could store each matrix as a vector of vectors and then manually code the movement of each element for each operator using temp matrices, but that seems too complicated to be the best solution.

do all the matrices have only one of each digit and the numbers across the center add to 10?
If so, you could take advantage of that.

you can learn about the syntax of overloading operators here: http://www.cplusplus.com/doc/tutorial/classes2/
Last edited on
Topic archived. No new replies allowed.