Question

The Lo Shu Magic Square is a grid with 3 rows and 3 columns shown below. 35 The Lo Shu Magic Square has the following propert

I need help as quick as possible, thanks beforehand. Please provide the test output
Project Specifications Input for this project: • Values of the grid (row by row) Output for this project: Whether or not the
Define a Lo Shu Magic Square using 3 parallel arrays corresponding to each row of the grid */ int magicArrayRowl (COLS], magi
of the magic square, second argument to the second row and the third argument to the third row of the magic square void showA
returns true if the sum of the values in each of the columns are equal. Otherwise, it returns false. First argument correspon
Sample Output er the nunber forrow and column 0:1 the nunber for row and column 1 Enter the number for row Q and column Enter
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
_________________


#include <iostream>
#include <iomanip>
#include <ctime>
#include <cstdlib>
using namespace std;
// Global constants
const int ROWS = 3; // The number of rows in the array
const int COLS = 3; // The number of columns in the array
const int MIN = 1; // The value of the smallest number
const int MAX = 9; // The value of the largest number
// Function prototypes
void showResult(int[][COLS]);
void showArray(int[][COLS]);
bool isMagicSquare(int[][COLS]);
bool checkRange(int[][COLS]);
bool checkUnique(int[][COLS]);
bool checkRowSum(int[][COLS]);
bool checkColSum(int[][COLS]);
bool checkDiagSum(int[][COLS]);
int main()
{
  
int magicArray[ROWS][COLS];
char ch;
  
while(true)
{
for(int i=0;i<ROWS;i++)
{
for(int j=0;j<COLS;j++)
{
cout<<"Enter the number for row "<<(i)<<" and column "<<(j)<<" :";
cin>>magicArray[i][j];
}
}
for(int i=0;i<ROWS;i++)
{
for(int j=0;j<COLS;j++)
{
cout<<magicArray[i][j]<<" ";
}
cout<<endl;
}
  
// Test the magic array and display the result.
showResult(magicArray);
cout<<"\n\nDo you want to try again :";
cin>>ch;

if(ch=='y'||ch=='Y')
{

   continue;

}else
{
break;
}   
   }

return 0;
}
// ********************************************************
// The showResult function accepts a two-dimensional int *
// array as an argument, tests to determine if it is a *
// Lo Shu Magic Square and displays the result. *
// ********************************************************
void showResult(int values[][COLS])
{
// Determine if the array is a Lo Shu Magic Square.
if (isMagicSquare(values)) {
// If so, display a message indicating that the
// array is a magic square.
cout << "This is a Lo Shu magic square.\n\n";
}
else {
// If not, display a message indicating that the
// array is not a magic square.
cout << "This is not a Lo Shu magic square.\n\n";
}
}
// ********************************************************
// The showArray function accepts a two-dimensional int *
// array as an argument and displays its contents. *
// ********************************************************
void showArray(int values[][COLS])
{
// Step through all the values in the array.
for (int row = 0; row < ROWS; row++) {
for (int col = 0; col < COLS; col++) {
// Display the values in this row.
cout << values[row][col] << " ";
}
// End the line, so we can display the next row.
cout << endl;
}
}
// ********************************************************
// The isMagicSquare function accepts a two-dimensional *
// int array as an argument, and returns true if the *
// array meets all the requirements of a magic square. *
// Otherwise, it returns false. *
// ********************************************************
bool isMagicSquare(int values[][COLS])
{
// Initialize the status to false.
bool status = false;
// Call the functions to check the array.
bool isInRange = checkRange(values);
bool isUnique = checkUnique(values);
bool isEqualRows = checkRowSum(values);
bool isEqualCols = checkColSum(values);
bool isEqualDiag = checkDiagSum(values);
// Determine if the array meets all the requirments.
if (isInRange && isUnique && isEqualRows && isEqualCols && isEqualDiag) {
// If so, set the status to true.
status = true;
}
// Return the status.
return status;
}
// ********************************************************
// The checkRange function accepts a two-dimensional int *
// array as an argument, and returns true if the values *
// are within the specified range. Otherwise, it returns *
// false. *
// ********************************************************
bool checkRange(int values[][COLS])
{
// Initialize status to true.
bool status = true;
// Step through all the values in the array.
for (int row = 0; row < ROWS; row++) {
for (int col = 0; col < COLS; col++) {
// Determine if the value is out of range.
if (values[row][col] < MIN || values[row][col] > MAX) {
// If so, set status to false.
status = false;
}
}
}
// Return the status.
return status;
}
// ********************************************************
// The checkUnique function accepts a two-dimensional int *
// array as an argument, and returns true if the values *
// in the array are unique. Otherwise, it returns false. *
// ********************************************************
bool checkUnique(int values[][COLS])
{
int count;
int num=1;
bool status=true;
for (int i = 0; i < ROWS; i++)
{
count = 0;
for (int j = 0; j < COLS; j++)
{
if (values[i][j] == num)
count++;
}
if (count > 1)
status=false;
num++;
}
// Return the status.
return status;
}
// ********************************************************
// The checkRowSum function accepts a two-dimensional *
// int array as an argument, and returns true if the sum *
// of the values in each of the array's rows are equal. *
// Otherwise, it returns false. *
// ********************************************************
bool checkRowSum(int values[][COLS])
{
// Initialize status to true.
bool status = true;
// Calculate the sum of the values in the first row.
int sumRowA = values[0][0] + values[0][1] + values[0][2];
// Calculate the sum of the values in the second row.
int sumRowB = values[1][0] + values[1][1] + values[1][2];
// Calculate the sum of the values in the third row.
int sumRowC = values[2][0] + values[2][1] + values[2][2];
// Determine if the sum of the columns is not equal.
if ((sumRowA != sumRowB) || (sumRowA != sumRowC) || (sumRowB != sumRowC)) {
// If so, set status to false.
status = false;
}
// Return the status.
return status;
}
// ********************************************************
// The checkColSum function accepts a two-dimensional *
// int array as an argument, and returns true if the sum *
// of the values in each of the array's columns are *
// equal. Otherwise, it returns false. *
// ********************************************************
bool checkColSum(int values[][COLS])
{
// Initialize status to true.
bool status = true;
// Calculate the sum of the values in the first column.
int sumColA = values[0][0] + values[1][0] + values[2][0];
// Calculate the sum of the values in the second column.
int sumColB = values[0][1] + values[1][1] + values[2][1];
// Calculate the sum of the values in the third column.
int sumColC = values[0][2] + values[1][2] + values[2][2];
// Determine if the sum of the columns is not equal.
if ((sumColA != sumColB) || (sumColA != sumColC) || (sumColB != sumColC)) {
// If so, set status to false.
status = false;
}
// Return the status.
return status;
}
// ********************************************************
// The checkDiagSum function accepts a two-dimensional *
// int array as an argument, and returns true if the sum *
// of the values in each of the array's diagonals are *
// equal. Otherwise, it returns false. *
// ********************************************************
bool checkDiagSum(int values[][COLS])
{
// Initialize status to true;
bool status = true;
// Calculate the sum of the values in the first diagonal.
int sumDiagA = values[0][0] + values[1][1] + values[2][2];
// Calculate the sum of the values in the second diagonal.
int sumDiagB = values[2][0] + values[1][1] + values[0][2];
// Determine if the sum of the diagonals is not equal.
if (sumDiagA != sumDiagB) {
// If so, set status to false.
status = false;
} // Return the status.
return status;
}
__________________________________

Output:

C:\Program Files (x86)\Dev-Cpp\MinGW64\bin\LoShuMagicSquareOtNot.exe Enter the number for row 0 and column 0 :1 Enter the num

Do you want to try again :y Enter the number for row 0 and column 0 :4 Enter the number for row 0 and column 1 :9 Enter the n

_______________Could you plz rate me well.Thank You

Add a comment
Know the answer?
Add Answer to:
I need help as quick as possible, thanks beforehand. Please provide the test output The Lo...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Concepts tested by the program: Working with one dimensional parallel arrays Use of functions Use of...

    Concepts tested by the program: Working with one dimensional parallel arrays Use of functions Use of loops and conditional statements Description The Lo Shu Magic Square is a grid with 3 rows and 3 columns shown below. The Lo Shu Magic Square has the following properties: The grid contains the numbers 1 – 9 exactly The sum of each row, each column and each diagonal all add up to the same number. s is shown below: Write a program that...

  • 9. Lo Shu Magic Square The Lo Shu Magic Square is a grid with three rows and three columns that h...

    9. Lo Shu Magic Square The Lo Shu Magic Square is a grid with three rows and three columns that has the following properties: The grid contains the numbers 1 through 9 exactly. The sum of each row, each column, and each diagonal all add up to the same number. This is shown in the following figure · 15 4 9 2-15 3 5 7-15 81 615 15 15 15 15 Write a program that simulates a magic square using...

  • please use java language please used ArrayList The Lo Shu Magic Square is a grid with...

    please use java language please used ArrayList The Lo Shu Magic Square is a grid with 3 rows and 3 columns, shown in Figure 7-31. The • The sum of each row, each column, and each diagonal all add up to the same number 20. Lo Shu Magic Square Lo Shu Magic Square has the following properties: • The grid contains the numbers 1 through 9 exactly. This is shown in Figure 7-32. In a program you can simulate a...

  • I am using C++ Write a program to determine if a gird follows the rules to...

    I am using C++ Write a program to determine if a gird follows the rules to be classified as a Lo Shu Magic Square. The Lo Shu Magic Square is a grid with 3 rows and 3 columns shown in figure below. The Lo Shu Magic Square has the following properties: The grid contains the numbers 1 through 9 exactly. The sum of each row, each column, and each diagonal all add up to the same number. This is shown...

  • I need a c++ code please. 32. Program. Write a program that creates an integer constant...

    I need a c++ code please. 32. Program. Write a program that creates an integer constant called SIZE and initialize to the size of the array you will be creating. Use this constant throughout your functions you will implement for the next parts and your main program. Also, in your main program create an integer array called numbers and initialize it with the following values (Please see demo program below): 68, 100, 43, 58, 76, 72, 46, 55, 92, 94,...

  • I need help with the following and written in c++ thank you!: 1) replace the 2D...

    I need help with the following and written in c++ thank you!: 1) replace the 2D arrays with vectors 2) add a constructor to the Sudoku class that reads the initial configuration from a file 3) adds a function to the Sudoku class that writes the final Sudoku grid to a file or to the standard output device, cout. Sudoku.h #pragma once /* notes sudoku() default constructor precondition : none postcondition: grid is initialized to 0 sudoku(g[][9]) 1-parameter constructor precondition...

  • I need this written in C++. Magic Squares. An n x n matrix that is filled...

    I need this written in C++. Magic Squares. An n x n matrix that is filled with the 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. The following algorithm will construct magic n x n squares; it only works if n is odd: Place 1 in the middle of the bottom row. After k has been placed in the (i,j) square,...

  • IN C++ ADD COMMENTS AS MUCH AS POSSIBLE Exercise 1: Duplicate the Arrays Suppose you are...

    IN C++ ADD COMMENTS AS MUCH AS POSSIBLE Exercise 1: Duplicate the Arrays Suppose you are developing a program that works with arrays of integers, and you find that you frequently need to duplicate the arrays. Rather than rewriting the array-duplicating code each time you need it, you decide to write a function that accepts an array and its size as arguments. Creates a new array that is a copy of the argument array, and returns a pointer to the...

  • Please help i need a C++ version of this code and keep getting java versions. Please...

    Please help i need a C++ version of this code and keep getting java versions. Please C++ only Purpose: This lab will give you experience harnessing an existing backtracking algorithm for the eight queens problem, and seeing its results displayed on your console window (that is, the location of standard output). Lab A mostly complete version of the eight queens problem has been provided for you to download. This version has the class Queens nearly completed. You are to provide...

  • need help..... sudoku.h class sudoku { public: sudoku(); //default constructor //Postcondition: grid is initialized to 0...

    need help..... sudoku.h class sudoku { public: sudoku(); //default constructor //Postcondition: grid is initialized to 0 sudoku(int g[][9]); //constructor //Postcondition: grid = g void initializeSudokuGrid(); //Function to prompt the user to specify the numbers of the //partially filled grid. //Postcondition: grid is initialized to the numbers // specified by the user. void initializeSudokuGrid(int g[][9]); //Function to initialize grid to g //Postcondition: grid = g; void printSudokuGrid(); //Function to print the sudoku grid. bool solveSudoku(); //Funtion to solve the sudoku problem....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT