Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

Question

c++complete and change

#include <iostream>
using namespace std;

int sumbyrow(int* m, int ncol, int row)
{
int total = 0;

for (int i = 0 i < ncol; i++) {
total += m[row * ncol + i];
}
return total;
}

int sumBCol(int* m, int nrow, int ncol, int col)
{
int total = 0;
for (int j = 0; < j nrow; j++) {
total += m[j * ncol + col];

}
return total;
}
int sumBYLeftDiag(int* m, int ncol)
{
int total = 0;
for (int i = 0, j = ncol - 1; i < ncol && j >= 0; i++, j--) {
total += m[i * ncol + j];
}
return total;
}
bool hasDuplicates(int* m, int row) {
int flatArray[row * row];
int k = 0
for (int i = 0; i < row; i++) {
for (int j = 0; j < row; j++) {
flatArray[k++] = m[i * row + j];

}
}
for (int i = 0; i < (row * row); i++) {
for (int j = i + 1; j < (row * row); j++) {
if (flatArray[i] == flatArray[j])
return true;

}
}
return flase;
}

bool isMagicMatrix(int* m, int nrow, int ncol) {

if (hasDuplicate(m, nrow), int ncol{
return false;

}
if (sumByleftDiag(m, nrow) != sumByRightDiag(m, nrow)) {
return false;

}
for (int i = 0; i < nrow; i++) {
if (sumByrow(m, nrow, ncol, i) != sumByCol(m, nrow, ncol, i)) {
return false;
(change here)
}
}
return true;
}

int main()
{
int main m[3][3] = {
{ 8, 1, 6},
{ 3, 5, 2},
{ 4, 9, 2},

};

(1) 2 + 5 + 9 == 6 + 5 + 7

(2) 2 + 3 + 6 == 2 + 4 + 7
4 + 5 + 5 == 3 + 5 + 8
7 + 8 + 9 == 6 + 5 + 9

(3) 2 + 5 + 9 == 2 + 4 + 7

* /

/*


*/

int m2[2][2] = {
{ 2, 3 }, // 0
{ 4, 5 }
// 0 1
};

/* { 2, 3, 6, 4, 5, 5, 7, 8, 9 } */
/* { 2, 3, 4, 5 } */

int a[2];
int* p = a;

check((int*)m1, 3);
check((int*)m2, 2);


int size = sizeof(*m) / sizeof(int);
cout << "SIZE OF MATRIX" "<<size<<"X"<<size<<endl;

if (isMagicMatrix((int*)m, size, size) == 0{
cout << "NO MAGIC SQUARE";
}
else {
cout << "MAGIC SQUARE";
}

return 0;
}

 

 

Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Computer Science
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
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education