For my homework I'm supposed to make a guessing game. The instructions say to use at least one class to access and build the tree, but then the instructions also say not to use class objects. I'm a little confused here, so say if I had this:
1 2 3 4 5 6 7 8
class Tree{
//stuff here
};
int main()
{
Tree myTree;
}
does that break the rules of not using class objects? Because if it does, I don't understand how I'm supposed to access stuff from the Tree class. Or am I overthinking the no class objects rule?
"Write a class called CharacterTree that handles building and accessing your decision
tree. The only requirement of this class is that is uses some sort of linear or dynamic
array to store the tree itself. DO NOT USE STRUCTS OR CLASS OBJECTS."
And then suggestions for how to start include:
1 2
void CharacterTree::insert( string s, int index){}
string CharacterTree:retrieve( int index ){}
so if I need to use those in main(), I really need a Tree object, right? Like this: myTree.retrieve(index);
#include <iostream>
#include <cstdlib>
#include <string>
usingnamespace std;
class CharacterTree
{
public:
staticvoid insert(string s, int index);
static string retrieve(int index);
};
void CharacterTree::insert(string s, int index)
{
// your code here
}
string CharacterTree::retrieve(int index)
{
// your code here
return"";
}
int main()
{
// now you can use it like
CharacterTree::insert("A", 1); // or whatever
string data = CharacterTree::retrieve(1);
}
"The only requirement of this class is that is uses some sort of linear or dynamic
array to store the tree itself. DO NOT USE STRUCTS OR CLASS OBJECTS."
I read this as meaning that inside your class object, for storing the actual tree data, you are not to use any more classes. Just an array.