All pastes #101753 Raw Edit

Miscellany

public cpp v1 · immutable
#101753 ·published 2006-07-27 04:00 UTC
rendered paste body
# include <string.h># include <stdio.h># include <stdlib.h>class ContactInfo   {  public:     ContactInfo(char *name, char *number);        //constructor     char *getName();             // get function for contactName     char *getNumber();        //get function for contactNumber     void printInfo();   // prints contactName and contactNumber to standard output  private:     char *contactName;     char *contactNumber;     };   //end of class ContactInfo ContactInfo::ContactInfo(char *name, char *number){  contactName = (char *) malloc(100);  contactNumber = (char *) malloc(100);  strcpy(contactName, name);  strcpy(contactNumber,number);}char *ContactInfo::getName(){  return contactName;}char *ContactInfo::getNumber(){  return contactNumber;}class TreeNode {  public:      TreeNode(char * searchArg, ContactInfo *data); //constructor     ContactInfo *getInfo();   // accesses the contact info stored in the data portion this node     TreeNode *getLeftChild();      //just returns leftChild.   Used to traverse the BST     TreeNode *getRightChild();   //just returns rightChild.     void setLeftChild (TreeNode *newChild);   //used to build the binary search tree     void setRightChild(TreeNode *newChild); //ditto  private:       char *searchKey;      //Holds the searchArg specified in the constructor                                        //This is the value used for sorting the BST      ContactInfo *data;   //Stores the contact information for this node as supplied to the                                           // constructor     TreeNode *leftChild;     TreeNode *rightChild;}; //end of class TreeNode TreeNode::TreeNode(char * searchArg, ContactInfo *data){  searchKey = (char *) malloc(100);              strcpy(searchKey, searchArg);  this->data = data;}ContactInfo *TreeNode::getInfo(){  return data;}TreeNode *TreeNode::getLeftChild(){  return leftChild;}TreeNode *TreeNode::getRightChild(){  return rightChild;}void TreeNode::setLeftChild (TreeNode *newChild){  leftChild = newChild;}void TreeNode::setRightChild(TreeNode *newChild){  rightChild = newChild;}     int main(){  ContactInfo c("Josh","123-8588");  ContactInfo d("Katie","555-8944");  ContactInfo e("Dwiju","789-4345");    printf("%s\n",c.getName());  printf("%s\n",c.getNumber());  TreeNode t("J",&c);  TreeNode u("K",&d);  TreeNode v("D",&e);  t.setLeftChild(&u);  t.setRightChild(&v);    ContactInfo *x = t.getInfo();  printf("%s\n",x->getNumber());  printf("%s\n",x->getName());    TreeNode *kid1 = t.getLeftChild();  x = kid1->getInfo();    printf("%s\n",x->getNumber());  printf("%s\n",x->getName());    TreeNode *kid2 = t.getRightChild();  x = kid2->getInfo();  printf("%s\n",x->getNumber());  printf("%s\n",x->getName());      getchar();}