-
Notifications
You must be signed in to change notification settings - Fork 0
/
ActiveBacteria.cpp
66 lines (55 loc) · 1.41 KB
/
ActiveBacteria.cpp
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
* ActiveBacteia.cpp
*
* Created on: 30 áãöî× 2018
* Author: Yamit Gvinter
*
*/
#include <sstream>
#include <iostream>
#include <string>
#include <vector>
#include "Bacteria.h"
#include "ActiveBacteria.h"
using std::endl;
using std::cout;
using std::vector;
using std::string;
typedef enum { OUT_ID=0, OUT_AGE, OUT_FOOD } OutputEnum;
const std::string OUTPUT_FIELDS[]={ "Bacteria ID: ", "Age: ", "Food left: " };
const string ActiveBacteria::name= "Active Bact.";
//destructor
ActiveBacteria:: ~ActiveBacteria(){}
/* * clone
* clones the Active Bacteria. checks if the bacteria is ready to clone and is
* not dead, then multiply the age and resets the current consumed food.
* then makes a new "son" bacteria with the same parameters as the father, else,
* returns NULL.
*
* @ return pointer to the new bacteria (known as activeSon)
*/
Bacteria* ActiveBacteria:: clone()
{
if (isReadyToClone() && !isDead())
{
_currentAge *= two;
_currentFood = 0;
Bacteria* activeSon = new ActiveBacteria(*this);
return activeSon;
}
else
{
return NULL;
}
}
/* *print
* prints Active Bact., then sends to the print function in Bacteria, which
* prints the bacteria id and current age.
*
* @return the name and prints the id and age of the Active Bacteria as constant
*/
void ActiveBacteria:: print() const
{
cout<< name;
Bacteria::print();
}