Add files via upload
This commit is contained in:
@ -0,0 +1,54 @@
|
||||
#include "Envio.h"
|
||||
using namespace std;
|
||||
|
||||
bool cargar(tEnvio& envio, std::ifstream& archivo) {
|
||||
bool carga = false;
|
||||
int numItems = 0;
|
||||
|
||||
envio.cont = 0;
|
||||
|
||||
archivo.ignore();
|
||||
getline(archivo, envio.destinatario);
|
||||
getline(archivo, envio.ciudad);
|
||||
archivo >> numItems;
|
||||
envio.item = new tItem[numItems];
|
||||
for (int i = 0; i < numItems; i++){
|
||||
cargar(envio.item[i], archivo);
|
||||
envio.cont++;
|
||||
}
|
||||
if (!archivo.fail()) { carga = true; }
|
||||
|
||||
return carga;
|
||||
}
|
||||
|
||||
void mostrar(tEnvio& envio) {
|
||||
cout << "A " << envio.destinatario << " de " << envio.ciudad << ":" << endl;
|
||||
for (int i = 0; i < envio.cont; i++){
|
||||
mostrar(envio.item[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void destruir(tEnvio& envio) {
|
||||
delete[] envio.item;
|
||||
}
|
||||
|
||||
int cantidad(tEnvio& envio, std::string id, int& ini, int&fin, int& pos) {
|
||||
int cant = 0;
|
||||
|
||||
if (ini <= fin) {
|
||||
pos = (ini + fin) / 2;
|
||||
if (id < envio.item[pos].id) {
|
||||
fin = pos - 1;
|
||||
cant = cantidad(envio, id, ini, fin, pos);
|
||||
}
|
||||
else if (envio.item[pos].id < id) {
|
||||
ini = pos + 1;
|
||||
cant = cantidad(envio, id, ini, fin, pos);
|
||||
}
|
||||
else {
|
||||
cant = envio.item[pos].cantidad;
|
||||
}
|
||||
}
|
||||
|
||||
return cant;
|
||||
}
|
23
Exámenes Resultos (Extraordinaria)/Septiembre2016_1/Envio.h
Normal file
23
Exámenes Resultos (Extraordinaria)/Septiembre2016_1/Envio.h
Normal file
@ -0,0 +1,23 @@
|
||||
#ifndef _ENVIO
|
||||
#define _ENVIO
|
||||
|
||||
#include "ItemPedido.h"
|
||||
|
||||
//Constantes:
|
||||
|
||||
|
||||
//Tipos:
|
||||
typedef struct tEnvio {
|
||||
tItem *item; //NO ORDENADA.
|
||||
std::string destinatario, ciudad;
|
||||
int cont;
|
||||
};
|
||||
|
||||
//Funciones:
|
||||
bool cargar(tEnvio& envio, std::ifstream& archivo);
|
||||
void mostrar(tEnvio& envio);
|
||||
void destruir(tEnvio& envio);
|
||||
int cantidad(tEnvio& envio, std::string id, int& ini, int&fin, int& pos); //Recursiva.
|
||||
|
||||
|
||||
#endif // !_ENVIO
|
@ -0,0 +1,22 @@
|
||||
#include "ItemPedido.h"
|
||||
using namespace std;
|
||||
|
||||
bool cargar(tItem& item, std::ifstream& archivo) {
|
||||
bool carga = false;
|
||||
|
||||
archivo.ignore();
|
||||
getline(archivo, item.id);
|
||||
getline(archivo, item.nombre);
|
||||
archivo >> item.cantidad;
|
||||
|
||||
if (!archivo.fail()) { carga = true; }
|
||||
|
||||
return carga;
|
||||
}
|
||||
|
||||
void mostrar(tItem& item) {
|
||||
cout << right << setw(15) << item.id
|
||||
<< setw(2) << "-" << setw(2)
|
||||
<< setw(25) << item.nombre
|
||||
<< setw(5) << "(" << item.cantidad << ")" << endl;
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
#ifndef _ITEMPEDIDO
|
||||
#define _ITEMPEDIDO
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
|
||||
//Constantes:
|
||||
|
||||
|
||||
//Tipos:
|
||||
typedef struct tItem {
|
||||
std::string id, nombre;
|
||||
int cantidad;
|
||||
};
|
||||
|
||||
//Funciones:
|
||||
bool cargar(tItem& item, std::ifstream& archivo);
|
||||
void mostrar(tItem& item);
|
||||
|
||||
|
||||
#endif // !_ITEMPEDIDO
|
||||
|
@ -0,0 +1,49 @@
|
||||
#include "ListaEnvios.h"
|
||||
using namespace std;
|
||||
|
||||
bool cargar(tListaEnvios& lista) {
|
||||
bool carga = false;
|
||||
ifstream archivo;
|
||||
int numEnvios = 0;
|
||||
|
||||
lista.cont = 0;
|
||||
|
||||
archivo.open("tienda.txt");
|
||||
if (!archivo.is_open()) {
|
||||
cout << "Error al cargar la tienda." << endl;
|
||||
}
|
||||
else {
|
||||
archivo >> numEnvios;
|
||||
while (!archivo.fail() && lista.cont < numEnvios) {
|
||||
lista.envio[lista.cont] = new tEnvio;
|
||||
if (cargar(*lista.envio[lista.cont], archivo)) {
|
||||
lista.cont++;
|
||||
}
|
||||
}
|
||||
carga = true;
|
||||
}
|
||||
archivo.close();
|
||||
|
||||
return carga;
|
||||
}
|
||||
|
||||
void mostrar(tListaEnvios& lista) {
|
||||
for (int i = 0; i < lista.cont; i++){
|
||||
mostrar(*lista.envio[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void ordenarPorCliente(tListaEnvios& lista) {
|
||||
|
||||
}
|
||||
|
||||
void ordenarPorCiudad(tListaEnvios& lista) {
|
||||
|
||||
}
|
||||
|
||||
void destruir(tListaEnvios& lista) {
|
||||
for (int i = 0; i < lista.cont; i++){
|
||||
destruir(*lista.envio[i]);
|
||||
delete lista.envio[i];
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
#ifndef _LISTAENVIOS
|
||||
#define _LISTAENVIOS
|
||||
|
||||
#include "Envio.h"
|
||||
|
||||
//Constantes:
|
||||
const int MAX_ENVIOS = 50;
|
||||
|
||||
//Tipos:
|
||||
typedef struct tListaEnvios {
|
||||
tEnvio *envio[MAX_ENVIOS];
|
||||
int cont;
|
||||
};
|
||||
|
||||
//Funciones:
|
||||
bool cargar(tListaEnvios& lista);
|
||||
void mostrar(tListaEnvios& lista);
|
||||
void ordenarPorCliente(tListaEnvios& lista); //Ordenada por destinatario, de menor a mayor.
|
||||
void ordenarPorCiudad(tListaEnvios& lista); //Ordena por direcci<63>n de envio de mayor a menor.
|
||||
void destruir(tListaEnvios& lista);
|
||||
|
||||
#endif // !_LISTAENVIOS
|
Binary file not shown.
@ -0,0 +1,13 @@
|
||||
#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
|
||||
|
28
Exámenes Resultos (Extraordinaria)/Septiembre2016_1/main.cpp
Normal file
28
Exámenes Resultos (Extraordinaria)/Septiembre2016_1/main.cpp
Normal file
@ -0,0 +1,28 @@
|
||||
//Examen Septiembre 2016 - FP
|
||||
//Grupos: _1
|
||||
//Fernando M<>ndez Torrubiano
|
||||
|
||||
#include "ListaEnvios.h"
|
||||
#include "checkML.h"
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); //Detecta posibles fugas de memoria.
|
||||
system("chcp 1252"); //Castellano
|
||||
system("cls");
|
||||
|
||||
tListaEnvios envios;
|
||||
|
||||
if (cargar(envios)) {
|
||||
mostrar(envios);
|
||||
//
|
||||
}
|
||||
else {
|
||||
cout << "FIN DEL PROGRAMA." << endl;
|
||||
}
|
||||
system("PAUSE");
|
||||
|
||||
destruir(envios);
|
||||
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
3
|
||||
Juan
|
||||
Madrid
|
||||
3
|
||||
mouse
|
||||
El mejor mouse
|
||||
2
|
||||
pc
|
||||
El mejor pc
|
||||
1
|
||||
cable
|
||||
Los mejores cables
|
||||
4
|
||||
Maria
|
||||
Seattle
|
||||
2
|
||||
bici
|
||||
Gran bicicleta
|
||||
1
|
||||
rueda
|
||||
Ruedas estupendas
|
||||
2
|
||||
Luis
|
||||
Madrid
|
||||
2
|
||||
cuchara
|
||||
Cuchara para comer
|
||||
6
|
||||
tenedor
|
||||
Tenedores para comer
|
||||
6
|
Reference in New Issue
Block a user