Exercise EC-magic
|
Magic Squares
|
Due: Friday, December 15
5pm
|
Assignment: (This assignment is EXTRA CREDIT.)
A "Magic Square" is an NxN grid of numbers for which each row, column,
and diagonal adds up to the same sum. For instance,
8 1 6
3 5 7
4 9 2
You are to create a class that has a matrix as a field, and a boolean
method which determines if that matrix is a magic square. There,
obviously, also needs to be a way to set the values of the matrix.
Now, create a driver program that reads a data file "square.txt"
and determines if the indicated grid is a Magic Square.
The format of the file is as follows:
1st line: a number, representing N
The next N lines: N numbers representing the numbers in each
row, one row per line.
More Extra credit:
Modify the program to randomly look for "magic squares" of a certain
size (say N = 6), printing them out to a file.
Do a graphical display (complete with scale and legend) of
the temperatures.
Handin:
-
Be sure to read the general handin instructions on the exercises page.
-
Rename the folder containing all of the files to be
"lastname-firstname-100SectionLetter-magic". For example, if I were in Section Z, I would rename my folder to
be: "McElfresh-Scott-100Z-magic"
(without the quotes).
- Create a zip file of this folder, with the same name as the folder (except
with the .zip ending this time). Instructions for zipping can be found in
the system and software handouts linked on the main course page.
- Submit this file via the electronic
handin. If you have problems, contact me.
|