-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPetriDish.h
109 lines (96 loc) · 2.39 KB
/
PetriDish.h
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#ifndef PETRIDISH_H_
#define PETRIDISH_H_
#include <iostream>
#include "Bacteria.h"
#include <vector>
/**
* PetriDish
* Class which has a container of Bacteria pointers
* It also has data about the food left in the Petridish
*
* The class has the following methods:
* clean, addFood, addBacteria, print and updatePopulation.
* These methods determine the amount of food in the PetriDish
* and the number of bacterias in it.
*
* The class can print a status of the bacterias population
* and the amount of food.
*/
class PetriDish {
public:
/**
* Class Constructor.
* New PetriDishes are initialized empty of any food or bacteria.
*
*/
PetriDish();
/**
* Copy Constructor
* @param original const Petridish & - the original petriDish to be copied
*
*/
PetriDish(const PetriDish &original);
/**
* Class Destructor
*
*/
~PetriDish()
{
clean();
}
/**
* Assignment Operator
*
*/
PetriDish& operator=(const PetriDish &);
/** Clean
* Removes all food and Bacteria from PetriDish
*/
void clean();
/** AddFood
* Adds addedAmount (whole units) of food
* to the PetriDish
*
* @param addedAmount int the amount of food units added to the PetriDish
*
*/
void addFood(int addedAmount) {
_foodLeft += addedAmount;
}
/** AddBacteria
* Adds a new Bacteria to the PetriDish
*
* @param newBacteriaPtr Bacteria* a pointer to new bacteria of type bacteriaType
*
*/
void addBacteria(Bacteria* newBacteriaPtr) {
_bacterias.push_back(newBacteriaPtr);
}
/** Print
* Prints the Bacteria Colony and the amount of food
*/
void print() const;
/** UpdatePopulation
* Update the population timeUnits times.
* For each update:
* - For each Bacteria (in the order the were added):
* 1. The Bacteria can choose to eat.
* 2. The Bacteria can choose to duplicate itself.
* - Then, all dead Bacteria are removed.
* - Finally, adds the cloned bacteria to the dish.
*
* @param timeUnits int the number of units the time moves forward
*
* Takes ownership!
*/
void updatePopulation(int timeUnits);
private:
std::vector<Bacteria*> _bacterias; /**contains all the bacterias pointers which
are in the PetriDish */
int _foodLeft; // the amount of food remained in the PetriDish
/** RemoveDeadBacteria
* Helper function to delete remove dead Bacteria
*/
void removeDeadBacteria();
};
#endif