#include #include using namespace std; class dog { private: double weight; public: dog() { weight = 0; } //a setter method void setWeight(double newWeight) { if (newWeight < 0) weight = 0; else weight = newWeight; } //a getter method double getWeight() { return weight; } void feed(double food) { if( food > 0 && food < 100 ) weight += food; } void bite(dog &victim) { weight += 10; victim.weight -= 10; } }; int main() { dog pippin; dog lex; lex.setWeight(50); //Will no compile if weight is in private //pippin.weight = 300; //pippin.weight = -300; //Can't even view weight if it's in private //cout << pippin.weight << endl; pippin.setWeight(100); pippin.feed(5); cout << "Pippin weighs: " << pippin.getWeight() << endl; //Pippin weighs: 105 lex.bite(pippin); cout << "Lex weighs: " << lex.getWeight() << endl; // cout << "Pippin weighs: " << pippin.getWeight() << endl; // return 0; }