Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Could someone help me with my errors with my code? I know the code is not done yet but if you could help me I

Could someone help me with my errors with my code? I know the code is not done yet but if you could help me I will give thumbs up and if possible, if you want to you can see if you want to do it in your own way.

image text in transcribed

image text in transcribed

#include // this all is manditory for C++ language because with out it then the program would not run. #include // Objects of this class maintain a filebuf object as their internal stream buffer #include // used for input and output to a string. #include

bool canPlace(int array[][9], int r, int c, int num);

bool solveSudoku(int array[][9], int r, int c); bool separatecheck(int array[][9], int r, int c, int num);

int main() { ifstream fileopen; string filename; int sudoku[9][9]; int c=0; int x=0; int y=0; int index-0;

//this will ask for the sudoku board file while(!inFile.is_open()) { cout>filename; inFile.open(filename.c_str()); cin.clear(); }

while(!inFile.eof() && (index >c; sudoku[x][y]=c;

y++; index++; }

for (int i = 0; i >c; sudoku[i][j]=c; } }

x=0; index=0; y=0;

inFile.close();

//print the initialized board

cout

printBoard(sudoku);

if(solveSudoku(sudoku, x, y)==true); { cout

bool solveSudoku(int array[][9], int r, int c) { cout

for (int num = 1; num

if(solveSudoku(array, r +(c + 1) / 9, (c + 1) %9)) { return true; } } array[r][c]=0; } }

CS302 Assignment 2: Sudoku Solver SUDOKU Description Ah sudoku...a game that has been celebrated for a long time, now you all will get the chance to experience this simple yet complex game. The game of sudoku is traditionally played on a 9x9 board where each cell contains a number from 1 to 9. Seems simple but here is where it gets a bit complicated: you cannot have the same number on any row or column, and the real hard part is that there cannot be any duplicate number in all 9 3x3 sectors on the grid. 5 3 6 9 8 7 1 95 6 8 6 8 3 4 7 5 3 4 6 7 8 9 1 2 6 7 21 9 53 48 1 9 83 4 2/5 6 7 8 5 9 7 6 1 4 2 3 4 26 8 5 379 1 7 1 319 2 48 5 6 9 6 1 5 3 7 2 8 4 2 8 7 4 1 9 6 3 5 3 4 52 8 61 7 9 3 1 6 2 8 5 79 2 6 4 1 9 8 Figure 1: Initial Board Figure 2: Solved Board In figure 1, we have an initial sudoku board (this will be given as input to our program), and our program would need to fill out the blank spaces with numbers that solve the puzzle which is shown in figure 2. Notice the darker lines that separate each sector, so for example in the top left 3x3 sector, in figure 2, 4 is used in row 1 column 3, and no other cell in the sector uses 4, however in all other sectors, 4 appears once in each of them but they do not share a row or column in common. You can also find more information about sudoku using the following link https://en.wikipedia.org/wiki/Sudoku. You can also play the game to get a better idea if you want using the following link https://sudoku.com/. It will be your job to write a program that solves this, and don't worry, no linked lists to worry about this time, however you have to worry about everyone's favorite topic...recursion. Sample Run $ g++ main.cpp $ ./a.out Enter initial sudoku board file: file.txt initial sudoku board file: puzzle01.txt Enter Initial board read in 5 5 12 8 19 7 5 6 14 7 1 9 6 17 7 | - 9 - | - 25 | - 23 7 |- - 8 - 3 1 Sudoku puzzled solved | 8 | 2 | 3 6 4 5 1 | 3 76 9 | 4 5 92 4 71 1 8 | 9 5 31 7 2 1 8 6 1 | 1 3 | 4 8 19 7 2 | 8 6 | 5 5 | 2 4 9 6 7 | 5 9 1 I 7 3 3 | 1 8 2 | 6 15 | 7 9 2 1 4 1 2 5 1 3 7 81 3 | 7 8 4 | 6 1 91 8 | 9 3 6 4 2 5 | Enter initial sudoku board file: Yet Another .txt Enter initial sudoku board file: SUDOKU .txt Enter initial sudoku board file: puzzle02.txt Initial board read in | 5 3 | 6 - |- 9 7 9 1 1 51 T 8 6 6 | 8 | 4 | 7 8 3 31 1 1 61 2 3 CS302 Assignment 2: Sudoku Solver SUDOKU Description Ah sudoku...a game that has been celebrated for a long time, now you all will get the chance to experience this simple yet complex game. The game of sudoku is traditionally played on a 9x9 board where each cell contains a number from 1 to 9. Seems simple but here is where it gets a bit complicated: you cannot have the same number on any row or column, and the real hard part is that there cannot be any duplicate number in all 9 3x3 sectors on the grid. 5 3 6 9 8 7 1 95 6 8 6 8 3 4 7 5 3 4 6 7 8 9 1 2 6 7 21 9 53 48 1 9 83 4 2/5 6 7 8 5 9 7 6 1 4 2 3 4 26 8 5 379 1 7 1 319 2 48 5 6 9 6 1 5 3 7 2 8 4 2 8 7 4 1 9 6 3 5 3 4 52 8 61 7 9 3 1 6 2 8 5 79 2 6 4 1 9 8 Figure 1: Initial Board Figure 2: Solved Board In figure 1, we have an initial sudoku board (this will be given as input to our program), and our program would need to fill out the blank spaces with numbers that solve the puzzle which is shown in figure 2. Notice the darker lines that separate each sector, so for example in the top left 3x3 sector, in figure 2, 4 is used in row 1 column 3, and no other cell in the sector uses 4, however in all other sectors, 4 appears once in each of them but they do not share a row or column in common. You can also find more information about sudoku using the following link https://en.wikipedia.org/wiki/Sudoku. You can also play the game to get a better idea if you want using the following link https://sudoku.com/. It will be your job to write a program that solves this, and don't worry, no linked lists to worry about this time, however you have to worry about everyone's favorite topic...recursion. Sample Run $ g++ main.cpp $ ./a.out Enter initial sudoku board file: file.txt initial sudoku board file: puzzle01.txt Enter Initial board read in 5 5 12 8 19 7 5 6 14 7 1 9 6 17 7 | - 9 - | - 25 | - 23 7 |- - 8 - 3 1 Sudoku puzzled solved | 8 | 2 | 3 6 4 5 1 | 3 76 9 | 4 5 92 4 71 1 8 | 9 5 31 7 2 1 8 6 1 | 1 3 | 4 8 19 7 2 | 8 6 | 5 5 | 2 4 9 6 7 | 5 9 1 I 7 3 3 | 1 8 2 | 6 15 | 7 9 2 1 4 1 2 5 1 3 7 81 3 | 7 8 4 | 6 1 91 8 | 9 3 6 4 2 5 | Enter initial sudoku board file: Yet Another .txt Enter initial sudoku board file: SUDOKU .txt Enter initial sudoku board file: puzzle02.txt Initial board read in | 5 3 | 6 - |- 9 7 9 1 1 51 T 8 6 6 | 8 | 4 | 7 8 3 31 1 1 61 2 3

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_2

Step: 3

blur-text-image_3

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

The Accidental Data Scientist

Authors: Amy Affelt

1st Edition

1573877077, 9781573877077

More Books

Students also viewed these Databases questions

Question

How do modern Dashboards differ from earlier implementations?

Answered: 1 week ago