View Single Post
  #2 (permalink)  
Old January 1st, 2006, 02:34 AM
vector vector is offline
Authorized User
 
Join Date: Nov 2005
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default

See the change
#include <iostream>

using namespace std;

class cApple
{
protected:
    int iWormCount;
    float fTotalLengthOfWorms;
public:
    cApple()
    {
        iWormCount = 0;
        fTotalLengthOfWorms = 0;
    }

    cApple(int iWC, float fTLoW)
    {
        iWormCount = iWC;
        fTotalLengthOfWorms = fTLoW;
    }

    cApple operator ++ ()
    {
        return cApple(++iWormCount, ++fTotalLengthOfWorms);
    }

    void put()
    {
        cout << "Number of worms: " << iWormCount << endl;
        cout << "Total length of worms: " << fTotalLengthOfWorms << endl;
    }
};

class cBigApple:public cApple
{
private:
    float fWeightInKilos;
public:
    cBigApple() : cApple()
    {
        fWeightInKilos = 0;
    }

    cBigApple(int iWC, float fTLoW, float fWiK) : cApple(iWC, fTLoW)
    {
        fWeightInKilos = fWiK;
    }

    cBigApple operator -- ()
    {
        return cBigApple(--iWormCount, --fTotalLengthOfWorms, 0.0);
    }
};

class cBigRedApple:public cBigApple
{

public:
    cBigRedApple() : cBigApple()
    {
    }

    cBigRedApple(int iWC, float fTLoW, float fWiK) : cBigApple(iWC, fTLoW, fWiK)
    {
    }

    cBigRedApple operator -- ()
    {
        return cBigRedApple(iWormCount--, fTotalLengthOfWorms--, 0.0);
    }
};

int main()
{
    cApple oMyApple;
    ++oMyApple;
    cout << "oMyApple:" << endl;
    oMyApple.put();

    cBigApple oMyBigApple;
    ++oMyBigApple;
    ++oMyBigApple;
    ++oMyBigApple;
    cout << "\noMyBigApple:" << endl;
    oMyBigApple.put();

    cBigRedApple oMyBigRedApple;
    ++oMyBigRedApple;
    ++oMyBigRedApple;
    ++oMyBigRedApple;
    ++oMyBigRedApple;
    --oMyBigRedApple;
    oMyBigRedApple--;
    cout << "\noMyBigRedApple:" << endl;
    oMyBigRedApple.put();


    return 0;
}

Reply With Quote