//file Sudoku002.cpp
//authors aou
//date 2006.02.03
#include <iostream>
using namespace std;
/*
Project 01, date assigned 2006.02.03, date due 2006.02.10
Implement the following member function:
bool isValid(void);
test it on two puzzles, one good and one bad
*/
int bad[9][9]=
{
{1,2,3,4,5,6,7,8,0},
{1,2,3,4,5,6,7,8,9},
{9,8,7,6,5,4,3,2,1},
{1,2,3,4,5,6,7,8,9},
{1,2,3,4,5,6,7,8,9},
{9,8,7,6,5,4,3,2,1},
{1,2,3,4,5,6,7,8,9},
{1,2,3,4,5,6,7,8,9},
{0,8,7,6,5,4,3,2,1}
};
int good[9][9]=
{
{0,0,0,4,5,6,7,8,0},
{1,2,3,4,5,6,7,8,9},
{9,0,7,6,5,4,3,2,1},
{1,2,3,4,5,6,7,8,9},
{1,2,3,4,5,6,7,8,9},
{9,8,7,6,5,4,3,2,1},
{1,2,3,4,5,6,7,8,9},
{1,2,3,4,5,6,7,8,9},
{0,8,7,6,5,4,3,2,1}
};
class CSudoku
{
private:
int a[9][9];
public:
CSudoku(void); //default constructor
CSudoku(int d[9][9]); //custom constructor
void display(void);
bool isValid(void); //Project 01 test it on two puzzles one good and one bad
void createNew(void);
bool checkSolution(void);
bool isvalidMove(int r, int c, int n);
bool solve(void);
};
void main(void)
{
CSudoku puzzle1, puzzle2(good);
puzzle1.display();
cout << endl;
puzzle2.display();
cout << endl;
CSudoku puzzle3(bad);
puzzle3.display();
cout << endl;
if (puzzle3.isValid())
cout << "This is a good pouzzle\n";
else
cout << "This is NOT a good pouzzle\n";
}
bool CSudoku::isValid(void)
{
//supply the missing code
return true;
}
CSudoku::CSudoku(void)
{
for (int r=0; r<9; r++)
for (int c=0; c<9; c++)
a[r][c] = 0;
}
CSudoku::CSudoku(int d[9][9])
{
for (int r=0; r<9; r++)
for (int c=0; c<9; c++)
a[r][c] = d[r][c];
}
void CSudoku::display(void)
{
for (int r=0; r<9; r++)
{
for (int c=0; c<9; c++)
{
if (a[r][c]==0)
cout << ' ';
else
cout << a[r][c];
if (c==2 || c==5)
cout << '|';
else
cout << ' ';
}
cout << endl;
if (r==2 || r==5)
cout << "-----+-----+-----\n";
}
}
|