C++ programming Chapter(s) Covered: Chapter 1-8 Concepts tested by the program: Working with one dimensional parallel arrays Use of functions Use of loops and conditional statements Project Description The Lo Shu Magic Square is a grid with 3 rows and 3 columnsshown below. The Lo Shu Magic Square has the following properties: The grid contains the numbers 1 – 9 exactly. Each number 1 – 9must not be used more than once. So, if you were to add up thenumbers used,  The sum of each row, each column and each diagonal all add upto the same number, Write a program that simulates a magic square using 3 onedimensional parallel arrays of integer type. Each one the arrays corresponds to a row of the magicsquare. The program asks the user to enter the values of the magicsquare row by row and informs the user if the grid is a magicsquare or not. See the sample outputs for more clarification. Project Specifications Input for this project: Values of the grid (row by row) Output for this project: Whether or not the grid is magic square, check screenshot for further Use the following template to start your project: #include using namespace std; // Global constants const int ROWS = 3;  const int COLS = 3;  const int MIN = 1;  const int MAX = 9;  bool isMagicSquare(int arrayRow1[], int arrayRow2[], intarrayRow3[], int size); bool checkRange(int arrayRow1[], int arrayRow2[], intarrayRow3[], int size, int min, int max); bool checkUnique(int arrayRow1[], int arrayRow2[], intarrayRow3[], int size); bool checkRowSum(int arrayrow1[], int arrayrow2[], intarrayrow3[], int size); bool checkColSum(int arrayrow1[], int arrayrow2[], intarrayrow3[], int size); bool checkDiagSum(int arrayrow1[], int arrayrow2[], intarrayrow3[], int size); void fillArray(int arrayRow1[], int arrayRow2[], intarrayRow3[], int size); void showArray(int arrayrow1[], int arrayrow2[], intarrayrow3[], int size); int main() {      /* Define a Lo Shu Magic Square using 3 parallel arrayscorresponding to each row of the grid */ int magicArrayRow1[COLS],    magicArrayRow2[COLS],    magicArrayRow3[COLS];   // Your code goes here       return 0; } // Function definitions go here Create and use following functions: void fillArray(int arrayrow1[], int arrayrow2[], intarrayrow3[], int size) - Accepts 3 int arrays and a sizeas arguments and fills the arrays out with values entered by theuser. First argument corresponds to the first row of the magicsquare, second argument to the second row and the third argument tothe third row of the magic square void showArray(int arrayRow1[], int arrayRow2[], intarrayRow3[], int size) - accepts 3 int arrays and a sizeas arguments and displays their content. bool isMagicSquare(int arrayRow1[], int arrayRow2[],int arrayRow3[], int size) - accepts 3 int arrays and asize as arguments and returns true if all the requirements of amagic square are met. Otherwise, it returns false. First argumentcorresponds to the first row of the magic square, second argumentto the second row and the third argument to the third row of themagic square. bool checkRange(int arrayRow1[], int arrayRow2[], intarrayRow3[], int size, int min, int max) - accepts 3 intarrays, a size and a min and max value as arguments and returnstrue if the values in the arrays are within the specified range minand max. Otherwise, it returns false. First argument corresponds tothe first row of the magic square, second argument to the secondrow and the third argument to the third row of the magicsquare. bool checkUnique(int arrayRow1[], int arrayRow2[], intarrayRow3[], int size) - accepts 3 int arrays and a sizeas arguments and returns true if the values in the arrays areunique (only one occurrence of numbers between 1-9). Otherwise, itreturns false. First argument corresponds to the first row of themagic square, second argument to the second row and the thirdargument to the third row of the magic square. bool checkRowSum(int arrayRow1[], int arrayRow2[], intarrayRow3[], int size) - accepts 3 int arrays and a sizeas arguments and returns true if the sum of the values in each ofthe rows are equal. Otherwise, it returns false. First argumentcorresponds to the first row of the magic square, second argumentto the second row and the third argument to the third row of themagic square. bool checkColSum(int arrayRow1[], int arrayRow2[], intarrayRow3[], int size) - accepts 3 int arrays and a sizeas arguments and returns true if the sum of the values in each ofthe columns are equal. Otherwise, it returns false. First argumentcorresponds to the first row of the magic square, second argumentto the second row and the third argument to the third row of themagic square. bool checkDiagSum(int arrayrow1[], int arrayrow2[], intarrayrow3[], int size) - accepts 3 int arrays and a sizeas arguments and returns true if the sum of the values in each ofthe array's diagonals are equal. Otherwise, it returns false. Firstargument corresponds to the first row of the magic square, secondargument to the second row and the third argument to the third rowof the magic square.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

C++ programming

Chapter(s) Covered:

  • Chapter 1-8

Concepts tested by the program:

  • Working with one dimensional parallel arrays
  • Use of functions
  • Use of loops and conditional statements

Project Description

The Lo Shu Magic Square is a grid with 3 rows and 3 columnsshown below.

The Lo Shu Magic Square has the following properties:

  • The grid contains the numbers 1 – 9 exactly. Each number 1 – 9must not be used more than once. So, if you were to add up thenumbers used, 
  • The sum of each row, each column and each diagonal all add upto the same number,

Write a program that simulates a magic square using 3 onedimensional parallel arrays of integer type.

Each one the arrays corresponds to a row of the magicsquare.

The program asks the user to enter the values of the magicsquare row by row and informs the user if the grid is a magicsquare or not.

See the sample outputs for more clarification.

Project Specifications

Input for this project:

  • Values of the grid (row by row)

Output for this project:

  • Whether or not the grid is magic square, check screenshot for further

Use the following template to start your project:

#include

using namespace std;

// Global constants

const int ROWS = 3; 

const int COLS = 3; 

const int MIN = 1; 

const int MAX = 9; 

bool isMagicSquare(int arrayRow1[], int arrayRow2[], intarrayRow3[], int size);

bool checkRange(int arrayRow1[], int arrayRow2[], intarrayRow3[], int size, int min, int max);

bool checkUnique(int arrayRow1[], int arrayRow2[], intarrayRow3[], int size);

bool checkRowSum(int arrayrow1[], int arrayrow2[], intarrayrow3[], int size);

bool checkColSum(int arrayrow1[], int arrayrow2[], intarrayrow3[], int size);

bool checkDiagSum(int arrayrow1[], int arrayrow2[], intarrayrow3[], int size);

void fillArray(int arrayRow1[], int arrayRow2[], intarrayRow3[], int size);

void showArray(int arrayrow1[], int arrayrow2[], intarrayrow3[], int size);

int main()

{

     /* Define a Lo Shu Magic Square using 3 parallel arrayscorresponding to each row of the grid */

int magicArrayRow1[COLS],

   magicArrayRow2[COLS],

   magicArrayRow3[COLS];

 

// Your code goes here

      return 0;

}

// Function definitions go here

Create and use following functions:

  • void fillArray(int arrayrow1[], int arrayrow2[], intarrayrow3[], int size) - Accepts 3 int arrays and a sizeas arguments and fills the arrays out with values entered by theuser. First argument corresponds to the first row of the magicsquare, second argument to the second row and the third argument tothe third row of the magic square
  • void showArray(int arrayRow1[], int arrayRow2[], intarrayRow3[], int size) - accepts 3 int arrays and a sizeas arguments and displays their content.
  • bool isMagicSquare(int arrayRow1[], int arrayRow2[],int arrayRow3[], int size) - accepts 3 int arrays and asize as arguments and returns true if all the requirements of amagic square are met. Otherwise, it returns false. First argumentcorresponds to the first row of the magic square, second argumentto the second row and the third argument to the third row of themagic square.
  • bool checkRange(int arrayRow1[], int arrayRow2[], intarrayRow3[], int size, int min, int max) - accepts 3 intarrays, a size and a min and max value as arguments and returnstrue if the values in the arrays are within the specified range minand max. Otherwise, it returns false. First argument corresponds tothe first row of the magic square, second argument to the secondrow and the third argument to the third row of the magicsquare.
  • bool checkUnique(int arrayRow1[], int arrayRow2[], intarrayRow3[], int size) - accepts 3 int arrays and a sizeas arguments and returns true if the values in the arrays areunique (only one occurrence of numbers between 1-9). Otherwise, itreturns false. First argument corresponds to the first row of themagic square, second argument to the second row and the thirdargument to the third row of the magic square.
  • bool checkRowSum(int arrayRow1[], int arrayRow2[], intarrayRow3[], int size) - accepts 3 int arrays and a sizeas arguments and returns true if the sum of the values in each ofthe rows are equal. Otherwise, it returns false. First argumentcorresponds to the first row of the magic square, second argumentto the second row and the third argument to the third row of themagic square.
  • bool checkColSum(int arrayRow1[], int arrayRow2[], intarrayRow3[], int size) - accepts 3 int arrays and a sizeas arguments and returns true if the sum of the values in each ofthe columns are equal. Otherwise, it returns false. First argumentcorresponds to the first row of the magic square, second argumentto the second row and the third argument to the third row of themagic square.
  • bool checkDiagSum(int arrayrow1[], int arrayrow2[], intarrayrow3[], int size) - accepts 3 int arrays and a sizeas arguments and returns true if the sum of the values in each ofthe array's diagonals are equal. Otherwise, it returns false. Firstargument corresponds to the first row of the magic square, secondargument to the second row and the third argument to the third rowof the magic square.
Enter the number for row e and column e :1
Enter the number for row 0 and column 1 :3
Enter the number for row 0 and column 2 :2
Enter the number for row 1 and column e :5
Enter the number for row 1 and column 1 :4
Enter the number for row 1 and column 2 :9
Enter the number for row 2 and column e :6
Enter the number for row 2 and column 1 :7
Enter the number for row 2 and column 2 :8
1 3 2
5 4 9
6 7 8
is in Range : 1
is Unique : 1
is equal Rows : 0
is equal Cols : 0
is Equal Diag : 0
This is not a magic square
Do you want to try again?y
Enter the number for row e and column e :10
Enter the number for row e and column 1 :2
Enter the number for row e and column 2 :3
Enter the number for row 1 and column e :4
Enter the number for row 1 and column 1 :15
Enter the number for row 1 and column 2 :6
Enter the number for row 2 and column e :7
Enter the number for row 2 and column 1 :8
Enter the number for row 2 and column 2 :-8
10 2 3
4 15 6
7 8 -8
is in Range : 0
is Unique : 1
is equal Rows : 0
is equal Cols : 0
is Equal Diag : 0
This is not a magic square
Transcribed Image Text:Enter the number for row e and column e :1 Enter the number for row 0 and column 1 :3 Enter the number for row 0 and column 2 :2 Enter the number for row 1 and column e :5 Enter the number for row 1 and column 1 :4 Enter the number for row 1 and column 2 :9 Enter the number for row 2 and column e :6 Enter the number for row 2 and column 1 :7 Enter the number for row 2 and column 2 :8 1 3 2 5 4 9 6 7 8 is in Range : 1 is Unique : 1 is equal Rows : 0 is equal Cols : 0 is Equal Diag : 0 This is not a magic square Do you want to try again?y Enter the number for row e and column e :10 Enter the number for row e and column 1 :2 Enter the number for row e and column 2 :3 Enter the number for row 1 and column e :4 Enter the number for row 1 and column 1 :15 Enter the number for row 1 and column 2 :6 Enter the number for row 2 and column e :7 Enter the number for row 2 and column 1 :8 Enter the number for row 2 and column 2 :-8 10 2 3 4 15 6 7 8 -8 is in Range : 0 is Unique : 1 is equal Rows : 0 is equal Cols : 0 is Equal Diag : 0 This is not a magic square
Test
Case #
Actual
Input
Expected
Output
Is Magic?
Actual Output
Is Magic?
Did the
test pass?
Input
No
Y/N
bool checkRange: 1
bool checkUnique: 1
bool checkRowSum: ?
bool checkColSum: ?
bool checkDiagSum: ?
1
132
549
678
No
Y/N
bool checkRange: 0
bool checkUnique: 1
bool checkRowSum: ?
bool checkColSum: ?
bool checkDiagSum: ?
2
10 2 3
4 15 6
7 8 -8
bool checkRange: ?
bool checkUnique:?
bool checkRowSum: ?
bool checkColSum: ?
bool checkDiagSum: ?
3
4 9 2
Yes
Y/N
3 5 7
8 1 6
4
555
555
555
Transcribed Image Text:Test Case # Actual Input Expected Output Is Magic? Actual Output Is Magic? Did the test pass? Input No Y/N bool checkRange: 1 bool checkUnique: 1 bool checkRowSum: ? bool checkColSum: ? bool checkDiagSum: ? 1 132 549 678 No Y/N bool checkRange: 0 bool checkUnique: 1 bool checkRowSum: ? bool checkColSum: ? bool checkDiagSum: ? 2 10 2 3 4 15 6 7 8 -8 bool checkRange: ? bool checkUnique:? bool checkRowSum: ? bool checkColSum: ? bool checkDiagSum: ? 3 4 9 2 Yes Y/N 3 5 7 8 1 6 4 555 555 555
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 8 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education