Magic Square

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
class  Magic_Square 

{ 
private:

int  Size;  //  Number  of  rows  and  columns  in  the  Magic  Square  array

int MagSq[5][5]; // Magic Square matrix 

int ColSums[5]; // Array of column sums 

int RowSums[5]; // Array of row sums 

int Diag1; // Sum of major diagonal 

int Diag2; // Sum of minor diagonal

bool  Sum_Criteria;  //  Was  the  sum  test  met?

bool Sequence_Criteria; // Was the sequence test met? 

void Calc_RowSums(); // Calculates the row sums

void Calc_ColSums(); // Calculates the column sums 

void Calc_Diags(); // Calculates the two diagonal sums

public:

Magic_Square();  //  Constructor  initializes  all  member  variables

void Input_Values(); // Reads the input matrix values 

void Output_Values(); // Writes the output matrix values

void Seq_Test(); // Determines if the sequence test was met 

void Sum_Test(); // Determines if the sum test was met

void Evaluate();  //  Determines  and  generates  message whether  a  magic  square  or  not. If  not,  generates  message  about  which  criteria  failed 

}


Here's the outline of the class I've been given to create a program that tests magic squares. A magic square has dimensions nXn (in this case 5X5). Numbers can only go up to 25 and can only be used once. The numbers in all directions must add up to the same number. This program will be tested using input from a .DAT file and will print the values of the array and whether it's a magic square or not to an output file.

The .DAT file:

1
2
3
4
5
6
7
8
9
10
11
12
2	1  3  2  4
3	1  6  8  5  7  3  9  2  4
2	1  5  2  3
3	3  3  3  3  3  3  3  3  3
4	1  6  11  5  3  7  8  16  12  13  4  2  15  9  10  14
5	17  24  1  8  15  23  5  7  14  16  4  6  13  20  22  10  12  19  21  3  11  18  25  2  9
1	1
3       8  1  6  3  5  7  4  9  2
3	3  6  7  4  9  2  8  1  6
4       7  6  12  9  10  11  5  8   13   16   2   3   4   1   15   14  
3	6  1  8  9  4  2  3  7  5
4       1   15   6   12   8   10   3   13   11   5   16   2   14   4   9   17


I really feel like this is beyond my skill level right now. Any input would be appreciated. Let's discuss.

Thank you!
I think it's a good idea to work on raising your skill level.
Topic archived. No new replies allowed.