////////////////////////////////////////////////////////////// // DataTree.C // // CMSC341 Fall 2001 - Project 3 // // Kyu Bae xxx-xx-5868 Section 201 // // kyu_bae@yahoo.com / kbae1@umbc.edu // // Created: 16 Oct 2001 // // Current: 22 Oct 2001 // ////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////// // DataTree class: // data element for BinarySearchTree class which stores string // and integer data elements. The string data member uses // string class to store its string of characters. // There are big fours. and operator < to compare the string // data member. // Author:Kyu Bae // Version:18 Oct 2001 /////////////////////////////////////////////////////////////// #include "DataTree.H" ////////////////////////////////////////////////////////////// // DataTree(): // default constructor. // initialize data members, string word and int count to // zero. ////////////////////////////////////////////////////////////// DataTree::DataTree() { _word = 0; _count = 0; } ////////////////////////////////////////////////////////////// // DataTree(): // constructor with two arguments which initialize data members // to arguments passed in. // Param w: string object to _word // Param c: int object to _count ////////////////////////////////////////////////////////////// DataTree::DataTree(string w, int c) :_word(w), _count(c) { } ////////////////////////////////////////////////////////////// // Destructor: // Default destructor ////////////////////////////////////////////////////////////// DataTree::~DataTree() { } ////////////////////////////////////////////////////////////// // Copy construcotr: // Copy another DataTree object to this. // Param dt: DataTree object assign to this object ////////////////////////////////////////////////////////////// DataTree::DataTree(const DataTree & dt) { operator= (dt); } ////////////////////////////////////////////////////////////// // Assignment operator=: // Assign rhs to this DataTree. It initialize its data // members to this data members // Param rhs: DataTree object to this data members // Return: const DataTree reference object ////////////////////////////////////////////////////////////// const DataTree& DataTree::operator= (const DataTree & rhs) { if (this != &rhs) { _word = rhs._word; _count = rhs._count; } return *this; } ////////////////////////////////////////////////////////////// // getWord(): // accessor which returns the _word // Return: string _word data member. ////////////////////////////////////////////////////////////// string DataTree::getWord(void) const { return _word; } ////////////////////////////////////////////////////////////// // getCount(): // accessor which return the _count // return: int _count data member ////////////////////////////////////////////////////////////// int DataTree::getCount(void) const { return _count; } ////////////////////////////////////////////////////////////// // setCount(): // mutator which set _count data member to oneMore int object // Param oneMore: int object, oneMore to _count ////////////////////////////////////////////////////////////// void DataTree::setCount(int oneMore) { _count = oneMore; } ////////////////////////////////////////////////////////////// // addCount(): // mutator which increment _count by one. ////////////////////////////////////////////////////////////// void DataTree::addCount(void) { _count=_count+1; } ////////////////////////////////////////////////////////////// // operator!=(): // Not equal operator checking if DataTree obj's data members // are equal or not. // Param obj: DataTree object // return: boolean ///////////////////////////////////////////////////////////// bool DataTree::operator!= ( const DataTree & obj)const { if (_word == obj._word) return true; return false; } ////////////////////////////////////////////////////////////// // operator< (): // less than operator checking obj's data member _word is // less than this data member. // Param rhs: const DataTree obj // Return : boolean //////////////////////////////////////////////////////////// bool DataTree::operator< (const DataTree & rhs)const { if (_word < rhs._word) return true; return false; } ////////////////////////////////////////////////////////////// // print(): // print its data members , _word and _count // Param out: ostream object ////////////////////////////////////////////////////////////// void DataTree::print( ostream & out) const { out <<"[ " << _word << " , " << _count << " ]" << endl; } ////////////////////////////////////////////////////////////// // operator<< (): // Output operator calls print() to print the object of // DataTree data members // Param out: ostream object is passed in // Param dt: DataTree object is passed to print() // Return: ostream reference object of DataTree //////////////////////////////////////////////////////////// ostream & operator<< (ostream & out, const DataTree & dt) { dt.print(out); return out; }