-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnimal.cpp
More file actions
50 lines (42 loc) · 1.8 KB
/
Animal.cpp
File metadata and controls
50 lines (42 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <iostream>
#include <string>
#include "Animal.hpp" // when making inheritance, make sure to include the HPP files in order for the cpp files to understand where its coming from
using namespace std;
Animal::Animal() // this is the BASE CLASS == the first class that the derived classes inherit from and get the source of first information from
{
name_= "";
domestic_=false;
predator_=false;
// this is a defaulted parameter that sets everything to the value that would be automatically initialized if the user doesnt put any values in main or compiler (cin) == if you just put Animal Dog ("Dog"), it would still compile because it has defaulted values that set both parameters to false and keeps it running. Neat.
} //constuctor
Animal::Animal(std::string name, bool domestic , bool predator) //default constructor (initializes the variables)
{
name_= name;
domestic_=domestic;
predator_=predator;
// IMPORTANT NOTE: this is where the variables from the parametes that were initalized with their type are matched perfectly with their private variables
}
std::string Animal::getName() const //gets the name and returns it (NOTE: std is used when namespace isnt being used :) )
{
return name_;
}
bool Animal::isDomestic() const //the private variable domestic is returned in the is function
{
return domestic_;
}
bool Animal::isPredator() const //the private variable predator is returned in the is function
{
return predator_;
}
void Animal::setName(std::string name) //when setting the name, set it with its matching private variable
{
name_=name;
}
void Animal::setDomestic() // just sets the variable in the private section to be true
{
domestic_=true;
}
void Animal::setPredator() //same
{
predator_=true;
}