////////////////////////////////////////////////////////////// // DataHeap.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 // ////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////// // DataHeap class: // data element for BinaryHeap 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 "DataHeap.H" /////////////////////////////////////////////////////////////// // DataHeap(): // default constructor. // initialize data members, string word and int count to // zero. /////////////////////////////////////////////////////////////// DataHeap::DataHeap() { _count = 0; _word = 0; } ////////////////////////////////////////////////////////////// // DataHeap(): // constructor with two arguments which initialize data members // to arguments passed in. // Param w: string object to _word // Param c: int object to _count ////////////////////////////////////////////////////////////// DataHeap::DataHeap(int count, string word) { _count = count; _word = word; } /////////////////////////////////////////////////////////////// // Destructor: // Default destructor /////////////////////////////////////////////////////////////// DataHeap::~DataHeap() { } /////////////////////////////////////////////////////////////// // Copy construcotr: // Copy another DataHeap object to this. // Param dt: DataHeap object assign to this object /////////////////////////////////////////////////////////////// DataHeap::DataHeap(const DataHeap & dh) { operator= (dh); } /////////////////////////////////////////////////////////////// // Assignment operator=: // Assign rhs to this DataHeape. It initialize its data // members to this data members // Param rhs: DataHeap object to this data members // Return: const DataHeap reference object /////////////////////////////////////////////////////////////// const DataHeap & DataHeap::operator= (const DataHeap & rhs) { if (this != &rhs) { _word = rhs._word; _count = rhs._count; } return *this; } /////////////////////////////////////////////////////////////// // getWord(): // accessor which returns the _word // Return: string _word data member. /////////////////////////////////////////////////////////////// string DataHeap::getWord(void) const { return _word; } /////////////////////////////////////////////////////////////// // getCount(): // accessor which return the _count // return: int _count data member /////////////////////////////////////////////////////////////// int DataHeap::getCount(void) const { return _count; } /////////////////////////////////////////////////////////////// // operator!=(): // Not equal operator checking if DataHeap obj's data members // are equal or not. // Param obj: DataHeap object // return: boolean /////////////////////////////////////////////////////////////// bool DataHeap::operator!= ( const DataHeap & obj) const { if (_count == obj._count) return false; return true; } /////////////////////////////////////////////////////////////// // operator< (): // less than operator checking obj's data member _word is // less than this data member. // Param rhs: const DataHeap obj // Return : boolean /////////////////////////////////////////////////////////////// bool DataHeap::operator< (const DataHeap & rhs) const { if (_count < rhs._count) return true; return false; } /////////////////////////////////////////////////////////////// // operator==(): // equal operator checking if DataHeap obj's data members // are equal or not. // Param obj: DataHeap object // return: boolean /////////////////////////////////////////////////////////////// bool DataHeap::operator== ( const DataHeap & rhs) const { if (_count == rhs._count) return true; return false; } /////////////////////////////////////////////////////////////// // print(): // print its data members , _word and _count // Param out: ostream object /////////////////////////////////////////////////////////////// void DataHeap::print (ostream & out) const { out << "[ " << _word << ", " << _count << " ]" << endl; } /////////////////////////////////////////////////////////////// // operator<< (): // Output operator calls print() to print the object of // DataHeap data members // Param out: ostream object is passed in // Param dt: DataHeap object is passed to print() // Return: ostream reference object of DataHeap /////////////////////////////////////////////////////////////// ostream & operator<< (ostream & out, const DataHeap & dh) { dh.print(out); return out; }