std; const int ROWS = 3; const int COLS = 3; const int MIN = 1; const int MAX = 9; bool isMagicSquare(int arrayRow1[], int arrayRow2[], int arrayRow3[], int size); bool checkRange(int arrayRow1[], int arrayRow2[], int arrayRow3[], int size, int min, int max); bool checkUnique(int arrayRow1[], int arrayRow2[], int arrayRow3[], int siz

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++, create flowchart for this code:

#include <iostream>

using namespace std;

const int ROWS = 3;
const int COLS = 3;
const int MIN = 1;
const int MAX = 9;

bool isMagicSquare(int arrayRow1[], int arrayRow2[], int arrayRow3[], int size);
bool checkRange(int arrayRow1[], int arrayRow2[], int arrayRow3[], int size, int min, int max);
bool checkUnique(int arrayRow1[], int arrayRow2[], int arrayRow3[], int size);
bool checkRowSum(int arrayRow1[], int arrayRow2[], int arrayRow3[], int size);
bool checkColSum(int arrayRow1[], int arrayRow2[], int arrayRow3[], int size);
bool checkDiagSum(int arrayRow1[], int arrayRow2[], int arrayRow3[], int size);
void fillArray(int arrayRow1[], int arrayRow2[], int arrayRow3[], int size);
void showArray(int arrayRow1[], int arrayRow2[], int arrayRow3[], int size);

int main(){
int arrayRow1[ROWS], arrayRow2[ROWS], arrayRow3[ROWS];
char ch;
do{
fillArray(arrayRow1, arrayRow2, arrayRow3, ROWS);
showArray(arrayRow1, arrayRow2, arrayRow3, ROWS);
if(!isMagicSquare(arrayRow1, arrayRow2, arrayRow3, ROWS))
cout<<"This is not a Lo Shu magic square\n";
else
cout<<"This is a Lo Shu magic square\n";
cout<<"\n\nDo you want to try again?"; cin>>ch;
}while(ch=='y'||ch=='Y');
}

bool isMagicSquare(int arrayRow1[], int arrayRow2[], int arrayRow3[], int size){
if(!checkRange(arrayRow1, arrayRow2, arrayRow3, ROWS, 1, 9))
return false;
else if(!checkUnique(arrayRow1, arrayRow2, arrayRow3, ROWS))
return false;
else if(!checkRowSum(arrayRow1, arrayRow2, arrayRow3, ROWS))
return false;
else if(!checkColSum(arrayRow1, arrayRow2, arrayRow3, ROWS))
return false;
else if(!checkDiagSum(arrayRow1, arrayRow2, arrayRow3, ROWS))
return false;
return true;
}

bool checkRange(int arrayRow1[], int arrayRow2[], int arrayRow3[], int size, int min, int max){
for(int i = 0; i<size; i++){
if(arrayRow1[i]<min || arrayRow1[i]>max)
return false;
else if(arrayRow2[i]<min || arrayRow2[i]>max)
return false;
else if(arrayRow3[i]<min || arrayRow3[i]>max)
return false;
}
return true;
}

bool checkUnique(int arrayRow1[], int arrayRow2[], int arrayRow3[], int size){
int list[] = {0,0,0,0,0,0,0,0,0};
for(int i = 0; i<size; i++){
if(list[arrayRow1[i]] == 1)
return false;
else
list[arrayRow1[i]] = 1;
if(list[arrayRow2[i]] == 1)
return false;
else
list[arrayRow2[i]] = 1;
if(list[arrayRow3[i]] == 1)
return false;
else
list[arrayRow3[i]] = 1;
}
return true;
}

bool checkRowSum(int arrayRow1[], int arrayRow2[], int arrayRow3[], int size){
int sum = 0;
int sumnew = 0;
for(int i = 0; i<size; i++)
sum += arrayRow1[i];
for(int i = 0; i<size; i++)
sumnew += arrayRow1[i];
if(sumnew!=sum)
return false;
sumnew = 0;
for(int i = 0; i<size; i++)
sumnew += arrayRow1[i];
if(sumnew!=sum)
return false;
return true;
}

bool checkColSum(int arrayRow1[], int arrayRow2[], int arrayRow3[], int size){
int sum = 0;
int sumnew = 0;
sum = arrayRow1[0] + arrayRow2[0] + arrayRow3[0];
sumnew = arrayRow1[1] + arrayRow2[1] + arrayRow3[1];
if(sum!=sumnew)
return false;
sumnew = 0;
sumnew = arrayRow1[2] + arrayRow2[2] + arrayRow3[2];
if(sum!=sumnew)
return false;
return true;
}

bool checkDiagSum(int arrayRow1[], int arrayRow2[], int arrayRow3[], int size){
int sum = 0;
sum = arrayRow1[0] + arrayRow2[1] + arrayRow3[2];
int sumnew = arrayRow1[2] + arrayRow2[1] + arrayRow3[0];
if(sum!=sumnew)
return false;
return true;
}

void fillArray(int arrayRow1[], int arrayRow2[], int arrayRow3[], int size){
for(int i = 0; i<size; i++){
cout<<"Enter elements of row 0 and column "<<i<<": ";
cin>>arrayRow1[i];
}
for(int i = 0; i<size; i++){
cout<<"Enter elements of row 1 and column "<<i<<": ";
cin>>arrayRow2[i];
}
for(int i = 0; i<size; i++){
cout<<"Enter elements of row 2 and column "<<i<<": ";
cin>>arrayRow3[i];
}
}

void showArray(int arrayRow1[], int arrayRow2[], int arrayRow3[], int size){
for(int i = 0; i<size; i++)
cout<<arrayRow1[i]<<" ";
cout<<"\n";
for(int i = 0; i<size; i++)
cout<<arrayRow2[i]<<" ";
cout<<"\n";
for(int i = 0; i<size; i++)
cout<<arrayRow3[i]<<" ";
cout<<"\n";
}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 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
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