-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
129 lines (107 loc) · 3.8 KB
/
main.cpp
File metadata and controls
129 lines (107 loc) · 3.8 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
#define _CRT_SECURE_NO_WARNINGS
#include "Definiciones.h"
#include "Funciones.h"
#define TICK 480
int main()
{
//nos creamos un colectivo de cada clase
Colectivo* nuevo = new Nuevo("01",15,eDireccion::Electrica,300);
Colectivo* viejo = new Viejo("02", 10, eDireccion::Hidraulica, 250);
Nuevo* acordeon = new Acordeon("03", 20, eDireccion::Electrica, 350);
//le asignamos un ramal a cada colectivo
AsignarRamal(nuevo);
AsignarRamal(viejo);
AsignarRamal(acordeon);
//nos creamos la lista de colectivos
cListaT<Colectivo>* ListaColectivos = new cListaT<Colectivo>();
try{
ListaColectivos->AgregarItem(nuevo);
}
catch (exception *ex) {
cout << ex->what() << endl;
delete ex;
}
try {
ListaColectivos->AgregarItem(viejo);
}
catch (exception* ex) {
cout << ex->what() << endl;
delete ex;
}try {
ListaColectivos->AgregarItem(acordeon);
}
catch (exception* ex) {
cout << ex->what() << endl;
delete ex;
}
//------------------SIMULACION------------------
for (int i = 0; i < TICK; i++)
{
//recorremos la lista de colectivos
for (unsigned int i = 0; i < ListaColectivos->getCA(); i++)
{
if (i % 5 == 0) //cada 5 min actualizamos la poscion
{
int pos = ListaColectivos->getItem(i)->GetParada();
string nombre=ListaColectivos->getItem(i)->GetRamal()->GetLista().getItem(pos)->GetNombre();
cout << "Colectivo: " << ListaColectivos->getItem(i)->GetClave()
<< "se encuentra en la parada: " << nombre << endl;
}
if (Acordeon* actual = dynamic_cast<Acordeon*>(ListaColectivos->getItem(i))) //ver
{
if (actual->GetAire() == false)
actual->PrenderApagarAire(true);
}
else if (Nuevo* actual = dynamic_cast<Nuevo*>(ListaColectivos->getItem(i)))
{
if (actual->GetAire() == false)
actual->PrenderApagarAire(true);
}
//recorremos la lista de paradas de cada colectivo
int incio = ListaColectivos->getItem(i)->GetRamal()->GetCod();
for (int i = incio; i < ListaColectivos->getItem(i)->GetRamal()->GetLista().getCA() - incio; i++)
{
//vamos actualizando la parada actual en la que se encuentra
ListaColectivos->getItem(i)->SetParada(i);
//bajamos pasajeros por cada colectivo que haya en la lista
ListaColectivos->getItem(i)->BajarPasajero(ListaColectivos->getItem(i)->GetRamal());
//subimos pasajeros por cada colectivo que haya en la lista
ListaColectivos->getItem(i)->SubirPasajero(ListaColectivos->getItem(i)->GetRamal());
}
//apagamos los aires
for (unsigned int i = 0; i < ListaColectivos->getCA(); i++)
{
if (Acordeon* actual = dynamic_cast<Acordeon*>(ListaColectivos->getItem(i))) //ver
{
if (actual->GetAire() == true)
actual->PrenderApagarAire(false);
}
else if (Nuevo* actual = dynamic_cast<Nuevo*>(ListaColectivos->getItem(i)))
{
if (actual->GetAire() == true)
actual->PrenderApagarAire(false);
}
}
//cuando el colectivo termina su recorrido, le asignamos un nuevo ramal de manera dinamica
AsignarRamal(ListaColectivos->getItem(i));
}
}
viejo->SetEstado(false);
viejo->ColectivoRoto(ListaColectivos, viejo);
//imprimimos monto total de cada colectivo, cantidad de pasajeros que se suben y el total de todos los colectivos
string info = InfoDia(ListaColectivos);
cout << info << endl;
for (int i = 0; i < ListaColectivos->getCA(); i++)
{
cout << ListaColectivos->getItem(i) << endl;
cout << "-----------------------------------------" << endl;
cout << ListaColectivos->getItem(i)->GetRamal() << endl;
cout << "-----------------------------------------" << endl;
cout << ListaColectivos->getItem(i)->GetRamal()->GetLista().getItem(i) << endl;
cout << "-----------------------------------------" << endl;
cout << ListaColectivos->getItem(i)->GetLista()->getItem(i) << endl;
}
//ver liberar memoria
//ListaColectivos->~cListaT();
return 0;
}