/* Itemtype.cpp */ #include "ItemType2.h" /* ItemType class file */ /*********************************************************************** * ItemType() -- Default constructor used to initialize defaults * * * * Parameters * * void * * Returns * * void * * Precondition * * NONE * * Postcondition * * rank and totalearnings will be zero. * ***********************************************************************/ ItemType::ItemType() { rank = 0; totalearnings = 0; } /*********************************************************************** * ComparedToName() -- compare name to ItemType other.name * * * * Parameters * * ItemType other -- ItemType to compare with * * Returns * * RelationType -- Look @ enum RelationType for values * * Precondition * * name and ItemType other.name should contain something * * Postcondition * * returns enum RelationType LESS GREATER or EQUAL. * ***********************************************************************/ RelationType ItemType::ComparedToName(ItemType other) { if (name < other.name) return LESS; else if (name == other.name) return EQUAL; else return GREATER; } /*********************************************************************** * ComparedToCompany() -- compare company to ItemType other.company * * * * Parameters * * ItemType other -- ItemType to compare with * * Returns * * RelationType -- Look @ enum RelationType for values * * Precondition * * company and ItemType other.company should contain something * * Postcondition * * returns enum RelationType LESS GREATER or EQUAL. * ***********************************************************************/ RelationType ItemType::ComparedToCompany(ItemType other) { if (company < other.company) return LESS; else if (company == other.company) return EQUAL; else return GREATER; } /*********************************************************************** * ComparedToRank() -- compare rank to ItemType other.rank * * * * Parameters * * ItemType other -- ItemType to compare with * * Returns * * RelationType -- Look @ enum RelationType for values * * Precondition * * rank and ItemType other.rank should contain something * * Postcondition * * returns enum RelationType LESS GREATER or EQUAL. * ***********************************************************************/ RelationType ItemType::ComparedToRank(ItemType other) { if (rank < other.rank) return LESS; else if (rank == other.rank) return EQUAL; else return GREATER; } /*********************************************************************** * ChangeCompanyName() -- copy NewCompany.company to company * * * * Parameters * * ItemType NewCompany -- ItemType copy company from * * Returns * * void * * Precondition * * NewCompany.company contains something * * Postcondition * * company contains NewCompany.company * ***********************************************************************/ void ItemType::ChangeCompanyName(ItemType NewCompany) { company = NewCompany.company; } /*********************************************************************** * GetName() -- get name and return it * * * * Parameters * * void * * Returns * * StrType -- Return name * * Precondition * * NONE * * Postcondition * * Return name * ***********************************************************************/ StrType ItemType::GetName() const { return(name); } /*********************************************************************** * GetCompany() -- get company and return it * * * * Parameters * * void * * Returns * * StrType -- Return company * * Precondition * * NONE * * Postcondition * * Return company * ***********************************************************************/ StrType ItemType::GetCompany() const { return(company); } /*********************************************************************** * GetRank() -- get rank and return it * * * * Parameters * * void * * Returns * * StrType -- Return rank * * Precondition * * NONE * * Postcondition * * Return rank * ***********************************************************************/ int ItemType::GetRank() const { return(rank); } /*********************************************************************** * GetEarnings() -- get totalearnings and return it * * * * Parameters * * void * * Returns * * StrType -- Return totalearnings * * Precondition * * NONE * * Postcondition * * Return totalearnings * ***********************************************************************/ double ItemType::GetEarnings() const { return(totalearnings); } /*********************************************************************** * SetCompany() -- copy newStr to company * * * * Parameters * * StrType newStr -- StrType to copy from * * Returns * * void * * Precondition * * newStr contains a string to copy * * Postcondition * * company will contain the old value of newStr * ***********************************************************************/ void ItemType::SetCompany(StrType newStr) { company = newStr; } /*********************************************************************** * SetName() -- copy newStr to name * * * * Parameters * * StrType newStr -- StrType to copy from * * Returns * * void * * Precondition * * newStr contains a string to copy * * Postcondition * * name will contain the old value of newStr * ***********************************************************************/ void ItemType::SetName(StrType newStr) { name = newStr; } /*********************************************************************** * SetRank() -- copy newStr to rank * * * * Parameters * * StrType newStr -- StrType to copy from * * Returns * * void * * Precondition * * newRank has the new number and it is in bounds * * Postcondition * * rank will contain the old value of newStr * ***********************************************************************/ void ItemType::SetRank(int newRank) { /* can't go any higher then max and no lower then zero */ if(newRank >= 0 && newRank <= (MAX_ITEMS - 1)) { rank = newRank; } } /*********************************************************************** * SetEarnings() -- copy newTotalearnings to totalearnings * * * * Parameters * * double newTotalearnings -- double to copy from * * Returns * * void * * Precondition * * newTotalearnings contains a number to copy * * Postcondition * * totalearnings will contain the old value of newTotalearnings * ***********************************************************************/ void ItemType::SetEarnings(double newTotalearnings) { totalearnings = newTotalearnings; } /*********************************************************************** * PrintEmployee() -- print employee name to screen * * * * Parameters * * void * * Returns * * void * * Precondition * * StrType name contains a value * * Postcondition * * output printed to screen * ***********************************************************************/ void ItemType::PrintEmployee() { name.PrintToScreen(true); } /*********************************************************************** * PrintEmployeetoFile() -- print employee name to fileName * * * * Parameters * * ofstream fileName -- File to print to * * Returns * * void * * Precondition * * fileName exists and StrType name contains a value * * Postcondition * * fileName contins output * ***********************************************************************/ void ItemType::PrintEmployeetoFile(ofstream &fileName) { name.PrintToFile(true, fileName); } /*********************************************************************** * IncreaseRank() -- IncreaseRank by one * * * * Parameters * * void * * Returns * * void * * Precondition * * just make sure you have the right employee and company * * Postcondition * * rank++ * ***********************************************************************/ void ItemType::IncreaseRank() { rank++; } /*********************************************************************** * DecreaseRank() -- DecreaseRank by one * * * * Parameters * * void * * Returns * * void * * Precondition * * just make sure you have the right employee and company * * Postcondition * * rank-- * ***********************************************************************/ void ItemType::DecreaseRank() { rank--; } /*********************************************************************** * PayEmployee() -- Pay either an employee their wages or an unemployed* * person $50.00 * * * * Parameters * * void * * Returns * * void * * Precondition * * just make sure you have the right employee and company * * Postcondition * * totalearnings will increase * ***********************************************************************/ void ItemType::PayEmployee() { if(IsUnemployed()) { totalearnings += 50; } else { totalearnings += (rank * 1000); } } /*********************************************************************** * IsUnemployed() -- If employee is unemployed return true else false * * * * Parameters * * void * * Returns * * bool -- True of unemployed false if employed * * Precondition * * just make sure you have the right person * * Postcondition * * return True of unemployed false if employed * ***********************************************************************/ bool ItemType::IsUnemployed() { /* if the rank is zero they are unemployed */ if(rank == 0) { return(true); } else { return(false); } }