Program to tests whether they form a magic square

Assignment Help C/C++ Programming
Reference no: EM13693811

Program Specification: An n x n matrix that is filled with the whole numbers 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.  

Here is a magic square where n = 3:

8          1          6           

3          5          7           

4          9          2          

Program: Write a program that reads n2 numbers from standard input and tests whether they form a magic square when put into matrix form. 

The value of n is NOT an input to the program; n must be determined from the number of inputs.

For example, the input that creates the example matrix above is   8 1 6 3 5 7 4 9 2.

The output is a single word, "true" if the input produces a magic square, "false" otherwise. Your program may assume that each input token is a whole number.

The program must verify:

1. The proper number of input values was provided.

2. Each of the numbers between 1 and n2 occurs exactly once in the input.

3. When the numbers are arranged in a matrix,

  • the sum of the rows,
  • columns,
  • and diagonals must be the same value.

You need to make well-formed and clean code. You should not copy and paste the code from other source.

Reference no: EM13693811

Questions Cloud

Consider pollution control in the electric industry : Consider pollution control in the electric industry. The prices of marketable permits are set by:
Minimum annual production rate to make this investment : A manufacturing company is considering a capacity expansion investment at the cost of $245,219 with no salvage value. The expansion would enable the company to produce up to 35,887 parts per year and the useful life of the additional capacity is seve..
Economists occasionally speak of helicopter money : Economists occasionally speak of “helicopter money” as a short-hand approach to explaining increases in the money supply. Suppose the Governor of the Fed flies over the country in a helicopter dropping 10,000,000 in newly printed $100 bills (a total ..
Generate a salary as a number with two digits : Generate a salary as a number with two digits after the decimal point. The salary for a teacher should be in the range from $40,000 to 70,000.
Program to tests whether they form a magic square : Write a program that reads n2 numbers from standard input and tests whether they form a magic square when put into matrix form.
Write a program to print out a simplified bill : Write a program to print out a simplified bill. The customer's name, the number of hours of labor, and the cost of parts and supplies should be entered in response to INPUT statements.
Calculate the average of a variable quantity of integers : Create a simple command line program to calculate the average of a variable quantity of integers that are passed as an argument when the program is called.
Write a program to print all of the permutations : Write a program to print all of the permutations of the values 1, 2, 3, ..., n - Your program takes one argument from the command line, which as an integer n  that is the number of elements.
What rules of inference are used in the argument : What rules of inference are used in the argument? "No man is an island. Manhattan is an island. Therefore, Manhattan is not a man."

Reviews

Write a Review

C/C++ Programming Questions & Answers

  In psuedocode, design an application

In psuedocode, design an application that has an array of at least 20 integers. It should call a module that uses the sequential search algorithm to locate one of the values

  Design and implement a c++ program for find friends

MCS2514Pgm1- Design and implement a C++ program that will help find friends according to a defined method. In particular, your program will find and display the ten people in database who answered a set of survey questions closest to what the user..

  Write a c program that asks for and reads in two integers

Write a C program that asks for and reads in two integers and then reports if one is a multiple of the other.

  Write a program to create 100 real random numbers

Write a program to create 100 real random numbers and store it into a 1-D array. Find the value 1413 from the stored data and print out the value 1413 and the index of the array to the screen

  Write a program that uses joptionpanes to perform

For example, if the distance of travel is 30 kilometers, the time of travel is 2 hours, then the speed is 30/2 = 15 (kilometers per hour).

  Define a 2-element array of characters

Write an if statement that sets the variable age to 21 when the flag variable adult is set and define a 2-element array of characters named alpha initialized with the characters P, Q.

  What output would be produced by the program segment

What output would be produced by the following program segment?

  Give examples of pretest and posttest loops

Give examples of pretest and posttest loops - Discuss the syntax of while, for, and do...while loops. Give examples.

  Describe an example application of polymorphism

Provide and describe an example application of polymorphism that could be used in a program solution. List and describe the class relationships.

  Build a definition for a class that stores data

Using C++ language, build a definition for a class that stores data about a two dimensional vector. The class has to have mutators and accessors to get and set the x and y values. Make x and y integers. Then overload the operator * so that it retu..

  Perform operations on arrays

Perform operations on arrays execute tests and repetitions

  Program to add numbers and display sum

For each of problems write C++ code to do the required task. Receive the number and find out whether it is odd or even.

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