-
Notifications
You must be signed in to change notification settings - Fork 0
/
aldeano.cpp
118 lines (89 loc) · 2.58 KB
/
aldeano.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include "aldeano.h"
using namespace std;
Aldeano::Aldeano(){}
Aldeano::Aldeano(const Aldeano& a) : nombreA(a.nombreA), edadA(a.edadA), generoA(a.generoA), saludA(a.saludA){ }
int Aldeano::getEdadA() const{
return edadA;
}
void Aldeano::setEdadA(int value){
edadA = value;
}
string Aldeano::getGeneroA() const{
return generoA;
}
void Aldeano::setGeneroA(const string &value){
generoA = value;
}
int Aldeano::getSaludA() const{
return saludA;
}
void Aldeano::setSaludA(int value){
saludA = value;
}
string Aldeano::getNombreA() const{
return nombreA;
}
void Aldeano::setNombreA(const string &value){
nombreA = value;
}
string Aldeano::toString(){
//Se convierte la salud y la edad a una string para poder imprimir
char miEdad[7];
char miSalud[7];
sprintf(miEdad, "%d", edadA);
sprintf(miSalud, "%d", saludA);
return "\t\t\t+ " + nombreA + " | " + generoA + " | " + miEdad + " | " + miSalud;
}
Aldeano &Aldeano::operator = (const Aldeano &a){
//Ahora el compilador puede igualar
nombreA = a.nombreA;
edadA = a.edadA;
generoA = a.generoA;
saludA = a.saludA;
return *this;
}
ostream &operator <<(ostream &o, Aldeano &a){
//Se convierte la salud y la edad a una string para poder imprimir
char miSalud[7];
sprintf(miSalud, "%d", a.saludA);
char miEdad[7];
sprintf(miEdad, "%d", a.edadA);
o << "\t\t\t+ "
<< a.nombreA
<< " | " << miEdad
<< " | " << a.generoA
<< " | " << miSalud << " HP";
return o;
}
istream &operator >> (istream &is, Aldeano &a){
//Se convierte la salud y la edad a una string para poder guardar
is >> a.nombreA;
string myStr;
getline(is, myStr) >> a.edadA;
a.edadA = atof(myStr.c_str());
is >> a.generoA;
string myStr2;
getline(is, myStr2) >> a.saludA;
a.saludA = atof(myStr2.c_str());
return is;
}
bool Aldeano::operator == (const Aldeano &a){
//Operador sobrecargado para poder comparar
return nombreA == a.nombreA;
}
//Resto de operadores existentes (Hacer posible cambio a la edad y no al nombre)
bool Aldeano::operator != (const Aldeano &a){
return nombreA != a.nombreA;
}
bool Aldeano::operator <= (const Aldeano &a){
return nombreA <= a.nombreA;
}
bool Aldeano::operator >= (const Aldeano &a){
return nombreA >= a.nombreA;
}
bool Aldeano::operator < (const Aldeano &a){
return nombreA < a.nombreA;
}
bool Aldeano::operator > (const Aldeano &a){
return nombreA > a.nombreA;
}