Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include #include #include using namespace std; int eqn; //function to check for the magic number bool magic(int sum) { if(eqn == sum) return true; else

#include #include #include using namespace std; int eqn; //function to check for the magic number bool magic(int sum) { if(eqn == sum) return true; else return false; } //check for duplicate in the given data bool dup(int checkDuplicate[],int n) { for(int i=0;i> nMetrix; eqn = (nMetrix *((nMetrix*nMetrix)+1) )/2; int checkDuplicate[nMetrix*nMetrix]; int matrix[nMetrix][nMetrix]; int allSum[nMetrix*nMetrix]; int sumLen = 0; int count = 0; for(int i=0;i > number; matrix[i][j] = number; checkDuplicate[count++] = number; } } cout

for(int i = 0; i

int len = nMetrix - 1; DiagonalSum = 0; for(int i = 0; iPlease help me to fix this code.

image text in transcribed

image text in transcribedimage text in transcribed

TITLE IDENTIFYING A SUDOKU SOLUTION INTRODUCTION A Sudoku puzzle is a 9x9 grid in which some---usually around 28 or 30---of the cells are filled with integers in the range of 1 to 9; the other cells are empty. A region of the puzzle is one of the nine 3x3 non-overlapping squares of cells within the grid. No integer is duplicated within any row, column, or region, and the puzzle's goal is to fill the remaining cells with integers from 1 to 9 so that this non- duplication property is maintained. Here is a typical Sudoku puzzle and its solution: 49 61385479 41 9756823 19 JOD COC 83 9 14 719 71283 19||1||4|5 8 llar Im 358214796 5 2 1 co |83|65|7|2|914 1912 |1|43168 |147|96|8532 9165 DESCRIPTION In this project, you are to design, implement, document, and test a C++ program that reads a 9x9 matrix of integers from a data file and reports whether or not the matrix satisfies the requirements of Sudoku; that is, whether or not any value is duplicated in any row, column, or region in the matrix. Note that the program will NOT solve a Sudoku puzzle, only test whether a matrix satisfies the puzzle's requirements. INPUT The program will read the name of a data file from the terminal and the elements of a 9x9 matrix from the named file. A data file might look like this: 794 6 2 1 3 5 8 5 8 3 4 9 7 2 6 1 261 3 8 5 4 7 9 41 975 68 8 2 3 6 7 2 8 3 9 1 4 5 3 5 8 2 1 4 7 96 8 3 6 5 7 2 914 9 2 5 1 4 3 6 8 7 1 4 7 9 6 8 5 3 2 OUTPUT The program will prompt for the name of the input file and write to the terminal the matrix being tested and whether or not it is a Sudoku solution, that is, whether or not there are any dpulicated values in any of the matrix's rows, columns, or regions. The program will write all output to the terminal. ERRORS The program may assume the input is as described; it need not detect any errors. EXAMPLE Two runs of the program might look like this: csh> sudoku Enter input file name: ml.dat The matrix 7 9 4 6 2 1 3 5 8 5 8 34 9 7 2 6 1 2 6 1 3 8 5 4 7 9 4 1 9 7 5 6 8 23 6 7 2 8 3 9 1 4 5 3 5 8 2 1 4 7 9 6 8 3 6 5 7 2 9 1 4 9 2 5 1 4 3 6 8 7 1 4 7 9 6 8 5 3 2 is a Sudoku solution. csh> sudoku Enter input file name: m2.dat The matrix 1 9 4 6 2 1 3 5 8 5 8 34 9 7 2 6 1 2 6 1 3 8 5 4 7 9 419756823 6 7 2 8 3 9 1 45 353 2 1 479 6 83 6 5 7 2914 9 2 5 1 4 3 6 8 7 1 4 7 9 6 8 5 3 2 is NOT a Sudoku solution. OTHER REQUIREMENTS Represent the candidate matrix in a two-dimensional array. Use functions to (1) open the input file; (2) read the matrix in; (3) test if the rows, columns, and regions of the matrix contain duplicate values; and (4) write out a matrix. HINTS The functions that test the rows, columns, and regions will all return boolean values. In each, a one-dimensional frequency matrix will likely be useful. Pass the coordinates of each region's upper left corner to the function that tests if a region contains duplicates AN EXTENSION Consider extending your program to report how an array that is not a solution fails<>

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Horse Betting The Road To Absolute Horse Racing 2

Authors: NAKAGAWA,YUKIO

1st Edition

B0CFZN219G, 979-8856410593

More Books

Students also viewed these Databases questions

Question

What is the difference between Needs and GAP Analyses?

Answered: 1 week ago

Question

What are ERP suites? Are HCMSs part of ERPs?

Answered: 1 week ago