Add files via upload

This commit is contained in:
Fernando Méndez
2019-06-20 13:06:16 +02:00
committed by GitHub
parent 989e433448
commit 2fd3b1e062
80 changed files with 2922 additions and 0 deletions

View File

@ -0,0 +1,72 @@
#include "ListaReproduccion.h"
using namespace std;
void nueva(tListaReproduccion& lista) {
//La capacidad y el nombre se guardan directamente en el main().
lista.elemento = new tElemento[lista.capacidad];
lista.cont = 0;
}
bool insertar(tListaReproduccion& lista, tElemento& elemento) {
bool insertado = false;
int ini = 0, fin = lista.cont - 1, pos = 0;
if (!buscar(lista, elemento.puntero[pos].titulo, ini, fin, pos)) {
lista.elemento[lista.cont].puntero = elemento.puntero;
lista.elemento[lista.cont].valoracion = elemento.valoracion;
lista.cont++;
insertado = true;
}
else {
lista.elemento[pos].puntero = elemento.puntero;
lista.elemento[pos].valoracion = elemento.valoracion;
}
return insertado;
}
bool buscar(tListaReproduccion& lista, std::string titulo, int& ini, int& fin, int& pos) {
bool encontrado = false;
if (ini <= fin) {
pos = (ini + fin) / 2;
if (titulo < lista.elemento[pos].puntero->titulo) {
fin = pos - 1;
encontrado = buscar(lista, titulo, ini, fin, pos);
}
else if (lista.elemento[pos].puntero->titulo < titulo) {
ini = pos + 1;
encontrado = buscar(lista, titulo, ini, fin, pos);
}
else {
encontrado = true;
}
}
return encontrado;
}
void mostrar(tListaReproduccion& lista) {
cout << "Lista: " << lista.nombreLista << endl;
for (int i = 0; i < lista.cont; i++){
cout << i + 1 << ".-";
mostrar(*lista.elemento[i].puntero);
cout << " (" << lista.elemento[i].valoracion << ")" << endl;
}
}
void modificarOrden(tListaReproduccion& lista, int& origen, int& fin) {
tElemento aux;
aux = lista.elemento[origen];
for (int i = origen; i > fin - 1; i--){
lista.elemento[i] = lista.elemento[i - 1];
}
lista.elemento[fin] = aux;
}
void destruir(tListaReproduccion& lista) {
delete[] lista.elemento;
}

View File

@ -0,0 +1,31 @@
#ifndef _LISTAREPRODUCCIONES
#define _LISTAREPRODUCCIONES
#include "ListaTemas.h"
//Constantes:
//Tipos:
typedef struct tElemento {
tTema *puntero;
int valoracion;
};
typedef struct tListaReproduccion{
tElemento *elemento;
std::string nombreLista;
int capacidad;
int cont;
};
//Funciones:
void nueva(tListaReproduccion& lista);
bool insertar(tListaReproduccion& lista, tElemento& elemento);
bool buscar(tListaReproduccion& lista, std::string titulo, int& ini, int& fin, int& pos); //Binaria y recursiva.
void mostrar(tListaReproduccion& lista);
void modificarOrden(tListaReproduccion& lista, int& origen, int& fin);
void destruir(tListaReproduccion& lista);
#endif // !_LISTAREPRODUCCIONES

View File

@ -0,0 +1,34 @@
#include "ListaTemas.h"
using namespace std;
bool cargar(tListaTemas& lista) {
bool carga = false;
ifstream archivo;
int numTemas = 0;
lista.cont = 0;
archivo.open("temas.txt");
if (!archivo.is_open()) {
cout << "Error al cargar los temas." << endl;
}
else {
archivo >> numTemas;
while (!archivo.fail() && lista.cont < numTemas) {
lista.tema[lista.cont] = new tTema;
if (cargar(*lista.tema[lista.cont], archivo)) {
lista.cont++;
}
}
carga = true;
}
archivo.close();
return carga;
}
void destruir(tListaTemas& lista) {
for (int i = 0; i < lista.cont; i++){
delete lista.tema[i];
}
}

View File

@ -0,0 +1,20 @@
#ifndef _LISTATEMAS
#define _LISTATEMAS
#include "Tema.h"
//Constantes:
const int MAX_TEMAS = 50;
//Tipos:
typedef struct tListaTemas {
tTema *tema[MAX_TEMAS];
int cont;
};
//Funciones:
bool cargar(tListaTemas& lista);
void destruir(tListaTemas& lista);
#endif // !_LISTATEMAS

View File

@ -0,0 +1,21 @@
#include "Tema.h"
using namespace std;
bool cargar(tTema& tema, ifstream& archivo) {
bool carga = false;
if (!archivo.fail()) {
archivo >> tema.titulo;
archivo >> tema.interprete;
archivo >> tema.segundos;
carga = true;
}
return carga;
}
void mostrar(tTema& tema) {
cout << right << setw(7) << tema.titulo
<< setw(15) << tema.interprete
<< setw(10) << tema.segundos << " seg.";
}

View File

@ -0,0 +1,23 @@
#ifndef _TEMA
#define _TEMA
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
//Constantes:
//Tipos:
typedef struct tTema {
std::string titulo, interprete;
int segundos;
};
//Funciones:
bool cargar(tTema& tema, std::ifstream&);
void mostrar(tTema& tema);
#endif // !_TEMA

View File

@ -0,0 +1,9 @@
#ifdef _DEBUG
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#ifndef DBG_NEW
#define DBG_NEW new (_NORMAL_BLOCK , __FILE__<5F>, __LINE__<5F>)
#define new DBG_NEW
#endif
#endif // _DEBUG

View File

@ -0,0 +1,56 @@
//Examen Junio 2016 - FP
//Grupo_1
//Fernando M<>ndez Torrubiano
#include "ListaReproduccion.h"
#include "checkML.h"
using namespace std;
int main() {
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); //Detecta fugas de memoria.
system("chcp 1252"); //Castellano.
system("cls");
srand(1);
tListaTemas listaTemas;
tListaReproduccion listaReproduccion;
int origen, fin;
if (cargar(listaTemas)) {
cout << "Nombre: ";
cin >> listaReproduccion.nombreLista;
do {
cout << "Numero de temas: ";
cin >> listaReproduccion.capacidad;
} while (listaReproduccion.capacidad < 0 || listaReproduccion.capacidad > listaTemas.cont);
nueva(listaReproduccion);
for (int i = 0; i < listaReproduccion.capacidad; i++){
listaReproduccion.elemento[i].puntero = listaTemas.tema[0 + rand() % listaReproduccion.capacidad];
listaReproduccion.elemento[i].valoracion = 0 + rand() % listaReproduccion.capacidad;
if (!insertar(listaReproduccion, listaReproduccion.elemento[i])) {
i--;
}
}
mostrar(listaReproduccion);
origen = 4;
//origen = 0 + rand() % listaReproduccion.capacidad;
fin = 0;
//fin = 0 + rand() % listaReproduccion.capacidad;
cout << "Cambio de orden: " << origen + 1 << " al " << fin + 1 << endl;
modificarOrden(listaReproduccion, origen, fin);
mostrar(listaReproduccion);
system("PAUSE");
}
else {
cout << "Fin del programa." << endl;
system("PAUSE");
}
destruir(listaTemas);
destruir(listaReproduccion);
return 0;
}

View File

@ -0,0 +1,16 @@
5
titulo1
interprete1
240
titulo2
interprete2
274
titulo3
interprete3
180
titulo4
interprete4
60
titulo5
interprete5
60