Organism.cpp 1.31 KB
Newer Older
Imanol Pérez's avatar
Imanol Pérez committed
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
#include <iostream>
#include "Organism.hpp"
#include <algorithm>

//////////////////////////////////////////////////////
//                                                  //
//           Class for a single organism            //
//                                                  //
//                  Imanol Perez                    //
//                  January 201                    //
//                                                  //
//////////////////////////////////////////////////////

Organism::Organism() {

}

Organism::Organism(int i, int j)
{
  /*

  Constructor

  */

  //Updates moving averages, which must be greater or equal to 0.
  MA1=std::max(i, 0);
  MA2=std::max(j, 0);
  returns=0.0;
}

Organism::~Organism() { }

void Organism::DisposeObject() {
	delete this;
}



bool Organism::isNull(void) {
  /*

  Checks if the organism is null.
  An organism is considered null if both moving
  averages are zero.

  */

  return MA1==0 && MA2==0;
}



std::ostream& operator<<(std::ostream& output, Organism& org) {
  /*

  Allows to output an object of class Organism.

  */
	
  if (org.returns!=0.0) output<<"Returns: "<<org.returns<<"\n";
  output<<"First Moving Average: "<<org.MA1<<"\nSecond Moving Average: "<<org.MA2<<"\n";

  return output;
}