Answer to Question #261507 in C++ for saliha

Question #261507

A decision tree is a decision support tool that uses a tree-like model of decisions and their

possible consequences. It is widely used in classification and prediction problems. You are required to

implement the below decision tree to help you decide whether you should go for a trip or not based on

various factors. You also need to take string inputs from the user in this program.



1
Expert's answer
2021-11-05T17:29:35-0400
#include <stdexcept> 
#include <vector> 
 
using std::runtime_error; 
using std::vector; 
 
class TreeNode {    
protected:    
    vector<TreeNode> next;  
    int s;  
      
public:  
    TreeNode(int n_out) { next.resize(n_out); }  
    virtual ~TreeNode() {}   
    virtual void setState(int val) { s = val; }  
    virtual TreeNode branch_next(); 
}; 
      
class DecisionNode : public TreeNode { T  
Nivate:  
    vector<int> bpcts;  
      
public:  
    DecisionNode(int n_out) : TreeNode{n_out} { 
    	bpcts.resize(n_out);  
    }  
    DecisionNode(int n_out, vector<int> b_percents 
		    ) : DecisionNode(n_out)  { 
    	bpcts = b_percents;  
    }  
    virtual ~DecisionNode() {}  
    virtual TreeNode branch_next() {  
    	return next[s];  
    }  
}; 
      
class chance_node : public TreeNode {  
public:  
    chance_node() : TreeNode{1} {}  
    virtual ~chance_node() {}  
    virtual TreeNode branch_next() {  
    	return next[0];  
    }  
}; 
      
class EndNode : public TreeNode {  
public:  
    EndNode() : TreeNode{0} {}  
    virtual ~EndNode() {}  
    virtual TreeNode branch_next() {  
    	runtime_error("Decision is made"); 
    	return TreeNode(0); 
    }  
};

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS