-
Notifications
You must be signed in to change notification settings - Fork 0
/
Animal.cpp
106 lines (87 loc) · 3.68 KB
/
Animal.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
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
///////////////////////////////////////////////////////////////////////////////
/// University of Hawaii, College of Engineering
/// @brief _ee205_lab_08d_animal_farm_1_to_clion - EE 205 - Spr 2022
///
/// @file Animal.cpp
/// @version 1.0
///
/// @author Aksel Sloan <@aksel@hawaii.edu>
/// @date 21_Apr_2022
///////////////////////////////////////////////////////////////////////////////
#include <iostream>
#include <cassert>
#include "Animal.h"
#include "Weight.h"
const std::string Animal::KINGDOM_NAME = "Animalia";
///constructors
///minimal
Animal::Animal(const t_weight newMaxWeight, std::string const newClassification, const std::string newSpecies) { //use unit / max constructor
//@todo validation
weightClass.setMaxWeight( newMaxWeight ); //set things, don't use a constructor
setClassification( newClassification );
species = newSpecies;
}
Animal::Animal(const Gender newGender, const t_weight newWeight, const t_weight newMaxWeight,
const std::string newClassification, const std::string newSpecies)
: Animal( newMaxWeight ,newClassification, newSpecies ){
weightClass.setWeight( newWeight, Weight::POUND );
gender = newGender;
}
///getters
std::string Animal::getKingdom() const noexcept {
return KINGDOM_NAME;
}
std::string Animal::getClassification() const noexcept {
return classification;
}
std::string Animal::getSpecies() const noexcept {
return species;
}
Gender Animal::getGender() const noexcept { //@todo, get this working (more specifically the put to operator)
return gender;
}
///setters
void Animal::setClassification(std::string newClassification) {
assert( !newClassification.empty());
classification = newClassification;
}
///dump
void Animal::dump() const {
cout << setw(80) << setfill( '=' ) << "" << endl ;
cout << setfill( ' ' ) ;
cout << left ;
cout << boolalpha ;
FORMAT_LINE_FOR_DUMP( "Node", "this" ) << this << endl;
FORMAT_LINE_FOR_DUMP( "Node", "next" ) << this->next << endl;
FORMAT_LINE_FOR_DUMP( "Animal", "next" ) << this << endl;
FORMAT_LINE_FOR_DUMP( "Animal", "kingdom" ) << getKingdom() << endl;
FORMAT_LINE_FOR_DUMP( "Animal", "classification" ) << getClassification() << endl;
FORMAT_LINE_FOR_DUMP( "Animal", "species" ) << getSpecies() << endl;
FORMAT_LINE_FOR_DUMP( "Animal", "gender" ) << getGender() << endl;
std::cout << "Animal weight " << weightClass.getWeight() << " out of " << weightClass.getMaxWeight() << " " << weightClass.getUnits() << std::endl;
}
bool Animal::validate() const {
assert( !classification.empty() );
assert( !species.empty() );
if ( weightClass.bIsKnown ){
assert( weightClass.getWeight() > 0 );
if ( weightClass.bHasMax ){
assert( weightClass.getMaxWeight() > weightClass.getWeight() );
}
}
if ( weightClass.bHasMax ){
assert( weightClass.getMaxWeight() > 0 );
}
return true;
}
///put to operator
//how should I deal with this? seems like only one definition of put to operator per cpp
/// Output Gender as a formatted string
///
/// @param lhs_stream The output stream to write to (usually `cout`). `
/// `lhs` stands for Left Hand Side and means the left side
/// of the `<<` operator.
/// @param rhs_Gender The Gender to output.
/// `rhs` stands for Right Hand Side and means the right
/// side of the `<<` operator.
/// @return `Unknown gender`, `Female` or `Male`.