Build an object-oriented simulation of the probability demonstration given in class. Use linked lists. Define two classes: a tree class and a node class. Use separate header and implementation files. You may not use an array (anywhere) or anything like unto it. This prohibition includes containers from the standard template library. Use recursion to build the tree, pass the balls through the structure, and get the results for output. In main, do the following:
1. instantiate the tree class
2. send the tree object a message to drop 256 virtual balls; the tree object drops these one at a time
3. output the results using operator overloading of the stream insertion operator (do not output from any class; stringstream may be used
I have the basic's of everything and even kinda have a sorta pascal's triangle, but not what has to be had. Here's what I have
In Main: This is all that can be in main
#include "tree.h"
int main(void)
{
tree plinko;
plinko.drop(plinko, 256);
plinko.getResults();
return 0;
}
tree.h:
#include <iostream>
using namespace std;
class tree
{
public:
tree(void);
~tree(void);
void getResults(void);
void drop(tree, int);
friend ostream &operator<<(ostream &out, tree);
};
class node: friend tree //I don't know why this friend won't work.
{
private://I think this is on the right track
tree left;
tree right;
public:
node(void);
~node(void);
};
tree.cpp
#include "tree.h"
tree::tree(void)
{
}
tree::~tree(void)
{
}
node::node(void)
{
}
node::~node(void)
{
}
void tree::drop(tree plinko, int numBalls)
{
int rows, direction;
srand(time(NULL));
for(int i=0; i < numBalls; i++)
{
for(int j=0; j < rows; j++)
{
direction = rand() %2;
if(direction == 0)
{
//go left rout
}
else
{
//go right rout
}
}
}
}
void tree::getResults(void)
{
}
ostream &operator<<(ostream & out, tree plinko)
{
out;//enter here what I want to be out put
return out;
}
here is the recursion creating the triangle that I do have
long plinko(int n, int r)
{
if ((n == 0) || (r == 0) || (n == r)) return 1;
else return (plinko(n-1,r-1) + plinko(n-1,r));
} // This is the recursive function