c++ Objective: Implement a non-trivial algorithm in C++. Problem: A Magic Square
ID: 3593264 • Letter: C
Question
c++
Objective: Implement a non-trivial algorithm in C++. Problem: A Magic Square of order N consists of N’ squares, each of which contains a number from 1 through N" such that the rows, columns, and diagonals sum to the same thing (called the magic sum). For example, the following is a magic square of order 3 with a magic sum of 15: 6 8 (2 24 Input: Your program should ask the user to enter an odd integer. For the purposes of this program, treat the input as an unsigned short. Every odd number up to 999 is valid for this program. The program should continue prompting for numbers and printing magic squares until the user enters a zero. If an even number is entered, print an appropriate error message and prompt the user to enter another number. Output: The program should output the magic squares to a text file. You don't need to print the boxes around the numbers, but arrange the numbers in columns and rows so the square is readable using print formatting. In addition to the magic square, also print out the magic sum. Miscellaneous: This program must use functions and arrays. It is your decision how many functions are used and how they are defined. There is an algorithm for creating magic squares, make sure you do your research before tackling this program.Explanation / Answer
/*Since there are no explicit constructors,
there exists a default constructor*/
struct Trivial {
int i;
private:
int j;
};
/* In Trivial2 structure, the presence of the
Trivial2(int a, int b) constructor requires
that you provide a default constructor. For
the type to qualify as trivial, we must
explicitly default that constructor.*/
struct Trivial2 {
int i;
Trivial2(int a, int b)
{
i = a;
}
Trivial2() = default;
};
/*Since there are no explicit constructors,
there exists a default constructor*/
struct Trivial {
int i;
private:
int j;
};
/* In Trivial2 structure, the presence of the
Trivial2(int a, int b) constructor requires
that you provide a default constructor. For
the type to qualify as trivial, we must
explicitly default that constructor.*/
struct Trivial2 {
int i;
Trivial2(int a, int b)
{
i = a;
}
Trivial2() = default;
};
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.