Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Solving Sudoku Puzzles (sudoku.h; sudokuImp.cpp; sodokuDriver.cpp) The goal of Sudoku is to assign digits to the empty cells so that every row, column, and sub-grid

Solving Sudoku Puzzles (sudoku.h; sudokuImp.cpp; sodokuDriver.cpp)

The goal of Sudoku is to assign digits to the empty cells so that every row, column, and sub-grid contains exactly one instance of the digits from 1 to 9. The starting cells are assigned to constrain the puzzle such that there is only one way to finish it. Sudoku solvers pride themselves on the fact that there is no need to guess to solve the puzzle, the careful application of logic will lead you to the solution.

Some recursive backtracking pseudocode:

Find row, we find the first empty grid slot. Next we find the first number, between 1 to 9, that can be placed in this slot. Before placing a number in an empty slot, we must check that the number does not appear in the row, column, and the 3 x 3 grid containing the slot. After placing a number the first empty slot, we find the next empty slot and try to place a number in that slot. If a number cannot be placed in a slot, then we must backtrack to the previous slot, where the number was placed, place a different number, and continue. If we arrive at a slot where no number can be placed, then the Sudoku problem has no solutions.

You are given the header file, you need to write an implementation file and a driver file. You can modify the sudoku class (header file) as you wish.

You can copy the partially filled sudoku grid of the given sample outputs to test your program.

Please use this header file:

// this is the header file // you can modify or add additional functions/variable as you wish. // class sudoku { public: sudoku(); //default constructor //Postcondition: grid is initialized to 0

sudoku(int g[][9]); //constructor //Postcondition: grid = g

void initializeSudokuGrid(); //Function to promt 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. //Postcondition: If a solution exits, it returns true, // otherwise it returns false. bool findEmptyGridSlot(int &row, int &col); //Function to determine if the grid slot specified by //row and col is empty. //Postcondition: Returns true if grid[row][col] = 0;

bool canPlaceNum(int row, int col, int num); //Function to determine if num can be placed in //grid[row][col] //Postcondition: Returns true if num can be placed in // grid[row][col], otherwise it returns false.

bool numAlreadyInRow(int row, int num); //Function to determine if num is in grid[row][] //Postcondition: Returns true if num is in grid[row][], // otherwise it returns false.

bool numAlreadyInCol(int col, int num); //Function to determine if num is in grid[row][] //Postcondition: Returns true if num is in grid[row][], // otherwise it returns false.

bool numAlreadyInBox(int smallGridRow, int smallGridCol, int num); //Function to determine if num is in the small grid //Postcondition: Returns true if num is in small grid, // otherwise it returns false.

private: int grid[9][9]; };

image text in transcribed

Three Sample Outputs Sample Output 2 Sample Output 1 Sample Output 3 Enter partially filled sudoku grid: Enter partially filled sudoku grid: JO 80170003 020000009 0 90030548 0 04090000 O 0070 3000 1000010400 619 080050 7 00000080 2 0006 4010 19 567 2438 208043750 000000020 000091305 004000100 509360000 05 1000000 04 2150809 000024000 Enter partially filled sudoku grid: 0 0 300 2000 2 2600 94000 008530006 0 56000190 000000000 0 21000 570 6000 25 400 000 910067 008 600 900 grid before solution: 080170003 0 20000009 090030548 0 04090000 0 0 0 70 3000 1000010400 619 080050 1700000080 2000 64010 grid before solution: 19 5 6 7 2438 208043750 000000020 000091305 004000100 5093 60000 051000000 042150809 000024000 grid before solution: 00300 2000 2 600 94000 008530006 0 56 000190 000000000 0 21000570 6000 2 5400 000 910067 0 0 86 00 900 Solution:- Solution- No solutions. 48 5 1 7 9 6 2 3 3 2 6 4 5 8 179 1976 3 2 5 48 8 3429 5761 5 6 1 743 892 19 7 2 8 16 435 619 3 8 72 54 743 5 2 1986 258 9 6 4317 19 5 6 7 2438 2 6 8 943 751 473518 926 8 8 2 749 1365 63428 5197 519 36 7284 7518 3 9 6 42 3 4 2 1 5 6 8 79 9 8 6 7 24513

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

SQL Database Programming

Authors: Chris Fehily

1st Edition

1937842312, 978-1937842314

Students also viewed these Databases questions

Question

3. How can firms assess the business value of information systems?

Answered: 1 week ago

Question

What is the purpose of the Salary Structure Table?

Answered: 1 week ago

Question

What is the scope and use of a Job Family Table?

Answered: 1 week ago