Please send questions to
st10@humboldt.edu .
// Implementation file for class MyNode
//
// by: Sharon M. Tuttle
// last modified: 11-19-03 - now uses initialization
// section in constructors
// AND has overloaded operators
#include <iostream>
#include "MyNode.h"
using namespace std;
//-----
// constructors
//-----
MyNode::MyNode() : quant(0), cost(0), nextPtr(NULL)
{
}
MyNode::MyNode(int newQuant, float newCost)
: quant(newQuant), cost(newCost), nextPtr(NULL)
{
}
//-----
// accessors
//-----
int MyNode::get_quant() const
{
return quant;
}
float MyNode::get_cost() const
{
return cost;
}
MyNode* MyNode::get_nextPtr() const
{
return nextPtr;
}
//-----
// mutators
//-----
void MyNode::set_quant(int newQuant)
{
quant = newQuant;
}
void MyNode::set_cost(float newCost)
{
cost = newCost;
}
void MyNode::set_nextPtr(MyNode *nextNodePtr)
{
nextPtr = nextNodePtr;
}
// overloaded operators
MyNode MyNode::operator +(const MyNode& node2)
{
MyNode tempMyNode;
tempMyNode.quant = quant + node2.quant;
tempMyNode.cost = ((quant * cost) +
(node2.quant * node2.cost))
/ static_cast<double>(quant + node2.quant);
return tempMyNode;
}
bool MyNode::operator ==(const MyNode& node2)
{
return ( (cost == node2.cost) &&
(quant == node2.quant) &&
(nextPtr == node2.nextPtr)
);
}
// other member functions
bool MyNode::equalQuant(MyNode node2) const
{
return (quant == node2.quant);
}