Está en la página 1de 4

Solución.

/*
* Fundamentos de inform�tica. Escuela de Ingenier�as Industriales.
M�laga.
* Tercera pr�ctica evalluable
* Ejercicio. Gesti�n de una carrera de marat�n
*/
#include <iostream>
#include <string>
#include <array>
using namespace std;
//------------------------------------
const int MAX_CORREDORES = 10;
typedef struct{
int h, m, s;
} Tiempo;
typedef struct{
string dni;
Tiempo medio, fin;
} Corredor;
typedef array <Corredor, MAX_CORREDORES> DCorredores;
typedef struct{
int tam;
DCorredores dat;
} ListaCorredores;
//------------------------------------
bool menor(const Tiempo& t1, const Tiempo& t2)
{
return (t1.h < t2.h)
|| ((t1.h == t2.h) && (t1.m < t2.m))
|| ((t1.h == t2.h) && (t1.m == t2.m) && (t1.s < t2.s));
}
//------------------------------------
void mostrar_hora(const Tiempo& t)
{
cout << t.h << " h " << t.m << " m " << t.s << " s ";
}
//------------------------------------
void mostrar_corredor(const Corredor& c)
{
cout << c.dni;
if (menor(c.medio, c.fin)){
cout << ". Intermedio: ";
mostrar_hora(c.medio);
cout << " Llegada: ";
mostrar_hora(c.fin);
}else{
cout << ". Error.";
}
}
//------------------------------------
void mostrar_lista_corredores(const ListaCorredores& l)
{
for(int i = 0; i < l.tam; i++){
mostrar_corredor(l.dat[i]);
cout << endl;
}
}
//------------------------------------
int buscar_corredor(const string& dni, const ListaCorredores& l)
{
int i = 0;
while (i < l.tam && dni != l.dat[i].dni){
i++;
}
return i;
}
//------------------------------------
void consultar_corredor(const string& dni, const ListaCorredores& l)
{
int p = buscar_corredor(dni, l);
if (p == l.tam){
cout << "Error. El corredor no se encuentra" << endl;
}else{
mostrar_corredor(l.dat[p]);
}
}
//------------------------------------
void desplazar_izq(ListaCorredores& l, int p)
{
for(int i = p; i < l.tam-1; i++){
l.dat[i] = l.dat[i+1];
}
l.tam--;
}
//------------------------------------
void descalificar_corredor(const string& dni, ListaCorredores& l)
{
int p = buscar_corredor(dni, l);
if(p == l.tam){
cout << "Error. El corredor no est� en la lista"<< endl;
}else{
desplazar_izq(l, p);
cout << "Corredor descalificado"<< endl;
}
}
//------------------------------------
bool informacion_correcta(const ListaCorredores& l)
{
int i = 0;
while ((i < l.tam-1) && !menor(l.dat[i+1].fin, l.dat[i].fin)){
i++;
}
return i == l.tam-1;
}
//------------------------------------
char menu ()
{
char opcion;

cout << endl;


cout << "=========================================" << endl;
cout << "a. Mostrar todos los participantes." << endl;
cout << "b. Mostrar un participante." << endl;
cout << "c. Descalificar a un participante." << endl;
cout << "d. Comprobar si la clasificaci�n es correcta." << endl;
cout << "x. Salir.\n";
cout << "=========================================" << endl;
do {
cout << "Introduzca Opcion: ";
cin >> opcion;
} while ( ! (((opcion >= 'a') && (opcion <= 'f')) || (opcion ==
'x')));
return opcion;
}
//------------------------------------
int main ()
{
ListaCorredores l = {7,
{{
{"111A", {1, 10, 20}, {2, 20, 2}},
{"222A", {2, 20, 17}, {1, 20, 2}}, // Error
{"333A", {1, 15, 14}, {2, 22, 21}},
{"444A", {1, 17, 12}, {2, 22, 21}},
{"555A", {1, 16, 11}, {2, 28, 21}},
{"666A", {1, 23, 45}, {2, 28, 22}},
{"777A", {1, 21, 36}, {3, 28, 22}}
}}
};
char opcion;
string dni;

cout << "Nombre del alumno: PONGA AQUI SU NOMBRE" << endl;
cout << "Ordenador: PONGA AQUI SU ORDENADOR" << endl;

do {
opcion = menu();
switch (opcion) {
case 'a':
cout << "------------------------------------" << endl;
cout << "Lista de participantes: " << endl;
cout << "------------------------------------" << endl;
mostrar_lista_corredores(l);
break;
case 'b':
cout << "------------------------------------" << endl;
cout << "Consulta de un participante: " << endl;
cout << "------------------------------------" << endl;
cout << "Introduzca dni: ";
cin >> dni;
consultar_corredor(dni, l);
break;
case 'c':
cout << "------------------------------------" << endl;
cout << "Descalificar a un participante: " << endl;
cout << "------------------------------------" << endl;
cout << "Introduzca dni: ";
cin >> dni;
descalificar_corredor(dni, l);
break;
case 'd':
cout << "------------------------------------" << endl;
cout << "Comprobar que la clasificaci�n es correcta: " <<
endl;
cout << "------------------------------------" << endl;
if(informacion_correcta(l)){
cout << "La informaci�n es correcta" << endl;
}else{
cout << "Error. Los participantes no est�n en orden"
<< endl;
}
break;
}
} while (opcion != 'x');
}
//------------------------------------

También podría gustarte