[Solved] Language C Magic Square Matrix Two Dimensional Arrays Sum Row Sum Column Sum Main Diagonal Q37267280
The language is c++
A magic square is a matrix (two dimensional arrays) in which thesum of each row, sum of each column, sum of the main diagonal, andsum of the reverse diagonal are all the same value.
You are to code a program to determine if a giventwo-dimensional array (that will be read in from a file) is a magicsquare or not. The functions you will need to code are asfollows:
Code a function/method for each of the following:
-
Read data into the matrix
-
Print the matrix on the screen
-
Sum a row given the index for that row
-
Sum a column given the index for that column
-
Sum the main diagonal
-
Sum the reverse diagonal
-
Determine if the two dimensional array is a magic square
The main method will read the size of the array outside of thewhile loop. Then inside the while loop it will call all the methodsgiven above to read the data into the matrix, print the matrix,print all the row sums, print all the column sums, and print bothdiagonals. Then the program will determine if the matrix is a magicsquare and print an appropriate message. The next size should beread in at the end of the while loop. The main will continue withthe next matrix in the data file, until a size of -1 is reached.See the Additional Notes on Two Dimension Arrays for more help withthis assignment. Do not use dynamic arrays or pointers inthis solution. Follow the solution given in the video andin Additional Notes on Two Dimension Arrays.
Sample Output:
The first part of the output should look similar to this:
=========
= Square 1=
=========
8 1 6
3 5 7
4 9 2
The sum of row 0 is 15
The sum of row 1 is 15
The sum of row 2 is 15
The sum of column 0 is 15
The sum of column 1 is 15
The sum of column 2 is 15
The main diagonal is 15
The other diagonal is 15
This matrix is a magic box!
Data File:
Paste everything below this block of text into a notepad file.Your input file must appear exactly as it below and include all ofthis data in the same file.
3
8 1 6
3 5 7
4 9 2
7
30 39 48 1 10 19 28
38 47 7 9 18 27 29
46 6 8 17 26 35 37
5 14 16 25 34 36 45
13 15 24 33 42 44 4
21 23 32 41 43 3 12
22 31 40 49 2 11 20
4
48 9 6 39
27 18 21 36
15 30 33 24
12 45 42 3
3
6 2 7
1 5 3
2 9 4
4
3 16 2 13
6 9 7 12
10 5 11 8
15 4 14 1
5
17 24 15 8 1
23 5 16 14 7
4 6 22 13 20
10 12 3 21 19
11 18 9 2 25
7
30 39 48 1 10 28 19
38 47 7 9 18 29 27
46 6 8 17 26 37 35
5 14 16 25 34 45 36
13 15 24 33 42 4 44
21 23 32 41 43 12 3
22 31 40 49 2 20 11
-1
This is what I have so far:
#include <iostream>
#include <fstream>
using namespace std;
int box[10][10];
int size;
int readSize(ifstream& fin) {
fin >> size;
}
int readData(ifstream& fin) {
}
void printMatrix() {
}
int sumRow(int r) {
}
int sumCol(int c) {
}
int sumMainDiagonal() {
}
int sumReverseDiagonal() {
}
bool isMagic() {
}
int main() {
}
Expert Answer
Answer to The language is c++ A magic square is a matrix (two dimensional arrays) in which the sum of each row, sum of each column… . . .
OR

