Question: Solution.h - #ifndef SOLUTION_H #define SOLUTION_H class solution { private: int grid[9][9]; public: solution(); void read(); bool verify() const; void print() const; }; #endif Solution.cpp

![grid[9][9]; public: solution(); void read(); bool verify() const; void print() const; };](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f3c4428cf7d_52166f3c441e89f0.jpg)

Solution.h -
#ifndef SOLUTION_H #define SOLUTION_H class solution { private: int grid[9][9]; public: solution(); void read(); bool verify() const; void print() const; }; #endifSolution.cpp -
#include#include "solution.h" using std::cout; int main() { solution s; // Read the solution file as input s.read(); // Print the Sudoku grid s.print(); // Verify whether or not the solution is correct if (s.verify()) cout
invalid1.txt -
1 9 8 7 6 5 4 3 2 2 1 9 8 7 6 5 4 3 3 2 1 9 8 7 6 5 4 4 3 2 1 9 8 7 6 5 5 4 3 2 1 9 8 7 6 6 5 4 3 2 1 9 8 7 7 6 5 4 3 2 1 9 8 8 7 6 5 4 3 2 1 9 9 8 7 6 5 4 3 2 1invalid2.txt -
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
valid1.txt -
2 3 4 9 5 6 8 1 7 9 5 7 8 1 4 2 6 3 1 8 6 3 7 2 4 5 9 5 4 9 6 8 1 7 3 2 6 1 8 7 2 3 5 9 4 7 2 3 4 9 5 6 8 1 3 9 2 5 6 7 1 4 8 4 7 5 1 3 8 9 2 6 8 6 1 2 4 9 3 7 5
valid2.txt -
3 5 4 8 6 7 1 2 9 6 7 8 9 2 1 3 5 4 1 9 2 5 3 4 6 7 8 7 3 5 1 4 9 2 8 6 4 1 9 6 8 2 7 3 5 8 2 6 7 5 3 4 9 1 9 6 1 3 7 5 8 4 2 2 8 3 4 9 6 5 1 7 5 4 7 2 1 8 9 6 3makefile -
CXX = /usr/bin/g++ CXXFLAGS = -Wall -Werror -ansi -pedantic -std=c++14 RM = /bin/rm sudoku: FORCE $(CXX) $(CXXFLAGS) -o sudoku sudoku.cpp solution.cpp clean: FORCE $(RM) -rf sudoku *.o FORCE:
Verify the Correctness of a Sudoku Solution Sudoku is a logic-based, combinatorial number-placement puzzle. The rules of Sudoku are quite simple. In a traditional sudoku puzzle (and there are variations) the objective is to fill a 99 grid with digits so that each column, each row, and each of the nine 33 sub-grids that compose the grid (also called "boxes", "blocks", "regions", or "sub-squares") contains all the digits from 1 to 9. The puzzle setter provides a partially completed grid, which typically has a unique solution. For a solution to a Sudoku puzzle to be correct, the following conditions must hold true: - Every row should contain the digits 1 to 9 but should not repeat the digits 1 to 9 at any point within that row. - Every column should contain the digits 1 to 9 but should not repeat the digits 1 to 9 at any point within that column. - Every 33 sub-grid should contain the numbers 1 to 9 but should not repeat the numbers 1 to 9 at any point within that sub-grid. Row 1 to 9 , No Duplicates A completed sudoku grid like the one to the left uses all the numbers 1,2,3,4,5,6,7,8,9 in every row, every column and every 33 square every 33 square (marked on the grid by (marked on the grid by the thicker lines) without duplieating any of these duplicating any of these numbers in any single rows, column of 33 rows, block. 53 urla, No vupucates The example to the left shows the same sudoku grid as above but completed incorrectly. 3 repeated in same 33 Writing a computer program to solve Sudoku puzzles can be quite challenging, and typically uses algorithms and data structures outside the scope of an intermediate class in programming. However, writing a program that will check a solution to a Sudoku puzzle and verify that it is correct is a lot easier. Files We Give You: A makefile and a sample main program (sudoku.cpp) to test your code. The executable file created by a successful build will be named sudoku. The header file solution. h contains a class definition for a class called solution (described on the following page) that can be used to verify the correctness of a Sudoku solutions. The source file solution. cpp contains member function definitions for the class, all but one of which have already been implemented. You will need to complete the final member function definition. Seven input files have been provided that can be used to test your program. The files valid1.txt, valid2. txt, and valid3. txt are valid puzzle solutions, while the other four are all invalid for one reason or another. File You Must Submit: Complete the solution: :verify () member function in the file solution. cpp. This will be the only file that you submit. he solution Class he header file solution. h contains a definition of a class named solution that can be used to erify the correctness of a Sudoku puzzle solution. The class has a private data member named grid that represents a Sudoku grid as a twolimensional array of integers with 9 rows, each with 9 columns. The class has the following public member functions defined in solution. cpp, all but one of vich have already been completed. - solution: :solution() Class constructor. Sets the grid elements to 0 . The definition for this function is already complete. - void solution: :read() This member function reads the values of the Sudoku grid from standard input. The definition for this function is already complete. - void solution::print() const This member function prints the Sudoku grid array to the screen as 9 rows of 9 columns. The definition for this function is already complete. - bool solution::verify() const This member function takes no arguments. It should return a Boolean value - true if the Sudoku grid array contains a valid solution, false if not. As provided, this function always returns true. You will need to complete the code for this function to make it work correctly. The exact technique you use to verify whether a solution is correct or not is up to you, but it will most likely require you to loop through the columns of each row looking for duplicate values, loop through the rows of each column looking for duplicate values, and loop through the rows and columns of each sub-grid looking for duplicate values
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
