sudoku solver cell object orientated

Hey im new to object orientated classes and im using a 2d one with a flag of true and false as well as a candidate list for a vector, but i do not know how i can run through with triple context and delete a vector if it shows up in the triple context if anybody can help here is the code

cell.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
  #include "Cell.h"


Cell::Cell(void)
{
}

Cell::Cell(int pValue, bool pIsGiven)
{
	if (pValue < 0 || pValue > 9)
	{
		cout << "Values are larger or smaller than the range of the sudoku rules"<<endl;
	}
	else
	{
		if (pValue == 0)
		{
			pIsGiven = false;

			for (int i = 1; i < 10; i++)
			{
				candidateVector.push_back(i);
			}
		}
		else
		{
			cellValue = SetValue(pValue);
			pIsGiven = true;
			candidateVector.erase(candidateVector.begin(),candidateVector.end());
		}
	}
}
int Cell::GetValue()
{
	return cellValue;
}

int Cell::SetValue(int inValue)
{
	for (int i = 1; i < 10; i++)
			{
				if(!(inValue == i))
				{
				candidateVector.insert(candidateVector.begin(), i);
				}
			}
	return cellValue = inValue;
	
	
}

bool Cell::GetIsGiven()
{
	if (isGiven == true)
	{
		return true;
	}
	else
	{
		return false;
	}
}


int Cell::GetCandidateList()
{
	int passer;
	for (vector<int>::iterator it = candidateVector.begin(); it < candidateVector.end(); it++)
	{
		passer = *it;
	}
	return passer;
}



Cell::~Cell(void)
{
}



cell.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#pragma once
#include <iostream>
#include<string>
#include <vector>
#include<iterator>


using namespace std;
class Cell
{
public:
	Cell(void);
	Cell(int inValue, bool inIsGiven);
	~Cell(void);
	int SetValue(int sValue);
	int GetValue();

	
	bool GetIsGiven();

	int GetCandidateList();
	
private:
	int cellValue;
	bool isGiven;//wheter it is given to us by the defined unsolved puzzle
	vector<int> candidateVector;
};



main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
void ReadInFile()
	{
	 ifstream file("sudoku_puzzle.txt");
    //reads in the file and saves to the 2d array
    for (int row = 0; file && row < ROWS; ++row){
		int inValue;
        for (int col = 0; file >> inValue && col < COLS; ++col){
			if(col == 8)
			{
				grid[row][col].SetValue(inValue);
			}
            if (file.get() != ' '){ 
				break;
			}
			
				grid[row][col].SetValue(inValue);
			
		}
	}
Help?
??
Please clarify your question and maybe comment your code:

What do you mean by using 2d object orientated classes ?
What is triple context?
What is candidateVector supposed to represent? Is it a list of possible values?
What is happening in first if clause in constructor in your code?
What is the meaning of cell value 0?

To solve the sudoku, you need to represent an entire board, not just single cell. Do you have a representation for the board?

Also, a tip of the day:
Did you know, that people who read this forum with intention of helping others often skip those topics that have been answered? They might consider that help has already been given to the interested party, so there is no point in bumping.
Last edited on
To solve the sudoku, you need to represent an entire board not just single cell. Do you have a representation for the board?
I do this is represented as a cell object named Cell Grid[9][9].

What do you mean by using 2d object orientated classes ? Not entirely sure myu self but the classes above are ment to be used in the method of main.

What is triple context? Triple context is a method or finding if a number is within the cell, row and column of the given number.

What is candidateVector supposed to represent? Is it a list of possible values?
possibvle values that can be in the cell that is not already in the triple context as explained above

What is happening in first if clause in constructor in your code? if the number is 0-9 then it is a value, if it is anything else throw an error.

What is the meaning of cell value 0? Cell value 0 is an unknown cell.
Thanks
Great. Look at this old topic http://www.cplusplus.com/forum/beginner/101567/

If you check the code, and run it, you will see how you can look at any of 81 cells in context of row, column and 3x3 grid it belongs to. From there it is just a step to remove false candidates from each cell;

Topic archived. No new replies allowed.