Beispiel #1
0
void QuestionTable::nextStep()
{
	Node * q = questions.headValue();
	while(true)
	{
		int i = newQuestionValue(q -> a);
		int j = questions.getN0();
		if (i == j)
			break;
		questions.addToTable(q, i);
		q = questions.headValue();
	}
	string s = fileName(q -> a, false);
	ifstream input(s.c_str());
	vector<int> pos;
	vector<int> neg;
	int m;
	int n;
	input >> m >> n;
	pos.resize(m);
	neg.resize(n);
	for (int i = 0; i < m; ++i)
	{
		input >> pos[i];
	}
	for (int i = 0; i < n; ++i)
	{
		input >> neg[i];
	}
	string str;
	getline(input, str);
	getline(input, str);
	input.close();
	int ans = userAnswer(str);
	Table* t = new Table(MAX_WRONG_ANS);
	if (ans == 1)
	{
		positive.addToQueue(q -> a);
		for (int i = 0; i < n; ++i)
		{
			int j = persons.search(neg[i]);
			if (j != -1)
			{
				Node* tmp = persons.current(j);
				if (j + 1 < MAX_WRONG_ANS)
				{
					t->addToTable(tmp, j + 1);
				}
				else
				{
					delete tmp;
				}
			}
		}
	}
	else if (ans == -1)
	{
		negative.addToQueue(q -> a);
		for (int i = 0; i < m; ++i)
		{
			int j = persons.search(pos[i]);
			if (j != -1)
			{
				Node* tmp = persons.current(j);
				if (j + 1 < MAX_WRONG_ANS)
				{
					t->addToTable(tmp, j + 1);
				}
				else
				{
					delete tmp;
				}
			}
		}
	}
	persons.addTable(t);
	delete t;	
	persons.setCurrentToHead();
}