Help with magic squares assignment please

Hello,
I am very new to C++ and I am having a heck of a time with one of my assignments. I have googled it extensively but it seems like every variation of the magic squares program is either significantly more advanced or basic than what I am supposed to do. I have been provided an inputfile that lists the magic square data in the following format for example:

3
8 1 6
3 5 7
4 9 2
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

This data continues through several increasingly large blocks of numbers. My guidelines for the project are:

1. Process an unknown number of matrices. The input file consists of a number n, indicating the size of the matrix, followed by n rows, one per line. Your program should use functions with appropriate parameters and return values to perform the following steps for each matrix:

a. Void readSquare (n, square) - Read and print n; Read the n rows into a 2-dimensional array, square

b. Void printSquare (n, square) - Print the 2-dimensional array, square; formatted and easy to read

c. bool checkMagic (n, square) - Checks to see if the 2-dimensional array, square is a magic square by first finding the correct sum for each of the rows, columns and diagonals using the formula total = ((1 + n2) / 2 ) * n;
then looping through each row, column and diagonal calling the following functions that you must write – each function will return the sum of the particular row, col, or diagonal

i. int sumRow (row, n, square)– sums the values in a particular row
ii. int sumColumn (col, n, square) – sums the values in a particular column
iii. int sumDiagonal1 – (n, square) sums the values in the left diagonal
iv. int sumdiagonal2 – (n, square) sums the values in the right diagonal
function returns true or false indicating whether or not the matrix is a magic square.

2. checkMagic should terminate as soon as you detect that the matrix is NOT a magic square. For example, if you find that row 2 does not add up to the correct total, do not look at the remaining the rows, columns or diagonals.

3. Main program – uses a while loop to read matrices until the end of file of reached, calling functions to process the magic squares.

Unfortunately we haven't done anything even remotely like this in class so far so I have no idea where I am supposed to even begin to understand how to do this. I am not asking anyone to just do the assignment for me because I want to actually learn it, but if you can help steer me in the right direction so I can get started that would be so appreciated.

closed account (48T7M4Gy)
The question says do it in stages. So your first job is 1(a) and the first part of that is to read some data from a file. Have a read of this tutorial, particularly the demo program(s)

http://www.cplusplus.com/doc/tutorial/files/
Topic archived. No new replies allowed.