Programming

Programming questions? Ask a programmer for answers ASAP

Connect one-on-one with {0} who will answer your question

I have to program a...

I have to program a Magic Square tester in C++. I have a class already made up that will employ the use of an Input function, Output function that will both read and write info to a .dat file. The input function should read in information through a .dat file like:

N = dimension

2 1 2 4 5 (for example)

I will attach the program specifications and the class that I have created. The magic square has maximum dimensions [5][5].

The notion of a Magic Square is a familiar topic in recreational mathematics. A Magic Square is defined to be a square array of dimension N x N in which the following conditions or criteria are true:

I. Sequence Criteria: the elements of the array are the distinct positive integers 1, 2, 3 . . . . . . N*N in any order. Each of the integers in the sequence is used only once to populate the magic square. (As an example, a magic square of dimension 3 will use the following integers: 1,2,3,4,5,6,7,8,9. By definition, there are nine locations in the resulting 3*3 array. Each number in the sequence must only appear once in a specific location in the array.)

II. Sum Criteria: the individual sums of each row, each column and each of the two main diagonals are the same value.

Write a program which will serve as a Magic Square Tester. In particular, your program is to

1. Read data sets of the following form:

a. N, an integer representing the dimension of the array to be tested (maximum 5)

b. The N*N elements of the array, in row order (first row values, then second, etc.)

2 Print the N*N values of the array (matrix) in a two dimensional format

3. Print the result of performing the test for both criteria as follows:

a. If both criteria are met, print the message Magic Square! below the matrix values

b. If either condition is not met (or both are not met), print the message Not a Magic Square! below the matrix and also print the criteria that were not met (Sequence criteria failed. and/or Sum criteria failed.).

4. Test your program on the following data entered into a text file:

N Data entered in row-major order.

2 1 3 2 4

3 1 6 8 5 7 3 9 2 4

2 1 5 2 3

3 3 3 3 3 3 3 3 3 3

4 1 6 11 5 3 7 8 16 12 13 4 2 15 9 10 14

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

1 1

3 8 1 6 3 5 7 4 9 2

3 3 6 7 4 9 2 8 1 6

4 7 6 12 9 10 11 5 8 13 16 2 3 4 1 15 14

3 6 1 8 9 4 2 3 7 5

4 1 15 6 12 8 10 3 13 11 5 16 2 14 4 9 17

5. Read all input from a text file and output the results to a text file. Define the input and output

streams globally so that they are visible to the functions that do input/output. Do not include a path on the names of both input and output disk files so that the project directory will be accessed.

In order to run your program myself with my data, name and open your input disk file as “Magic.dat” (again, no path name!), which will be the file name that I will create.

6. Solve this problem using a Magic Square class defined as follows:

class Magic_Square

{

private:

int Size; // Number of rows and columns in the Magic Square array

int MagSq [ 5 ] [ 5 ] ; // Magic Square matrix

int ColSums [ 5 ] ; // Array of column sums

int RowSums [ 5 ] ; // Array of row sums

int Diag1 ; // Sum of major diagonal

int Diag2 ; // sum of minor diagonal

bool Sum_Criteria ; // Was the sum test met?

bool Sequence_Criteria ; // Was the sequence test met?

void Calc_RowSums ( ) ; // Calculates the row sums

void Calc_ColSums ( ) ; // Calculates the columns sums

void Calc_Diags ( ) ; // Calculates the two diagonal sums

public:

Magic_Square( ) ; // Constructor to initialize ColSums, RowSums, Diag1 and

// Diag2 to zeroes.

void Input_Values ( ); // Inputs the matrix values

void Output_Values ( ); // Displays the matrix values

void Seq_Test ( ) ; // Determines if the sequence test was met

void Sum_Test ( ) ; // Determines if the sum test was met

void Evaluate ( ) ; // Determines and displays whether a magic square or not

and if not, which criteria failed.

N = dimension

2 1 2 4 5 (for example)

I will attach the program specifications and the class that I have created. The magic square has maximum dimensions [5][5].

The notion of a Magic Square is a familiar topic in recreational mathematics. A Magic Square is defined to be a square array of dimension N x N in which the following conditions or criteria are true:

I. Sequence Criteria: the elements of the array are the distinct positive integers 1, 2, 3 . . . . . . N*N in any order. Each of the integers in the sequence is used only once to populate the magic square. (As an example, a magic square of dimension 3 will use the following integers: 1,2,3,4,5,6,7,8,9. By definition, there are nine locations in the resulting 3*3 array. Each number in the sequence must only appear once in a specific location in the array.)

II. Sum Criteria: the individual sums of each row, each column and each of the two main diagonals are the same value.

Write a program which will serve as a Magic Square Tester. In particular, your program is to

1. Read data sets of the following form:

a. N, an integer representing the dimension of the array to be tested (maximum 5)

b. The N*N elements of the array, in row order (first row values, then second, etc.)

2 Print the N*N values of the array (matrix) in a two dimensional format

3. Print the result of performing the test for both criteria as follows:

a. If both criteria are met, print the message Magic Square! below the matrix values

b. If either condition is not met (or both are not met), print the message Not a Magic Square! below the matrix and also print the criteria that were not met (Sequence criteria failed. and/or Sum criteria failed.).

4. Test your program on the following data entered into a text file:

N Data entered in row-major order.

2 1 3 2 4

3 1 6 8 5 7 3 9 2 4

2 1 5 2 3

3 3 3 3 3 3 3 3 3 3

4 1 6 11 5 3 7 8 16 12 13 4 2 15 9 10 14

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

1 1

3 8 1 6 3 5 7 4 9 2

3 3 6 7 4 9 2 8 1 6

4 7 6 12 9 10 11 5 8 13 16 2 3 4 1 15 14

3 6 1 8 9 4 2 3 7 5

4 1 15 6 12 8 10 3 13 11 5 16 2 14 4 9 17

5. Read all input from a text file and output the results to a text file. Define the input and output

streams globally so that they are visible to the functions that do input/output. Do not include a path on the names of both input and output disk files so that the project directory will be accessed.

In order to run your program myself with my data, name and open your input disk file as “Magic.dat” (again, no path name!), which will be the file name that I will create.

6. Solve this problem using a Magic Square class defined as follows:

class Magic_Square

{

private:

int Size; // Number of rows and columns in the Magic Square array

int MagSq [ 5 ] [ 5 ] ; // Magic Square matrix

int ColSums [ 5 ] ; // Array of column sums

int RowSums [ 5 ] ; // Array of row sums

int Diag1 ; // Sum of major diagonal

int Diag2 ; // sum of minor diagonal

bool Sum_Criteria ; // Was the sum test met?

bool Sequence_Criteria ; // Was the sequence test met?

void Calc_RowSums ( ) ; // Calculates the row sums

void Calc_ColSums ( ) ; // Calculates the columns sums

void Calc_Diags ( ) ; // Calculates the two diagonal sums

public:

Magic_Square( ) ; // Constructor to initialize ColSums, RowSums, Diag1 and

// Diag2 to zeroes.

void Input_Values ( ); // Inputs the matrix values

void Output_Values ( ); // Displays the matrix values

void Seq_Test ( ) ; // Determines if the sequence test was met

void Sum_Test ( ) ; // Determines if the sum test was met

void Evaluate ( ) ; // Determines and displays whether a magic square or not

and if not, which criteria failed.

Show More

Show Less

Was this answer helpful?

Describe your issueThe assistant will guide you

Chat 1:1 with a programmerLicensed Experts are available 24/7

100% satisfaction guaranteeGet all the answers you need

Related Programming Questions

DESCRIPTION: You will be given a 2D array, called matrix, of

DESCRIPTION: You will be given a 2D array, called matrix, of integers. The array has an unknown number of cells filled with data.Your goal is to write a new method called rowSum which will accept a 2D… read more

Nstructions Today you will be given an integer table. It

nstructionsToday you will be given an integer table. It will be populated for you. You will also be given a position (ROW, COL) within the inside (this will not be on the edge) of the array, starting … read more

A magic square Customer Question A magic square is a 2-D

A magic square Customer Question A magic square is a 2-D list where the sum of each row is equal to the sum of each column and is equal to the sum of each of the two diagonals. Here is an example of a… read more

I need a program with the following specifications and is

I need a program with the following specifications and is due 12/15/12 at 12pm: Write a program (project name binaryDiagonals) that generates a 6 x 6 matrix. Your program must populate the matrix with… read more

import java.util.Scanner; public class MagicSquare {

import java.util.Scanner; public class MagicSquare { //initializes N and magic static int N = 0; static int[][] magic = new int[N][N]; //square builder method public static int squareBuilder(){ int ro… read more

****For LogicPro Only**** Lesson 9-4: Two-Dimensional Arrays This

****For LogicPro Only**** Lesson 9-4: Two-Dimensional Arrays This lesson uses program TwoDTable. // Program TwoDTable manipulates a two-dimensional array // variable import java.io.*; import java.util… read more

****For LogicPro Only**** Lesson 9-4: Two-Dimensional Arrays This

****For LogicPro Only**** Lesson 9-4: Two-Dimensional Arrays This lesson uses program TwoDTable. // Program TwoDTable manipulates a two-dimensional array // variable import java.io.*; import java.util… read more

can you answer http://www.math.ucla.edu/~virtanen/10a.2.12w/assignments/hw8/hw8.html

can you answer http://www.math.ucla.edu/~virtanen/10a.2.12w/assignments/hw8/hw8.html the page has the following if you cannot access it: Your Assignment Your assignment is to implement matrix addition… read more

Complete Problem 4 on p. 350 in Ch. 6 of Prelude to

Complete Problem 4 on p. 350 in Ch. 6 of Prelude to Programming. You are required to generate only the pseudocode, as described in the Week Two CheckPoint. No charting is required, but you may have to… read more

I have 3 java programs I need help with please. [7]! ! 30

I have 3 java programs I need help with please. [7]! ! 30 points! ! file Bool.java ! As a practical joke for your birthday, your best friend gave you some single- dimensioned arrays, each full of bool… read more

An n x n array, that is filled with integers 1, 2, 3, …,n2

An n x n array, that is filled with integers 1, 2, 3, …,n2 is a magic square if the sum of the elements in each row, in each column, and in the two diagonals is the same value and each value in the ar… read more

PLEASE ANSWER THE FOLLOWING QUESTIONS 1. An array is a

PLEASE ANSWER THE FOLLOWING QUESTIONS: 1. An array is a list of data items that _____. (Points : 3) are of different data types are all integers share the same name are not indexed 2. An array that st… read more

Hey, I have this program and I am stuck on trying to calculate

Hey, I have this program and I am stuck on trying to calculate the mode? Can you try and fix this for me... let me know.. thanks #include "stdafx.h" #include int Responses[101]={ 0, 6, 7, 8, 9, 8, 7, … read more

A magic square is an n x n matrix in which each of the integers

A magic square is an n x n matrix in which each of the integers 1,2,3...n 2 appears exactly once and all column sums, row sums, and diagonal sums are equal. For example, the following is a 5 x 5 magic… read more

I need a function that takes a 2 dimensional array, sums each

I need a function that takes a 2 dimensional array, sums each row and then sorts the rows by sums(lowest to highest). The function should return the sorted array. The array should contain 5 rows, each… read more

I need to write a program that for displaying odd magic square

I need to write a program that for displaying odd magic square of size 15 using arrays and multidimensional arrays .we cannot use vectors. the sum of each rows and columns must be displayed and the ra… read more

Write a Java program that asks the users to enter a m n matrix

Write a Java program that asks the users to enter a m ´ n matrix of integers, m and n being the number of rows and columns, respectively. The program stores this matrix into a twodimensional m ´ n arr… read more

A magic square is an n x n matrix in which each of the integers

A magic square is an n x n matrix in which each of the integers 1,2,3...n 2 appears exactly once and all column sums, row sums, and diagonal sums are equal. For example, the following is a 5 x 5 magic… read more

Disclaimer: Information in questions, answers, and other posts on this site ("Posts") comes from individual users, not JustAnswer; JustAnswer is not responsible for Posts. Posts are for general information, are not intended to substitute for informed professional advice (medical, legal, veterinary, financial, etc.), or to establish a professional-client relationship. The site and services are provided "as is" with no warranty or representations by JustAnswer regarding the qualifications of Experts. To see what credentials have been verified by a third-party service, please click on the "Verified" symbol in some Experts' profiles. JustAnswer is not intended or designed for EMERGENCY questions which should be directed immediately by telephone or in-person to qualified professionals.

Ask-a-doc Web sites: If you've got a quick question, you can try to get an answer from sites that say they have various specialists on hand to give quick answers... Justanswer.com.

JustAnswer.com...has seen a spike since October in legal questions from readers about layoffs, unemployment and severance.

Web sites like justanswer.com/legal

...leave nothing to chance.

...leave nothing to chance.

Traffic on JustAnswer rose 14 percent...and had nearly 400,000 page views in 30 days...inquiries related to stress, high blood pressure, drinking and heart pain jumped 33 percent.

Tory Johnson, GMA Workplace Contributor, discusses work-from-home jobs, such as JustAnswer in which verified Experts answer people’s questions.

I will tell you that...the things you have to go through to be an Expert are quite rigorous.

My Expert answered my question promptly and he resolved the issue totally. This is a great service. I am so glad I found it I will definitely use the service again if needed.

New York

Wonderful service, prompt, efficient, and accurate. Couldn't have asked for more. I cannot thank you enough for your help.

Freshfield, Liverpool, UK

This expert is wonderful. They truly know what they are talking about, and they actually care about you. They really helped put my nerves at ease. Thank you so much!!!!

Los Angeles, CA

Thank you for all your help. It is nice to know that this service is here for people like myself, who need answers fast and are not sure who to consult.

Hesperia, CA

I couldn't be more satisfied! This is the site I will always come to when I need a second opinion.

Kernersville, NC

Just let me say that this encounter has been entirely professional and most helpful. I liked that I could ask additional questions and get answered in a very short turn around.

Woodstock, NY

Thank you so much for taking your time and knowledge to support my concerns. Not only did you answer my questions, you even took it a step further with replying with more pertinent information I needed to know.

Elkton, Maryland

< Previous | Next >

LogicPro

Computer Software Engineer

9,436 satisfied customers

Expert in C, C++, Java, DOT NET, Python, HTML, Javascript, Design.

unvadim

Computer Software Engineer

1,168 satisfied customers

Good knowledge of OOP principles. 3+ years of programming experience with Java and C++. Sun Certified Java Programmer 5.0.

The-PC-Guy

Software Engineer

932 satisfied customers

Extensive Knowledge in PHP, MYSQL, CSS & Javascript

TheDoctor

Software Engineer

893 satisfied customers

M.S. in Internet Information Systems

Rafael Martins

Computer Software Engineer

449 satisfied customers

Desktop, Mobile and Web Developer. 10+ years of experience. Creative solutions provider.

Ramesh Patil

Computer Software Engineer

406 satisfied customers

MCA, 3+ years of experience in Asp.Net, C#, SSIS, VB.Net, Ms-SqlServer2005, MySql, Javascript,

Arty

Computer Software Engineer

377 satisfied customers

15+ years of programming, C, C++, Java, PHP, awk, ruby, shell, ASM, Forth, Raptor, M.A.R.I.E, Excel

< Previous | Next >

Disclaimer: Information in questions, answers, and other posts on this site ("Posts") comes from individual users, not JustAnswer; JustAnswer is not responsible for Posts. Posts are for general information, are not intended to substitute for informed professional advice (medical, legal, veterinary, financial, etc.), or to establish a professional-client relationship. The site and services are provided "as is" with no warranty or representations by JustAnswer regarding the qualifications of Experts. To see what credentials have been verified by a third-party service, please click on the "Verified" symbol in some Experts' profiles. JustAnswer is not intended or designed for EMERGENCY questions which should be directed immediately by telephone or in-person to qualified professionals.