Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using the following C++ code.... 1. Discussion of the Data Structures used. 2. D

ID: 3864718 • Letter: U

Question

Using the following C++ code....

1. Discussion of the Data Structures used.

2. Discussion of the used Algorithm.

3. Discussion of the performance of the algorithm based on the results.

4. Discussion of weaknesses of the used algorithm along with any possible enhancements.

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std;
#define UNASSIGNED 0
#define N 9

bool FindEmptyLocation(int grid[N][N], int &row, int &col);
bool isSafe(int grid[N][N], int row, int col, int num);

/* assign values to all unassigned locations for Sudoku solution
*/
bool StartSolvingSudoku(int grid[N][N])
{
int row, col;
if (!FindEmptyLocation(grid, row, col))
return true;
for (int num = 1; num <= 9; num++)
{
if (isSafe(grid, row, col, num))
{
grid[row][col] = num;
if (StartSolvingSudoku(grid))
return true;
grid[row][col] = UNASSIGNED;
}
}
return false;
}

/* Searches the grid to find an entry that is still unassigned. */
bool FindEmptyLocation(int grid[N][N], int &row, int &col)
{
for (row = 0; row < N; row++)
for (col = 0; col < N; col++)
if (grid[row][col] == UNASSIGNED)
return true;
return false;
}

/* Returns whether any assigned entry n the specified row matches
the given number. */
bool UsedInRow(int grid[N][N], int row, int num)
{
for (int col = 0; col < N; col++)
if (grid[row][col] == num)
return true;
return false;
}

/* Returns whether any assigned entry in the specified column matches
the given number. */
bool UsedInColumn(int grid[N][N], int col, int num)
{
for (int row = 0; row < N; row++)
if (grid[row][col] == num)
return true;
return false;
}

/* Returns whether any assigned entry within the specified 3x3 box matches
the given number. */
bool UsedInCubical(int grid[N][N], int boxStartRow, int boxStartCol, int num)
{
for (int row = 0; row < 3; row++)
for (int col = 0; col < 3; col++)
if (grid[row+boxStartRow][col+boxStartCol] == num)
return true;
return false;
}

/* Returns whether it will be legal to assign num to the given row,col location.
*/
bool isSafe(int grid[N][N], int row, int col, int num)
{
return !UsedInRow(grid, row, num) && !UsedInColumn(grid, col, num) &&
!UsedInCubical(grid, row - row % 3 , col - col % 3, num);
}

/* print grid */
void printSolvedGrid(int grid[N][N])
{
for (int row = 0; row < N; row++)
{
for (int col = 0; col < N; col++)
cout<<grid[row][col]<<" ";
cout<<endl;
}
}

/* Main */
int main()
{
cout << "Welcome to SUDOKU"<<endl;
cout << "(note: leave a space between numbers)"<<endl;
string mystr;
int count = 0;

int grid[N][N]; //= new int[9][9];
for (int row = 0; row < 9; row++) {

cout << "Enter values for row " << row + 1 << " : ";
for (int col = 0; col < 9; col++){
cin >> grid[row][col];}
}
cout<<endl << "Solution:" <<endl << endl;
// int grid[N][N] = {{3, 0, 6, 5, 0, 8, 4, 0, 0},
// {5, 2, 0, 0, 0, 0, 0, 0, 0},
// {0, 8, 7, 0, 0, 0, 0, 3, 1},
// {0, 0, 3, 0, 1, 0, 0, 8, 0},
// {9, 0, 0, 8, 6, 3, 0, 0, 5},
// {0, 5, 0, 0, 9, 0, 6, 0, 0},
// {1, 3, 0, 0, 0, 0, 2, 5, 0},
// {0, 0, 0, 0, 0, 0, 0, 7, 4},
// {0, 0, 5, 2, 0, 6, 3, 0, 0}};
if (StartSolvingSudoku(grid) == true)
printSolvedGrid(grid);
else
cout<<"No solution exists"<<endl;
return 0;
}

Explanation / Answer

#include #include #include using namespace std; struct movies_t { string title; int year; } mine, yours; void printmovie (movies_t movie); int main () { string mystr; mine.title = "2001 A Space Odyssey"; mine.year = 1968; cout yours.year; cout