Answer To: Fall 2019 CMSC 140 Programming Project 5: Magic Square Chapter(s) Covered: · Chapter 1-8 Concepts...
Aditya answered on Aug 15 2021
#include
using namespace std;
// Global constants
const int ROWS = 3; // The number of rows in the array
const int COLS = 3; // The number of columns in the array
const int MIN = 1; // The value of the smallest number allowed
const int MAX = 9; // The value of the largest number allowed
// Function prototypes
bool isMagicSquare(int arrayRow1[], int arrayRow2[], int arrayRow3[], int size);
bool checkRange(int arrayRow1[], int arrayRow2[], int arrayRow3[], int size, int min, int max);
bool checkUnique(int arrayRow1[], int arrayRow2[], int arrayRow3[], int size);
bool checkRowSum(int arrayrow1[], int arrayrow2[], int arrayrow3[], int size);
bool checkColSum(int arrayrow1[], int arrayrow2[], int arrayrow3[], int size);
bool checkDiagSum(int arrayrow1[], int arrayrow2[], int arrayrow3[], int size);
void fillArray(int arrayRow1[], int arrayRow2[], int arrayRow3[], int size);
void showArray(int arrayrow1[], int arrayrow2[], int arrayrow3[], int size);
int main()
{
/* Define a Lo Shu Magic Square using 3 parallel arrays corresponding to each row of the grid */
int magicArrayRow1[COLS], magicArrayRow2[COLS],magicArrayRow3[COLS];
char userInput= 'N';
do
{
fillArray(magicArrayRow1, magicArrayRow2, magicArrayRow3, COLS);
showArray(magicArrayRow1, magicArrayRow2, magicArrayRow3, COLS);
if (isMagicSquare(magicArrayRow1, magicArrayRow2, magicArrayRow3, COLS))
{
cout << "\nThis is Lo Shu magic square." << endl;
}
else
{
cout << "\nThis is not Lo Shu magic square." <<...