Skip to content

Instantly share code, notes, and snippets.

@dishbreak
Last active August 29, 2015 13:56

Revisions

  1. dishbreak revised this gist Mar 2, 2014. 1 changed file with 8 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions usage.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    Television * tv = new Television();

    //conditional is true if call to pressPowerButton() is false.
    if ( !( tv->pressPowerButton() ) ) {
    //alert! We have an issue
    }

    ...
  2. dishbreak revised this gist Mar 2, 2014. 4 changed files with 92 additions and 92 deletions.
    24 changes: 12 additions & 12 deletions television-buggy.cpp
    Original file line number Diff line number Diff line change
    @@ -1,13 +1,13 @@
    void Television::pressPowerButton()
    {
    tvIsOn = !tvIsOn;
    void Television::pressPowerButton()
    {
    tvIsOn = !tvIsOn;

    if (tvIsOn == true)
    {
    turnOn();
    }
    else
    {
    turnOff();
    }
    }
    if (tvIsOn == true)
    {
    turnOn();
    }
    else
    {
    turnOff();
    }
    }
    20 changes: 10 additions & 10 deletions television-buggy.h
    Original file line number Diff line number Diff line change
    @@ -1,14 +1,14 @@
    class Television
    {
    public:
    Television();
    ~Television();
    {
    public:
    Television();
    ~Television();

    void pressPowerButton();
    void pressPowerButton();

    private:
    bool tvIsOn; //state variable
    private:
    bool tvIsOn; //state variable

    void turnOn();
    void turnOff();
    };
    void turnOn();
    void turnOff();
    };
    120 changes: 60 additions & 60 deletions television.cpp
    Original file line number Diff line number Diff line change
    @@ -1,65 +1,65 @@
    Television::Television()
    {
    //on creation, the television is off.
    tvIsOn = false;
    }
    {
    //on creation, the television is off.
    tvIsOn = false;
    }

    Television::~Television()
    {
    }
    Television::~Television()
    {

    }

    bool Television::pressPowerButton()
    {
    //if the current state is on, try to turn off
    if (tvIsOn == true)
    {
    tvIsOn = turnOff();
    }
    //otherwise, the current state is off, so try to turn on
    else
    {
    tvIsOn = turnOn();
    }
    //report the current state back to the user
    return tvIsOn;
    }
    bool Television::pressPowerButton()
    {
    //if the current state is on, try to turn off
    if (tvIsOn == true)
    {
    tvIsOn = turnOff();
    }
    //otherwise, the current state is off, so try to turn on
    else
    {
    tvIsOn = turnOn();
    }
    //report the current state back to the user
    return tvIsOn;
    }

    bool Television::turnOn()
    {
    //set a variable for success
    bool success = false;
    //do stuff to turn on, set success variable accordingly.
    //if we succeeded, return the new state of "on".
    if (success)
    {
    return true;
    }
    //otherwise, keep the state as "off".
    else
    {
    return false;
    }
    }
    bool Television::turnOn()
    {
    //set a variable for success
    bool success = false;

    //do stuff to turn on, set success variable accordingly.
    //if we succeeded, return the new state of "on".
    if (success)
    {
    return true;
    }
    //otherwise, keep the state as "off".
    else
    {
    return false;
    }
    }

    bool Television::turnOff()
    {
    //set a variable for success
    bool success = false;
    //do stuff to turn off, set success variable
    //if we succeeded, return the new state of "off".
    if (success)
    {
    return false;
    }
    //otherwise, keep the state as "on".
    else
    {
    return true;
    }
    }
    bool Television::turnOff()
    {
    //set a variable for success
    bool success = false;

    //do stuff to turn off, set success variable
    //if we succeeded, return the new state of "off".
    if (success)
    {
    return false;
    }
    //otherwise, keep the state as "on".
    else
    {
    return true;
    }
    }
    20 changes: 10 additions & 10 deletions television.h
    Original file line number Diff line number Diff line change
    @@ -1,14 +1,14 @@
    class Television
    {
    public:
    Television();
    ~Television();
    {
    public:
    Television();
    ~Television();

    bool pressPowerButton();
    bool pressPowerButton();

    private:
    bool tvIsOn; //state variable
    private:
    bool tvIsOn; //state variable

    bool turnOn();
    bool turnOff();
    };
    bool turnOn();
    bool turnOff();
    };
  3. dishbreak created this gist Mar 2, 2014.
    13 changes: 13 additions & 0 deletions television-buggy.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    void Television::pressPowerButton()
    {
    tvIsOn = !tvIsOn;

    if (tvIsOn == true)
    {
    turnOn();
    }
    else
    {
    turnOff();
    }
    }
    14 changes: 14 additions & 0 deletions television-buggy.h
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    class Television
    {
    public:
    Television();
    ~Television();

    void pressPowerButton();

    private:
    bool tvIsOn; //state variable

    void turnOn();
    void turnOff();
    };
    65 changes: 65 additions & 0 deletions television.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,65 @@
    Television::Television()
    {
    //on creation, the television is off.
    tvIsOn = false;
    }

    Television::~Television()
    {

    }

    bool Television::pressPowerButton()
    {
    //if the current state is on, try to turn off
    if (tvIsOn == true)
    {
    tvIsOn = turnOff();
    }
    //otherwise, the current state is off, so try to turn on
    else
    {
    tvIsOn = turnOn();
    }

    //report the current state back to the user
    return tvIsOn;
    }

    bool Television::turnOn()
    {
    //set a variable for success
    bool success = false;

    //do stuff to turn on, set success variable accordingly.

    //if we succeeded, return the new state of "on".
    if (success)
    {
    return true;
    }
    //otherwise, keep the state as "off".
    else
    {
    return false;
    }
    }

    bool Television::turnOff()
    {
    //set a variable for success
    bool success = false;

    //do stuff to turn off, set success variable

    //if we succeeded, return the new state of "off".
    if (success)
    {
    return false;
    }
    //otherwise, keep the state as "on".
    else
    {
    return true;
    }
    }
    14 changes: 14 additions & 0 deletions television.h
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    class Television
    {
    public:
    Television();
    ~Television();

    bool pressPowerButton();

    private:
    bool tvIsOn; //state variable

    bool turnOn();
    bool turnOff();
    };