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,12 @@
#ifdef _DEBUG
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#ifndef DBG_NEW
#define DBG_NEW new ( _NORMAL_BLOCK , __FILE__ , __LINE__ )
#define new DBG_NEW
#endif
#endif

View File

@ -0,0 +1,5 @@
S030514 Sardina 10.875 8.30
B892310 Bacalao 5.750 10.50
T231 Trucha 6.2 18.75
K4356 Sardina 5.00 5.50
GA65455 Pescadilla 15.35 9.30

View File

@ -0,0 +1,56 @@
#include "listaCompradores.h"
using namespace std;
void iniciar(tListaComprador & lista){
lista.capacidad = 10;
lista.cont = 0;
lista.comprador = new tComprador*[lista.capacidad];
}
bool insertar(tListaComprador& lista, tComprador& comprador){
bool insertado = false;
int pos = 0;
if(!buscar(lista, comprador, pos)){
lista.comprador[lista.cont] = new tComprador;
lista.comprador[lista.cont]->id = comprador.id;
lista.comprador[lista.cont]->importe = comprador.importe;
lista.cont++;
insertado = true;
}
else {
lista.comprador[pos]->importe += comprador.importe;
}
return insertado;
}
bool buscar(tListaComprador & lista, tComprador& comprador, int& pos){
bool encontrado = false;
while (!encontrado && pos < lista.cont) {
if (lista.comprador[pos]->id == comprador.id) {
encontrado = true;
}
else {
pos++;
}
}
return encontrado;
}
void mostrar(tListaComprador & lista){
for (int i = 0; i < lista.cont; i++){
cout << right << setw(10) << "Comprador: " << lista.comprador[i]->id
<< setw(10) << "Total: " << lista.comprador[i]->importe << endl;
}
}
void liberar(tListaComprador & lista){
for (int i = 0; i < lista.cont; i++){
delete lista.comprador[i];
}
delete[] lista.comprador;
}

View File

@ -0,0 +1,29 @@
#ifndef H_LISTACOMPRADORES_H
#define H_LISTACOMPRADORES_H
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
#include <stdlib.h>
//Constantes:
//Tipos:
typedef struct tComprador {
long long int id, importe;
};
typedef struct tListaComprador {
tComprador** comprador;
int cont, capacidad;
};
//Funciones:
void iniciar(tListaComprador& lista);
bool insertar(tListaComprador& lista, tComprador& comprador);
bool buscar(tListaComprador& lista, tComprador& comprador, int& pos);
void mostrar(tListaComprador& lista);
void liberar(tListaComprador& lista);
#endif // !H_LISTACOMPRADORES_H

View File

@ -0,0 +1,115 @@
#include "listaLonja.h"
using namespace std;
//Funciones auxiliares:
bool busquedaRecursiva(tListaLotes & lista, tLotes& nuevo, int& ini, int& fin, int& pos);
void inicializar(tListaLotes & lista){
lista.cont = 0;
}
int numLotes(tListaLotes & lista){
return lista.cont;
}
bool insertar(tListaLotes & lista, tLotes& nuevo){
bool insertado = false;
int pos = 0;
if (!buscar(lista, nuevo, pos)) {
lista.lote[lista.cont] = new tLotes;
lista.lote[lista.cont]->lote = nuevo.lote;
lista.lote[lista.cont]->tipo = nuevo.tipo;
lista.lote[lista.cont]->precio = nuevo.precio;
lista.lote[lista.cont]->peso = nuevo.peso;
lista.cont++;
}
else {
lista.lote[lista.cont] = new tLotes;
for (int i = lista.cont; i > pos; i--){
lista.lote[i] = lista.lote[i - 1];
}
lista.lote[pos]->tipo = nuevo.tipo;
lista.lote[pos]->lote = nuevo.lote;
lista.lote[pos]->precio = nuevo.precio;
lista.lote[pos]->peso = nuevo.peso;
lista.cont++;
insertado = true;
}
return insertado;
}
bool cargar(tListaLotes & lista){
bool carga = false;
ifstream archivo;
tLotes aux;
inicializar(lista);
archivo.open("datos.txt");
if (!archivo.is_open()) {
cout << "Error al caragar el archivo." << endl;
}
else {
while (!archivo.fail() && lista.cont < MAX_LOTES) {
archivo >> aux.lote;
archivo >> aux.tipo;
archivo >> aux.precio;
archivo >> aux.peso;
if (!archivo.eof()) {
insertar(lista, aux);
}
}
carga = true;
}
return carga;
}
bool buscar(tListaLotes& lista, tLotes& nuevo, int& pos){
bool encontrado = false;
int ini = 0, fin = lista.cont - 1;
encontrado = busquedaRecursiva(lista, nuevo, ini, fin, pos);
return encontrado;
}
bool busquedaRecursiva(tListaLotes& lista, tLotes& nuevo, int& ini, int& fin, int& pos) {
bool encontrado = false;
if (ini <= fin) {
pos = (ini + fin) / 2;
if (nuevo < *lista.lote[pos]) {
fin = pos - 1;
encontrado = busquedaRecursiva(lista, nuevo, ini, fin, pos);
}
else if (*lista.lote[pos] < nuevo){
ini = pos + 1;
encontrado = busquedaRecursiva(lista, nuevo, ini, fin, pos);
}
else {
encontrado = true;
}
}
return encontrado;
}
void obeternerLote(tListaLotes& lista, tLotes* lote, int& pos){
lote = lista.lote[pos];
}
void mostrar(tListaLotes& lista, tListaComprador& comprador){
for (int i = 0; i < comprador.cont; i++){
mostrarPrecio(*lista.lote[i], *comprador.comprador[i]);
}
}
void liberar(tListaLotes & lista){
for (int i = 0; i < lista.cont; i++){
delete lista.lote[i];
}
}

View File

@ -0,0 +1,23 @@
#ifndef H_LISTALONJA_H
#define H_LISTALONJA_H
#include "lotes.h"
//Constantes:
//Tipos:
typedef struct tListaLotes {
tLotes* lote[MAX_LOTES];
int cont;
};
//Funciones:
void inicializar(tListaLotes& lista);
int numLotes(tListaLotes& lista);
bool insertar(tListaLotes& lista, tLotes& nuevo);
bool cargar(tListaLotes& lista);
bool buscar(tListaLotes& lista, tLotes& nuevo, int& pos); //Implementaci<63>n recursiva y binaria.
void obeternerLote(tListaLotes& lista, tLotes* lote, int& pos);
void mostrar(tListaLotes& lista, tListaComprador& comprador);
void liberar(tListaLotes& lista);
#endif // !H_LISTALONJA_H

View File

@ -0,0 +1,28 @@
#include "lotes.h"
#include "listaCompradores.h"
using namespace std;
bool operator<(tLotes& loteIzq, tLotes& loteDer){
return (loteIzq.tipo < loteDer.tipo);
}
bool operator==(tLotes& loteIzq, tLotes& loteDer){
return (loteIzq.id == loteDer.id);
}
void mostrarLote(const tLotes& lote){
cout << right << setw(15) << "Lote: " << lote.lote
<< setw(25) << setprecision(2) << "Peso del lote: " << lote.peso << endl
<< setw(15) << "Tipo: " << lote.tipo << setw(25) << "Precio de salida: " << lote.precio << endl << endl;
}
void mostrarPrecio(tLotes & lote, tComprador& comprador){
cout << right << setw(15) << "Lote: " << lote.lote
<< setw(25) << setprecision(2) << "Comprador: " << comprador.id << endl
<< setw(15) << "Tipo: " << lote.tipo << setw(25) << "Precio de compra: " << comprador.importe << endl;
}
void modificarLote(tLotes & lote, long long int& id, float& precio){
lote.id = id;
lote.precio = precio;
}

View File

@ -0,0 +1,29 @@
#ifndef H_LOTES_H
#define H_LOTES_H
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
#include <stdlib.h>
#include "listaCompradores.h"
//Constantes:
const int MAX_LOTES = 300;
//Tipos:
typedef struct tLotes {
std::string lote, tipo;
float peso, precio;
long long int id;
};
//Funciones:
bool operator<(tLotes& loteIzq, tLotes& loteDer);
bool operator==(tLotes& loteIzq, tLotes& loteDer);
void mostrarLote(const tLotes& lote);
void mostrarPrecio(tLotes& lote, tComprador& comprador);
void modificarLote(tLotes& lote, long long int& id, float& precio);
#endif // !H_LOTES_H

View File

@ -0,0 +1,41 @@
//Examen Junio 2017 - FP
//Grupos D y G
//Fernando M<>ndez Torrubiano
using namespace std;
#include "listaLonja.h"
#include "CheckML.h"
int main() {
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); //Detecta posibles fugas de memoria.
system("chcp 1252"); //Castellano
system("cls");
tListaLotes listaLotes;
tListaComprador listaComprador;
iniciar(listaComprador);
tComprador aux;
int i = 0;
if (cargar(listaLotes)) {
while (i < listaLotes.cont) {
mostrarLote(*listaLotes.lote[i]);
cout << "Introduzca comprador y precio: ";
cin >> aux.id;
cin >> aux.importe;
insertar(listaComprador, aux);
i++;
}
mostrar(listaComprador);
mostrar(listaLotes, listaComprador);
}
else {
cout << "Error al cargar la lista." << endl;
}
system("PAUSE");
liberar(listaLotes);
liberar(listaComprador);
return 0;
}