Determine if the two dimensional array is a magic square

Assignment Help Computer Engineering
Reference no: EM132109185

 

Programming language: C++

Lab 11 - Is This Box a Magic Box?

Objectives:

Define a two dimensional array

Understand how to traverse a two dimensional array

Code and run a program that processes a two dimensional array

Instructions:

A magic square is a matrix (two dimensional arrays) in which the sum of each row, sum of each column, sum of the main diagonal, and sum of the reverse diagonal are all the same value.

You are to code a program to determine if a given two-dimensional array (that will be read in from a file) is a magic square or not. The functions you will need to code are as follows:

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 the while loop.

Then inside the while loop it will call all the methods given above to read the data into the matrix, print the matrix, print all the row sums, print all the column sums, and print both diagonals.

Then the program will determine if the matrix is a magic square and print an appropriate message. The next size should be read in at the end of the while loop.

The main will continue with the next matrix in the data file, until a size of -1 is reached. See the Additional Notes on Two Dimension Arrays for more help with this assignment.

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 of this 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

Run:

Run the program to see if your results are correct.

Submission:

You will need to turn in your source code (.cpp file) and output zipped into one folder. Please submit them to D2L as usual.

Reference no: EM132109185

Questions Cloud

Write a program for converting us measurement values : Write a program for converting US measurement values to their corresponding metric measurement.
Design a payroll class with a string containing the employee : Write another program that demonstrates the class by creating a Payroll object , then asking the user to enter the data for an employee.
Write a void method named that accepts an integer array : Write a void method named clear that accepts an integer array , and the number of elements in the array and sets the elements of the array to 0.
Write a program to read in various types of test questions : Write a C++ program to read in various types of test questions (multiple choice and True/False) from a test bank (text file), and load the questions.
Determine if the two dimensional array is a magic square : Determine if the two dimensional array is a magic square. The main method will read the size of the array outside of the while loop
Develop both an uml diagram and the corresponding java class : Develop both an uml diagram and the corresponding java class for a New York State Win 4 lottery ticket .
Prepapre a database of books that are stored using a vector : Create a database of books that are stored using a vector. Keep track of the author, title, and publication date of each book.
What is the big deal with this as far as complex projects : what is the big deal with this as far as complex projects are concerned? Surely it is a common characteristic of project management and those whom practice
Write a function that would be used in a recursive-descent : "Given a production, write a function that would be used in a recursive-descent parser for handling that production."

Reviews

Write a Review

Computer Engineering Questions & Answers

  Create a user account and add and activate the tag

In order to use the newly purchased tag a user must create a user account and add and activate the tag by ID. A user is either personal or commercial.

  Products were completely hardware based

Starting in 1981, designs for the Navigation Systems incorporated a microprocessor and an increasing number of integrated circuits. To support the microprocessor-based designs, Navigation Systems Inc.

  Write a paper about strategic importance of cloud computing

Write a paper about Strategic importance of cloud computing in business organizations. 2000 words deductions for above or below word count.

  Explain requirements of the security policy statement

Please select an appropriate hardening technique to meet the requirements of the security policy statement. Provide rationale for each selection.

  Discuss a possible research paper on physical security

Write the abstract for a possible research paper on Physical Security

  Advantages and disadvantages of moving this functionality

Many of the functions of an adapter could be performed in software that runs on the node's CPU.

  Getters would provide access to the attributes.

For this task you will make a Subject class, whose instances will represent the subjects for study at a university. A subject will have a name, just a String, and a subject code, that is a six-character String.

  Validate the email address and return true if valid

Create a new document called l5p3 html. It should have a form with a text input box for an email address and a Submit button.

  Define concept of level for general graph rather than dag

Can you define the concept of level for a general graph rather than for a DAG? Why? Why not? What does this imply about a USES relation that is not a hierarchy?

  Demonstrate the ability to assemble already-written classes

CSC151 : Demonstrate the ability to assemble already-written classes into a larger, more complicated program.

  Write a microprogram for translate

An example of macroinstruction is a TRANSLATE instruction. The instruction replaces an operand with a translated version of itself, the translated version.

  Write a program that prints a menu

Write a program that prints a menu. Based on the menu item selected by the user, the program should request the required inputs from the user.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd