Posted by Computer Consultant on 1999-03-19
At 06:45 PM 3/19/99 +0100, you wrote:
>Ok- here is the grep.
>
>I'm at Uni. and I have a project to do, but this isn't a request for you to
>do my homework. I'm looking to learn, not to copy. My C++ is rubbish, but I
>want to do this over the weekend for Monday night. Please try and sort me
>out!
>
>I'll skim over the details here for what I need to do, if you think you can
>help me or point me in the right direction by all means mail me:
>ceecsa@xxx.xx.xx.xx
>
>Ok- I have a table of attributes, and each row has boolean attributes and a
>kind, like this (for a beer example):
>
>is_it_pale | is_it_creamy | has_a_head | tastes_strong |
>kind_of_beer
>=========================================================
> T | F | T |
>F | lager
> F | T | T |
>T | stout
> T | T | N |
>N | bitter
>..
>and so on.
>
>Basically I have a function that calculates the entropy (the best ordering
>attribute for a good spread in the table) and then I need to make a decision
>tree based on the node I have chosen with the function.
>
>>From this I recurse and use the function to work out which attribute to sort
>by and then create this tree. The problem is I'm rubbish at C++ as I have
>said. My questions:
>
>* I have an array of structs for the table, is this the best choice?
Whatever you want
>* How do I use a binary tree here? I have a struct for a node, but I'm
>getting confused.
typedef struct b_tree_type {
whatevertype x;
struct b_tree_type *Left, *Right;
} BTREE, *BTREEPTR;
basically, you sort thru the tree, you asking how to put shit on the tree?
BTREEPTR Head, Runner;
...
Runner = Head;
of course, before hand make sure head isn't NULL.
and remeber to set Done when u found a position.
If this is what your question was, how to create a btree?
while(!Done)
{
if(x > Runner->x) // Perform some sort of compare here.
{
if(Runner->Left)
Runner = Runner->Left;
else
Allocate Left & Plot x.
}
else
{
if(Runner->Right)
Runner = Runner->Right;
else
Allocate Right & Plot x.
}
}
}
>* How can I accept a return as an input? Like if you are asked for a
>filename but I have a default file that is used if you press <enter>? As I
>can't get cin to do this? Do I need getln or scanf?
in DOS, there's a nice thing called getch();, u can loop that.
or kbhit(); (You would have to loop this until nonzero), if a key is
pressed and it's return, getch(); the buffer and continue, else
use fgets(); or your own input buffer. There are many ways to get input,
you could
hook int 9h and scan all keys comming in or even read directly from
0040:001Ah, 0040:001Ch
(Buffer pointers) at 0040:0080h (The buffer) You can read/write directly to
these
in DOS, you can move the pointer whereever you want and even increase your
Keyboard buffer
size from 16 to whatever =) These are BIOS, but other pmode OSes probably
put them somewhere else. You couldn't get to it anyway unless you achieve
ring0, which you can
do in 95 without a VxD. I assume you're not using a GUI by the structure of
your code
and type of questions you are asking about input.
you can also look into fgets();
>* If I have a char that is like this: char name[4]; how can I avoid
>type incompatibility with chars that are smaller than this? i.e. I had this
>in my code where the filename is. If you press enter then:
>
>char file_name[5];
>if(whatever you do for return)
>{
> file_name = "Jim";
>}
>else
>{
> cout << "Please enter...."
>
>blahh!
>
>I get cannot convert char[3] to char[5].
>
Dude.
char *file_name;
file_name = "Jim"; <== "Jim" is basicaly a constant address.
Either that or
char file_name[5];
strcpy(file_name, "Jim");
>OK-
>
>I think I'll stop there and see how I get on. If anyone does make any sense
>of this, and sends me a clue to any of it, then I thank you very kindly
>indeed!!
>
>Colin.
>
>
>
>
+=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=+
| http://www.nauticom.net/www/secret |
+=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=+
3%
Previous post | Next post | Timeline | Home