Kyle's Doxygen Test
This is just a test of Doxygen
Loading...
Searching...
No Matches
dog.cpp
Go to the documentation of this file.
1#include "dog.hpp"
2#include "utility.hpp"
3#include <stdio.h>
4
5Dog::Dog(const char* _name) : name(_name) {
6 energy = MAX_ENERGY / 2;
7 printf("Created %s the dog.\n", name);
8}
9
10void Dog::bark(void) {
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}
19
20void Dog::run(int minutes) {
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}
36
37void Dog::sleep(int minutes) {
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}
49
50bool Dog::checkEnergy(int energyToExpend) {
51 if (energy > energyToExpend) {
52 return true;
53 }
54 return false;
55}
bool checkEnergy(int energyToExpend)
Checks the dog's energy.
Definition dog.cpp:50
void bark(void)
Causes the dog to bark.
Definition dog.cpp:10
void run(int minutes)
Causes the dog to run.
Definition dog.cpp:20
int energy
The dog's available energy.
Definition dog.hpp:89
void sleep(int minutes)
Causes the dog to sleep.
Definition dog.cpp:37
Dog(const char *_name)
Creates a new Dog.
Definition dog.cpp:5
const char * name
The dog's name.
Definition dog.hpp:79
#define MAX_ENERGY
Definition dog.hpp:4
int multiply(int x, int y)
Multiplies two numbers.
Definition utility.cpp:7