Lab 1

Concerns and Grading Format


Common problems:

  1. Operators not robust enough (-5 pt, minor detail missed)

    You guys assume that if you define the operator > you can do the following:

    operator < is operator> false

    Though that is true it is not the full picture. You are forgetting this fact:

    operator < is true also when operator == is false, and will be false when == is false

    So here is what I see a lot in your labs:

    WRONG:
    bool operator>(const Fraction & left, const Fraction & right)
    {
    return left.greaterThanHelper(right);
    }
    bool operator<(const Fraction & left, const Fraction & right)
    {
    return !(left > right);
    }

    That won't cut it. What will is the following:

    CORRECT:
    bool operator>(const Fraction & left, const Fraction & right)
    {
    return left.greaterThanHelper(right);
    }
    bool operator<(const Fraction & left, const Fraction & right)
    {
    return !(left >= right);
    }

    The key is that the == has to be taken into account.

  2. const problems (-20 pt, not compiling)

    You guys just don't know how to use this properly yet. There will be more supplemental material later. When there is a mismatch of const parameter and const member function the compiler will not compile.

  3. Helper method placement (-20 pt, missed the whole point of the lab)

    Ok, this is key to the lab. I'm glad to say that only a few, maybe less than a dozen, of you got this part wrong. Don't worry if you got it wrong. But here is how it should be done:

    Prototype:

    class Fraction
    {
    public:
    .....

    Fraction sum(Fraction& right);
    Fraction diff(Fraction& right);

    private:
    ......
    };


    Fraction operator+(Fraction& left, Fraction& right);
    Fraction operator-(Fraction& left, Fraction& right);

    Definition:

    Fraction Fraction::sum(Fraction& right)
    {
    ........
    return ....;
    }

    Fraction operator+(Fraction& left, Fraction& right)
    {
    return left.sum(right);
    }

    As you can see, the helper function is a member of Fraction. A helper function is meant to be in a class hiding the information of the class.