-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathColectivo.cpp
More file actions
216 lines (192 loc) · 8.1 KB
/
Copy pathColectivo.cpp
File metadata and controls
216 lines (192 loc) · 8.1 KB
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#define _CRT_SECURE_NO_WARNINGS
#include "Colectivo.h"
#define Tarifa 15
Colectivo::Colectivo(string codigo_colec, unsigned int cant_max_pas, eDireccion direccion,
float peso_max): codigo_colec(codigo_colec)
{
tarifa = Tarifa;
parada = 0;
puerta = false;
EstadoFunicionamiento = true;
peso_actual = 0;
cant_pasajeros = 0;
pasajeros_totales = 0;
monto_total = 0;
this->cant_max_pas = cant_max_pas;
this->direccion = direccion;
this->peso_max = peso_max;
ramal = NULL;
ListaPasajerosCole = new cListaT<Pasajero>(cant_max_pas);
}
Colectivo::~Colectivo()
{
delete ListaPasajerosCole;
}
void Colectivo::SubirPasajero(Ramal *R)
{
//recorrer la lista de paradas que posee el ramal, en el orden indicado
if (R != NULL) {
int inicio = R->GetCod();
for (int i = inicio; i < inicio - 1; i++)
{
//abrimos las puertas del colectivo
puerta = true;
if (VerificarPesoCant()==true)
{
//subimos primero los pasajeros con discapacidad
if (i == R->ListaParadas.getItem(i)->ListaPasajeros->getItem(i)->GetParadaInicial() &&
R->ListaParadas.getItem(i)->ListaPasajeros->getItem(i)->GetDisc() == true)
{
if (cant_pasajeros < cant_max_pas) // hay lugar en el colectivo?
{
try {
ListaPasajerosCole->AgregarItem(R->ListaParadas.getItem(i)->ListaPasajeros->getItem(i));
}
catch (exception* e)
{
cout << e->what() << endl;
break; // no suben mas pasajeros
}
//eliminamos de la lista de pasajeros de la parada, al pasajero que subimos
//ver de manejar la excepcion de eliminar item
try {
R->ListaParadas.getItem(i)->ListaPasajeros->EliminarPorItem(R->ListaParadas.getItem(i)->ListaPasajeros->getItem(i));
}
catch (exception* e){
cout << e->what() << endl;
}
this->cant_pasajeros = cant_pasajeros + 1;
this->pasajeros_totales = pasajeros_totales + 1;
}
}
if (i == R->ListaParadas.getItem(i)->ListaPasajeros->getItem(i)->GetParadaInicial() &&
R->ListaParadas.getItem(i)->ListaPasajeros->getItem(i)->GetDisc() == false)
{
if (cant_pasajeros < cant_max_pas) // hay lugar en el colectivo?
{
float tarifa = CalcularTarifa(R->ListaParadas.getItem(i)->ListaPasajeros->getItem(i)->GetParadaInicial(),
R->ListaParadas.getItem(i)->ListaPasajeros->getItem(i)->GetParadaFinal());
Cobrar(R->ListaParadas.getItem(i)->ListaPasajeros->getItem(i), tarifa);
try {
ListaPasajerosCole->AgregarItem(R->ListaParadas.getItem(i)->ListaPasajeros->getItem(i));
}
catch (exception* e)
{
cout << e->what() << endl;
break; // no suben mas pasajeros
}
//eliminamos de la lista de pasajeros de la parada, al pasajero que subimos
//manejar excepcion
try {
R->ListaParadas.getItem(i)->ListaPasajeros->EliminarPorItem(R->ListaParadas.getItem(i)->ListaPasajeros->getItem(i));
}
catch (exception* e) {
cout << e->what() << endl;
}
this->cant_pasajeros = cant_pasajeros + 1;
this->pasajeros_totales = pasajeros_totales + 1;
}
}
}
//cerramos la puerta
puerta = false;
}
}
}
void Colectivo::Cobrar(Pasajero* P, float monto)
{
try
{
P->Pagar(monto);
}
catch (exception& e)
{
throw e;
}
monto_total = monto_total + monto;
}
void Colectivo::BajarPasajero(Ramal* R)
{
//recorrer la lista de paradas que posee el ramal, en el orden indicado
if (R != NULL) {
int inicio = R->GetCod();
for (int i = inicio; i < inicio - 1; i++)
{
//abrimos las puertas del colectivo
puerta = true;
//bajamos a los pasajero cuya para final sea igual a la parada en la que nos encontramos
if (i == ListaPasajerosCole->getItem(i)->GetParadaFinal())
{
try {
ListaPasajerosCole->EliminarPorItem(ListaPasajerosCole->getItem(i));
}
catch (exception* e) {
cout << e->what() << endl;
}
this->cant_pasajeros = cant_pasajeros - 1;
}
}
//cerramos la puerta
puerta = false;
}
}
bool Colectivo::VerificarPesoCant()
{
int ca = ListaPasajerosCole->getCA(); //cantidad de pasajeros en la lista
for (int i = 0; i < ca; i++)
{
peso_actual = peso_actual + ListaPasajerosCole->getItem(i)->GetPeso();
}
if (cant_max_pas <= cant_pasajeros || peso_max <= peso_actual)
return false; //si supera la capacidad de pasajeros o la capacidad de peso
else
return true;//hay lugar para que suban mas pasajeros y no superan la capacidad de peso
}
void Colectivo::ColectivoRoto(cListaT<Colectivo>* Lista, Colectivo* colec_roto)
{
for (int i = 0; i < Lista->getCA(); i++)
{
if (Lista->getItem(i)->EstadoFunicionamiento == true && colec_roto->EstadoFunicionamiento == false)
{
//preguntamos que tenga lugar para recibir los pasajeros del colectivo roto
if (Lista->getItem(i)->GetCantMax() - Lista->getItem(i)->GetCantActual() > colec_roto->GetCantActual())
{
//colec_sano = colec_roto; //ver aca!
cListaT<Pasajero>* aux = new cListaT<Pasajero>(Lista->getItem(i)->cant_max_pas);
for (int i = 0; i < Lista->getItem(i)->ListaPasajerosCole->getCA(); i++)
{
//nos copiamos los pasajeros del colectivo sano a la lista aux
aux[i] = Lista->getItem(i)->ListaPasajerosCole[i];
}
for (int i = aux->getCA(); i < aux->getTAM(); i++)
{
//nos copiamos los pasajeros del colectivo roto a la lista aux, justo despues de los pasajeros del colectivo sano.
aux[i] = colec_roto->ListaPasajerosCole[i];
}
//vaciamos la lista de pasajeros del colectivo sano (no la eliminamos)
delete[] Lista->getItem(i)->ListaPasajerosCole;
//nos copiamos la lista auxiliar a nuestra lista original vacia
Lista->getItem(i)->ListaPasajerosCole = aux;
//-----------------TALLLER-----------------//
colec_roto->EstadoFunicionamiento = true;
AsignarRamal(colec_roto);
}
}
}
}
ostream& operator<<(ostream& os, Colectivo& Cole)
{
os << "Colectivo:" << endl << "Codigo " << Cole.GetClave()<< endl;
os << "Cantidad Maxima de pasajeros: " << Cole.GetCantMax() << endl;
os << "Tarifa: " << Cole.GetTarifa() << endl;
return os;
}
istream& operator>>(istream& in, Colectivo& Cole)
{
cout << "Ingrese el valor de la nueva Tarifa: ";
float aux;
in >> aux;
aux += Cole.GetTarifa();
Cole.SetTarifa(aux);
return in;
}