Kyle's Doxygen Test
This is just a test of Doxygen
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Private Attributes | List of all members
Dog Class Reference

Represents a dog. More...

#include <dog.hpp>

Public Member Functions

 Dog (const char *_name)
 Creates a new Dog.
 
void bark (void)
 Causes the dog to bark.
 
void run (int minutes)
 Causes the dog to run.
 
void sleep (int minutes)
 Causes the dog to sleep.
 

Protected Member Functions

bool checkEnergy (int energyToExpend)
 Checks the dog's energy.
 

Private Attributes

const char * name
 The dog's name.
 
int energy
 The dog's available energy.
 

Detailed Description

Represents a dog.

This class keeps track of the dog's energy level, and performs actions for the dog based on how much energy it has. Sleeping regains energy for the dog, while barking and running use energy up.

Definition at line 13 of file dog.hpp.

Constructor & Destructor Documentation

◆ Dog()

Dog::Dog ( const char *  _name)

Creates a new Dog.

Creates a new Dog named _name with half of its maximum energy.

Parameters
_nameThe dog's name.

Definition at line 5 of file dog.cpp.

5 : name(_name) {
6 energy = MAX_ENERGY / 2;
7 printf("Created %s the dog.\n", name);
8}
int energy
The dog's available energy.
Definition dog.hpp:89
const char * name
The dog's name.
Definition dog.hpp:79
#define MAX_ENERGY
Definition dog.hpp:4

References energy, MAX_ENERGY, and name.

Member Function Documentation

◆ bark()

void Dog::bark ( void  )

Causes the dog to bark.

Causes the dog to bark if it has enough energy to do so. Barking costs 1 energy to do. If the dog does not have enough energy, then the bark fails.

Definition at line 10 of file dog.cpp.

10 {
11 int energyToExpend = 1;
12 if (checkEnergy(energyToExpend)) {
13 energy -= energyToExpend;
14 printf("%s BARKS!\n", name);
15 } else {
16 fprintf(stderr, "%s is too tired to bark.\n", name);
17 }
18}
bool checkEnergy(int energyToExpend)
Checks the dog's energy.
Definition dog.cpp:50

References checkEnergy(), energy, and name.

Referenced by testDog().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ checkEnergy()

bool Dog::checkEnergy ( int  energyToExpend)
protected

Checks the dog's energy.

Compares an amount of energy with the dog's current available energy. This function can be used to determine if the dog is able to take an action that costs energy.

Parameters
energyToExpendAn amount of energy to check.
Returns
True if the dog has enough energy, and false otherwise.

Definition at line 50 of file dog.cpp.

50 {
51 if (energy > energyToExpend) {
52 return true;
53 }
54 return false;
55}

References energy.

Referenced by bark(), and run().

Here is the caller graph for this function:

◆ run()

void Dog::run ( int  minutes)

Causes the dog to run.

Causes the dog to run for an amount of time if it has enough energy to run for that long. If the dog does not have enough energy, then the run fails. If the dog cannot complete the full run, no running takes place and no energy is expended. Running costs 3 energy per minute.

Parameters
minutesNumber of minutes for the dog to run.

Definition at line 20 of file dog.cpp.

20 {
21 int energyToExpend = multiply(minutes, 3);
22 if (checkEnergy(energyToExpend)) {
23 energy -= energyToExpend;
24 printf("%s runs for %d minute%s.\n",
25 name,
26 minutes,
27 minutes == 1 ? "" : "s");
28 } else {
29 fprintf(stderr,
30 "%s is too tired to run for %d minute%s.\n",
31 name,
32 minutes,
33 minutes == 1 ? "" : "s");
34 }
35}
int multiply(int x, int y)
Multiplies two numbers.
Definition utility.cpp:7

References checkEnergy(), energy, multiply(), and name.

Referenced by testDog().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sleep()

void Dog::sleep ( int  minutes)

Causes the dog to sleep.

Sleeping replenishes the dog's energy. The dog regains an amount of energy equal to twice the number of minutes slept. The dog will always sleep, regardless of how much energy it has remaining.

Parameters
minutesNumber of minutes for the dog to sleep.

Definition at line 37 of file dog.cpp.

37 {
38 int energyToRegain = multiply(minutes, 2);
39 energy += energyToRegain;
40 printf("%s sleeps for %d minute%s.\n",
41 name,
42 minutes,
43 minutes == 1 ? "" : "s");
44 if (energy > MAX_ENERGY) {
46 printf("%s is fully rested.\n", name);
47 }
48}

References energy, MAX_ENERGY, multiply(), and name.

Referenced by testDog().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ energy

int Dog::energy
private

The dog's available energy.

Represents the amount of energy the dog has available. This is set in the constructor and should not be accessed externally. Taking actions that cost the dog energy will cause this value to drop, and sleeping will cause this value to rise.

Definition at line 89 of file dog.hpp.

Referenced by bark(), checkEnergy(), Dog(), run(), and sleep().

◆ name

const char* Dog::name
private

The dog's name.

Represents the dog's name. This is set when the dog is created, and cannot be changed afterwards.

Definition at line 79 of file dog.hpp.

Referenced by bark(), Dog(), run(), and sleep().


The documentation for this class was generated from the following files: