#include<iostream>
using namespace std;
class Dog
{
public:
void Bark();
void Eat(float foodQuantity);
// You will have to define Walk in class
// it will cause the dog to change its
// location
float size, weight, location;
// Add new isHungry variable
bool isHungry;
// Add new walk function
void walk(float distance);
};
int main()
{
Dog fido;
fido.weight=40.5;
fido.size=10;
fido.Eat(20);
cout << fido.weight << " "
<< fido.size << endl;
// Declare dog rex and give him food to eat
Dog rex;
rex.weight=20;
rex.size=4;
rex.Eat(4);
cout << rex.weight << " " << rex.size << endl;
// Made fido not-hungry
fido.isHungry=false;
// Have fido bark
fido.Bark();
// Have fido take a walk, then bark,
// then eat, then bark
fido.location=12;
fido.walk(20);
fido.Bark();
fido.Eat(20);
fido.Bark();
cout << fido.location << endl;
return 0;
}
// Modified Bark so more woofs if dog is hungry
void Dog::Bark()
{
if(isHungry)
cout << "Woof woof woof!\n";
else
cout << "Woof woof!\n";
}
// Define new walk function
void Dog::walk(float distance)
{
location += distance; // Update location based on distance
if(distance>=10) // If dog walks >= 10, make him hungry
isHungry=true;
}
// Modify eat to make dog not hungry if it eats >= 10
void Dog::Eat(float foodQuantity)
{
weight+=foodQuantity;
size+=foodQuantity;
if(foodQuantity>=10)
isHungry=false;
}