Answered step by step
Verified Expert Solution
Question
1 Approved Answer
IN C++ Please. CONCEPT: VECTORS A magic square is an n-by-n vector where the integers 1 to n? appear exactly once and the sum of
IN C++ Please.
CONCEPT: VECTORS A magic square is an n-by-n vector where the integers 1 to n? appear exactly once and the sum of the integers in every row, column, and on both diagonals is the same. For example, the following magic square results when n=7. Notice that each row column, and both diagonals total 175. Magic Square Implement the class with two member functions: a constructor and a display method. You should use an STL vector. Given an input of 7, when we run out main our output should be: 30 10 19 39 47 48 7 27 38 46 18 26 28 29 37 6 35 8 16 14 1 9 17 25 33 41 49 34 36 5 13 45 42 4 15 23 31 24 32 44 3 21 22 43 2 12 20 40 11 (Hint: Use setw(3) in your cout for each number to get the right output) You should be able to construct an n-by-n magic square for any odd value n from 3 to 15. When j=1, place the value of jin the middle of the first row. Then, for a counter value ranging from 1 to n2, move up one row and to the right one column and store the counter value, unless one of the following events occurs: When the next row becomes 0, make the next row equal to n (this assumes you used 1 for the first row). When the next column becomes n+1, make the next column equal to 1 (this assumes that you used 1 for the first column). If a position is already filled, or the upper-right corner element has just obtained a value, place the next counter value in the position that is one row below the position where the last counter value has been placed. wewe LAB ACTIVITY 5.28.1: Magic Square 0/60 Current file: main.cpp Load default template. 1 #include "MagicSquare.h" 2 3 int main 4 5 // your program goes here 6 7 return 0; Current file: magicsquare.h Load default template... 1 #ifndef MAGICSQUARE_H 2 #define MAGICSQUARE_H 3 4 #includeStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started