multi directional tree

I am not sure what to call this or even what exactly i am looking for but this is what i am trying to do. I want to create a program that asks the user for input and depending on the input, will ask the next appropriate question. The problem that i am having is all of my searches end up with binary search trees and i need the user to be able to put in more than just a yes or no. The answer for 1 question may be yes or no but the next question might want an error code number or maybe even a yes/no/unknown. I have looked up several types of containers and still cant find what i am looking for. does anyone know a good place for me to start?
It would help a lot if you posted some pseudo-code showing how you would like things to work in the ideal case. Does this look good?

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
#include <iostream>
#include <vector>
#include <string>
using namespace std;

//...

class Question
{
private:
    string actual_question;

public:
    Question(const string & aq):
        actual_question(aq){}

    virtual ~Question()=0;
    virtual void Ask()=0;
};

class QMultipleChoice: public Question
{
private:
    vector<string> choices;

public:
    QMultipleChoice(const string & aq):
        Question(aq){}

    void add_choice(string & str){/*...*/}

    virtual ~QMultipleChoice(){}
    virtual void Ask(){/*...*/}
};

class QNumberInput: public Question
{
public:
    QNumberInput(const string & aq):
        Question(aq){}

    virtual ~QNumberInput(){}
    virtual void Ask(){/*...*/}
};

//...

int main()
{
    vector<Question*> qlist;

    //...

    return 0;
}

Useful link -> http://cplusplus.com/doc/tutorial/polymorphism/
It sounds like you need some kind of tree container. There isn't one in the standard library. You would have to either make your own or find a third party library.
Yes, but I was thinking he may be able to avoid making a tree of all possible question sequences if he just generated in run-time the wanted sequence as the user answered the questions. Depending on an answer he may choose to push_back to the vector one or the other question.
Last edited on
Topic archived. No new replies allowed.