-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunciones.cpp
More file actions
146 lines (129 loc) · 3.68 KB
/
Funciones.cpp
File metadata and controls
146 lines (129 loc) · 3.68 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
#pragma once
#define _CRT_SECURE_NO_WARNINGS
#include "Funciones.h"
cListaT<Parada> CargarLista(cListaT<Parada> Lista)
{
cListaT <Parada> aux = Lista;
string NomParada[12] = { "Catedral", "Juramento", "Olleros", "Carranza", "Pueyrredon", "Tribunales", "Cabildo", "Palermo", "PlazaItalia", "Congreso", "Bulnes", "Aguero" };
string DireParadas[12] = { "a","b","c","d","e","f", "g", "h", "i", "j", "k", "L" };
int parada_final=0, parada_inicial=0;
for (int i = 0; i < 12; i++) //recorremos la lista de paradas
{
srand(time(0));
int cantPasajeros = (rand() % 11) + 1;
cListaT<Pasajero>* ListaPasajeros = new cListaT<Pasajero>();
for (int j = 0; j < cantPasajeros; j++)
{
if (j % 5 == 0 && j > 0)
{
srand(time(0));
do
{
parada_final = 1 + (rand() % (13 - 1));
parada_inicial = 1 + (rand() % (13 - 1));
} while (parada_final==parada_inicial);
int boleto = 1+(rand() % (256 - 9));
Pasajero* pasajero_discapacitado = new Pasajero(parada_final,parada_inicial, to_string(boleto), true);
try {
ListaPasajeros->AgregarItem(pasajero_discapacitado);
}
catch (exception* ex) {
cout << ex->what() << endl;
delete ex;
}
}
else
{
srand(time(0));
do
{
parada_final = 1 + (rand() % (13 - 1));
parada_inicial = 1 + (rand() % (13 - 1));
} while (parada_final == parada_inicial);
int boleto = 1 + (rand() % (256 - 9));
Pasajero* pasajero = new Pasajero(parada_final, parada_inicial, to_string(boleto), true);
try {
ListaPasajeros->AgregarItem(pasajero);
}
catch (exception* ex) {
cout << ex->what() << endl;
delete ex;
}
}
}
Parada* parada = new Parada(i++, DireParadas[i], NomParada[i], ListaPasajeros);
aux + parada;
}
return aux;
}
Ramal* GenerarRamal()
{
cListaT<Parada> ListaParadas;
ListaParadas = CargarLista(ListaParadas);
Ramal* ramal = new Ramal(ListaParadas);
srand(time(0));
int NumRamal = (rand() % 3) + 1;
switch (NumRamal)
{
case 1: {
ramal->SetNom(eRamal::RamalA);
ramal->SetCod(0);
break; }
case 2: {
ramal->SetNom(eRamal::RamalB);
ramal->SetCod(12);
break; }
case 3: {
ramal->SetNom(eRamal::RamalC);
ramal->SetCod(6);
break; }
case 4: {
ramal->SetNom(eRamal::RamalD);
ramal->SetCod(5);
break; }
}
return ramal;
}
void AsignarRamal(Colectivo* Cole)
{
Ramal* aux = NULL;
if (Cole->GetRamal() == NULL)
{
aux = GenerarRamal();
Cole->SetRamal(aux);
}
else
{ //llamamos a la funcion GenerarRamal hasta que nos genere un ramal cuya parada inicial
//sea igual a la parada final de nuestro ramal actual
do
{
aux = GenerarRamal();
} while (Cole->GetRamal()->GetFinal() != aux->GetCod());
Cole->SetRamal(aux);
}
}
string InfoDia(cListaT<Colectivo>* Lista)
{
stringstream Datos;
float monto_totalcolectivos = 0;
int totalidad_pasajeros = 0;
//recorremos la lista de colectivos
for (int i = 0; i < Lista->getCA(); i++)
{
//sumamos los montos de cada colectivo
monto_totalcolectivos = monto_totalcolectivos + Lista->getItem(i)->GetMonto();
//sumamos la cantidad de pasajeros que subieron en el dia por colectivo
totalidad_pasajeros = totalidad_pasajeros + Lista->getItem(i)->GetPasajerosTot();
}
Datos << "Monto total recolectado: " << monto_totalcolectivos << endl;
Datos << "Cantidad total de pasajeros: " << totalidad_pasajeros << endl;
//recorremos la lista de colectivos
for (int i = 0; i < Lista->getCA(); i++)
{
Datos << "Colectivo:" << Lista->getItem(i)->GetClave() << endl
<< "Ramal: " << Lista->getItem(i)->GetRamal()->GetNom() << "Total Pasajeros: " <<
Lista->getItem(i)->GetPasajerosTot() << endl
<< "Total Recaudado: " << Lista->getItem(i)->GetMonto() << endl;
}
return Datos.str();
}