Physics 5
 Magic Squares - Assignment CNSL003

 

A detail from Albrecht Durer’s Melancholia

 

A magic square of order n is an arrangement of n × n numbers, usually distinct integers, in a square, such that the n numbers in all rows, all columns, and both diagonals sum to the same constant (see Wikipedia:Magic Square). There are two text files: file01.txt and file02.txt given. For each file: open the file, and check that all rows indeed sum to the same constant.  Copy both text files to the root directory of your project. This is the directory that contains the source folder.  Alternatively:  Use absolute paths to the files (c:\somedir\Projects\MagicSquares\file01.txt

 

Break apart each line at the tab character, producing an array of String (String[]), each containing one value. Consult the references for file reading to see how to do this.  Finally, transform each string value into an integer value. Check that the columns and the diagonal also sum to the same constant. Submit your <initials>CNSL003.cpp file.