这是阶级广场的主要功能。
const int max_size = 9;
class Square {
public:
void read(); //the square data is read
bool is_magic(); // determin if the given square is a magic square
private:
int sum_row(int i); // returns the row sum of the ith row
int sum_col(int i); // returns the col sum of the ith row
int sum_maindiag(); // returns the main the main diagonal sum
int sum_other(); // returns the non-main diagonal sum
int size;
int grid[max_size][max_size];
};
void main()
{
cout << "Magic Square Program" << endl << endl;
cout << "Enter a square of integers:" << endl;
Square s;
s.read();
if (s.is_magic()) cout << "That square is magic!" << endl;
else cout << "That square is not magic." << endl;
}