Note that there are some explanatory texts on larger screens.

plurals
  1. POC linking programs and using methods from other programs on main function (sudoku
    primarykey
    data
    text
    <p>NOTE: skip to bottom for real question</p> <p>Hey guys, right now I am in a rut where I know the basics how to solve my sudoku program, but if I did it the way i know how it would be ugly, long and a lot of unnecessary code. </p> <p>Right I have sudoku.cc, sudokuboard.cc, sudokuboard.h, stack.cc, and stack.h, So as of right now it doesn't matter what my stack.cc and my stack.h are because they are rather generic and anyone can find the programs to them and frankly I don't underdstand why I even need to include the stack.cc/h due. </p> <p>My sudoku.cc as of right now is: </p> <pre><code>#include &lt;iostream&gt; #include &lt;cassert&gt; #include &lt;fstream&gt; #include "sudokuboard.h" #include "stack.h" using namespace std; int main (void) { FILE *fp = fopen("test.txt","r"); char sudoku_grid[9][9]; char ch; if(fp != NULL) { for(int i = 0; i &lt; 9; i++) { for(int j = 0; j &lt; 9; j++) { ch = fgetc(fp); sudoku_grid[i][j] = ch; } ch = fgetc(fp); } for(int i = 0; i&lt; 9;i++) { for(int j= 0; j&lt;9;j++) cout&lt;&lt;sudoku_grid[i][j]; cout&lt;&lt;endl; } } return 0; } </code></pre> <p>Which so far does nothing but print out the file I gave it and have it stored in a 2D array.</p> <p>My sudokuboard.h is </p> <pre><code>#include &lt;iostream&gt; #define SDIM 9 class SudokuBoard { public: //------------------------------------------------------------------------ SudokuBoard(); // Construct a blank sudoku board //------------------------------------------------------------------------ //------------------------------------------------------------------------ void print(std::ostream &amp; ostr) const; // display it. duh. //------------------------------------------------------------------------ //------------------------------------------------------------------------ void place(size_t r, size_t c, char digit); // PRE: safe(r,c,digit) //------------------------------------------------------------------------ //------------------------------------------------------------------------ void remove(size_t r, size_t c, char digit); // PRE: get(r,c) == digit //------------------------------------------------------------------------ //------------------------------------------------------------------------ char get(size_t r, size_t c) const; // Return the digit at (r,c) on the board. or ' ' if blank. //------------------------------------------------------------------------ //------------------------------------------------------------------------ bool safe(size_t r, size_t c, char digit) const; // //------------------------------------------------------------------------ //------------------------------------------------------------------------ bool done() const; // Return true iff every cell has a number //------------------------------------------------------------------------ private: std::string rows[SDIM]; }; </code></pre> <p>and my sudokuboard.cc:</p> <pre><code>#include &lt;iostream&gt; #include &lt;cassert&gt; #include "sudokuboard.h" #define ASSERTBOUNDS assert(0 &lt;= r and r &lt; SDIM and 0 &lt;= c and c &lt; SDIM) SudokuBoard::SudokuBoard() { for (size_t i = 0;i&lt;SDIM;i++) { rows[i] = ""; for (size_t j=0;j&lt;SDIM;j++) rows[i] += ' '; } } void SudokuBoard::place(size_t r, size_t c, char digit) { ASSERTBOUNDS; assert(safe(r,c,digit)); } void SudokuBoard::remove(size_t r, size_t c, char digit) { ASSERTBOUNDS; assert(get(r,c)==digit); rows[r][c] = ' '; } char SudokuBoard::get(size_t r, size_t c) const { ASSERTBOUNDS; return rows[r][c]; } void SudokuBoard::print(std::ostream &amp; ostr) const { for (size_t i=0;i&lt;SDIM;i++) ostr &lt;&lt; rows[i] &lt;&lt; std::endl; } bool SudokuBoard::safe(size_t r, size_t c, char digit) const { for(size_t r=0; r&lt;SDIM; r++) for(size_t c=0; c&lt;SDIM; c++) if (get(r,c) == digit) return false; for(size_t c=0; c&lt;SDIM; c++) for(size_t r=0; r&lt;SDIM; r++) if (get(r,c) == digit) return false; return true; } bool SudokuBoard::done() const { for (size_t r=0;r&lt;SDIM;r++) for (size_t c=0;c&lt;SDIM;c++) if (rows[r][c]==' ') return false; return true; } </code></pre> <p>So as of right now I want to use sudokuboard.cc methods and use the SudokuBoard() in my sudoku.cc because I know if I do that I will be able to use the useful methods provided by Sudokuboard.cc thus making my code seem a lot cleaner because it isn't all cluttered up on one program. </p> <p>So as of right now I think the gateway to linking these two programs together in order to maximize my space I would have to set my current 2D array which is <strong>sudoku_grid</strong> to be part of Sudokuboard() some how. </p> <p>The problem is that I literally have no blinkin idea how to hook this puppies up. I know I cannot do <strong>sudoku_grid = Sudokuboard()</strong> because even if it did work, it would probably set all the arrays to being just spaces.</p> <p>Anyone have a solution of where to start off?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload