Add files via upload
This commit is contained in:
@ -0,0 +1,52 @@
|
||||
#include "Departamentos.h"
|
||||
using namespace std;
|
||||
|
||||
void inicializar(tDepartamento& departamento, std::string& id) {
|
||||
departamento.cont = 0;
|
||||
departamento.id = id;
|
||||
departamento.empleado = new tEmpleado[MAX_EMPLEADOS];
|
||||
}
|
||||
|
||||
int buscarEmpleado(tDepartamento& departamento, std::string& nif) {
|
||||
int pos = departamento.cont - 1;
|
||||
bool encontrado = false;
|
||||
|
||||
while (!encontrado && pos >= 0) {
|
||||
if (departamento.empleado[pos].puntero->nif == nif) {
|
||||
encontrado = true;
|
||||
}
|
||||
else {
|
||||
pos--;
|
||||
}
|
||||
}
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
bool insertarEmpleado(tListaContratos& contratos, tDepartamento& departamento, int& pos) {
|
||||
bool insertado = false;
|
||||
int i = buscarEmpleado(departamento, contratos.contrato[pos]->nif);
|
||||
|
||||
if (i == -1) {
|
||||
departamento.empleado[departamento.cont].puntero = contratos.contrato[pos];
|
||||
departamento.cont++;
|
||||
departamento.empleado->numero = departamento.cont;
|
||||
insertado = true;
|
||||
}
|
||||
|
||||
return insertado;
|
||||
}
|
||||
|
||||
void mostrarEmpleado(tEmpleado& empleado, int& i) {
|
||||
cout << right << setw(3) << i+1 << ".-" << setw(25) << empleado.puntero->nombre << setw(10) << "num.: " << empleado.numero << endl;
|
||||
}
|
||||
|
||||
void mostrarDepartamentos(tDepartamento& departamento) {
|
||||
for (int i = 0; i < departamento.cont; i++){
|
||||
mostrarEmpleado(departamento.empleado[i], i);
|
||||
}
|
||||
}
|
||||
|
||||
void liberar(tDepartamento& departamento) {
|
||||
delete[] departamento.empleado;
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
#ifndef H_DEPARTAMENTOS_H
|
||||
#define H_DEPAETAMENTOS_H
|
||||
|
||||
#include "ListaContratos.h"
|
||||
|
||||
//Constantes:
|
||||
const int MAX_EMPLEADOS = 50;
|
||||
|
||||
//Tipos:
|
||||
typedef struct tEmpleado {
|
||||
tContrato *puntero;
|
||||
int numero;
|
||||
};
|
||||
|
||||
typedef struct tDepartamento {
|
||||
tEmpleado *empleado;
|
||||
int cont;
|
||||
std::string id;
|
||||
};
|
||||
|
||||
//Funciones:
|
||||
void inicializar(tDepartamento& departamento, std::string& id);
|
||||
int buscarEmpleado(tDepartamento& departamento, std::string& nif);
|
||||
bool insertarEmpleado(tListaContratos& contratos, tDepartamento& departamento, int&);
|
||||
void mostrarEmpleado(tEmpleado& empleado, int& pos);
|
||||
void mostrarDepartamentos(tDepartamento& departamento);
|
||||
void liberar(tDepartamento& departamento);
|
||||
|
||||
#endif // !H_DEPARTAMENTOS_H
|
||||
|
Binary file not shown.
@ -0,0 +1,103 @@
|
||||
#include "ListaContratos.h"
|
||||
using namespace std;
|
||||
|
||||
//Funciones auxiliares:
|
||||
bool buscar(tListaContratos& lista, string& nif, int& ini, int& fin, int& pos);
|
||||
|
||||
bool cargarContratos(tListaContratos& lista, tPrioridades& prioridades) {
|
||||
bool carga = false;
|
||||
ifstream archivo;
|
||||
int numContratos = 0;
|
||||
|
||||
lista.cont = 0;
|
||||
|
||||
archivo.open("contratos.txt");
|
||||
if (!archivo.is_open()) {
|
||||
cout << "Error al cargar los contratos." << endl;
|
||||
}
|
||||
else {
|
||||
archivo >> numContratos;
|
||||
archivo.ignore();
|
||||
while(!archivo.fail() && lista.cont < numContratos){
|
||||
lista.contrato[lista.cont] = new tContrato;
|
||||
if (insertarContrato(lista, prioridades, archivo)) {
|
||||
lista.cont++;
|
||||
}
|
||||
}
|
||||
carga = true;
|
||||
}
|
||||
archivo.close();
|
||||
|
||||
return carga;
|
||||
}
|
||||
|
||||
bool insertarContrato(tListaContratos& lista, tPrioridades& prioridades, ifstream& archivo) {
|
||||
bool insertado = false;
|
||||
int ini = 0, fin = lista.cont - 1, pos = 0, numTareas = 0;
|
||||
|
||||
if (!buscar(lista, lista.contrato[lista.cont]->nif, ini, fin, pos)) {
|
||||
getline(archivo, lista.contrato[lista.cont]->nombre);
|
||||
archivo >> lista.contrato[lista.cont]->nif;
|
||||
archivo >> lista.contrato[lista.cont]->sueldo;
|
||||
archivo >> numTareas;
|
||||
lista.contrato[lista.cont]->lista.cont = 0;
|
||||
while (!archivo.fail() && lista.contrato[lista.cont]->lista.cont < numTareas) {
|
||||
if (cargarTareas(lista.contrato[lista.cont]->lista, prioridades, archivo)) {
|
||||
lista.contrato[lista.cont]->lista.cont++;
|
||||
}
|
||||
}
|
||||
insertado = true;
|
||||
}
|
||||
|
||||
return insertado;
|
||||
}
|
||||
|
||||
//
|
||||
bool buscar(tListaContratos& lista, string& nif, int& ini, int& fin, int& pos) {
|
||||
bool encontrado = false;
|
||||
|
||||
if (ini <= fin) {
|
||||
pos = (ini + fin) / 2;
|
||||
if (nif < lista.contrato[pos]->nif) {
|
||||
fin = pos - 1;
|
||||
encontrado = buscar(lista, lista.contrato[lista.cont]->nif, ini, fin, pos);;
|
||||
}
|
||||
else if (lista.contrato[pos]->nif < nif) {
|
||||
ini = pos + 1;
|
||||
encontrado = buscar(lista, lista.contrato[lista.cont]->nif, ini, fin, pos);;
|
||||
}
|
||||
else {
|
||||
encontrado = true;
|
||||
}
|
||||
}
|
||||
|
||||
return encontrado;
|
||||
}
|
||||
//
|
||||
|
||||
void mostrarContratos(tListaContratos& lista) {
|
||||
for (int i = 0; i < lista.cont; i++){
|
||||
cout << right << setw(3) << i + 1 << ".-"
|
||||
<< setw(30) << lista.contrato[i]->nombre
|
||||
<< setw(15) << lista.contrato[i]->nif
|
||||
<< setw(5) << "(" << lista.contrato[i]->lista.cont << ")"
|
||||
<< setw(10) << fixed << setprecision(2) << lista.contrato[i]->sueldo << endl;
|
||||
}
|
||||
}
|
||||
|
||||
int seleccionarContratos(tListaContratos& lista) {
|
||||
int linea = 0;
|
||||
|
||||
mostrarContratos(lista);
|
||||
cout << endl << "Introduzca el n<>mero la linea del contrato que desea seleccionar: ";
|
||||
cin >> linea;
|
||||
linea--;
|
||||
|
||||
return linea;
|
||||
}
|
||||
|
||||
void liberar(tListaContratos& lista) {
|
||||
for (int i = 0; i < lista.cont; i++){
|
||||
delete lista.contrato[i];
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
#ifndef H_LISTACONTRATOS_H
|
||||
#define H_LISTACONTRATOS_H
|
||||
|
||||
#include"ListaTareas.h"
|
||||
|
||||
//Constantes:
|
||||
const int MAX_CONTRATOS = 100;
|
||||
|
||||
//Tipos:
|
||||
typedef struct tContrato {
|
||||
std::string nombre, nif;
|
||||
tListaTareas lista;
|
||||
double sueldo;
|
||||
};
|
||||
|
||||
typedef struct tListaContratos {
|
||||
tContrato *contrato[MAX_CONTRATOS]; //Ordenados por NIF.
|
||||
int cont;
|
||||
};
|
||||
|
||||
//Funciones:
|
||||
bool cargarContratos(tListaContratos& lista, tPrioridades& prioridades);
|
||||
bool insertarContrato(tListaContratos& lista, tPrioridades& prioridades, std::ifstream& archivo);
|
||||
void mostrarContratos(tListaContratos& lista);
|
||||
int seleccionarContratos(tListaContratos& lista);
|
||||
void liberar(tListaContratos& lista);
|
||||
|
||||
|
||||
#endif // !H_LISTACONTRATOS_H
|
@ -0,0 +1,61 @@
|
||||
#include "ListaTareas.h"
|
||||
using namespace std;
|
||||
|
||||
bool cargarPrioridades(tPrioridades& prioridad) {
|
||||
bool carga = false;
|
||||
ifstream archivo;
|
||||
|
||||
archivo.open("prioridades.txt");
|
||||
if (!archivo.is_open()) {
|
||||
cout << "Error al cargar las prioridades." << endl;
|
||||
}
|
||||
else {
|
||||
for (int i = 0; i < ANIOS; i++) {
|
||||
for (int j = 0; j < MAX_TIPOS; j++){
|
||||
archivo >> prioridad[i][j];
|
||||
}
|
||||
}
|
||||
carga = true;
|
||||
}
|
||||
archivo.close();
|
||||
|
||||
return carga;
|
||||
}
|
||||
|
||||
bool cargarTareas(tListaTareas& lista, tPrioridades& prioridades, ifstream& archivo) {
|
||||
bool carga = false;
|
||||
|
||||
if (!archivo.fail()) {
|
||||
archivo >> lista.tarea[lista.cont].codigo;
|
||||
archivo.ignore();
|
||||
getline(archivo, lista.tarea[lista.cont].descripcion);
|
||||
lista.tarea[lista.cont].tiempo = calcularTiempo(lista, prioridades);
|
||||
carga = true;
|
||||
}
|
||||
|
||||
return carga;
|
||||
}
|
||||
|
||||
int calcularTiempo(tListaTareas& lista, tPrioridades& prioridades) {
|
||||
int tiempo = 0;
|
||||
|
||||
for (int i = 0; i < ANIOS; i++){
|
||||
for (int j = 0; j < MAX_TIPOS; j++){
|
||||
tiempo += prioridades[i][j];
|
||||
}
|
||||
}
|
||||
tiempo /= (ANIOS*MAX_TIPOS);
|
||||
tiempo *= 20;
|
||||
|
||||
floor(tiempo);
|
||||
|
||||
return tiempo;
|
||||
}
|
||||
|
||||
void mostrarTareas(tListaTareas& lista) {
|
||||
for (int i = 0; i < lista.cont; i++){
|
||||
cout << right << setw(2) << lista.tarea[i].codigo
|
||||
<< setw(40) << lista.tarea[i].descripcion
|
||||
<< setw(5) << lista.tarea[i].tiempo << endl;
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
#ifndef H_LISTATAREAS_H
|
||||
#define H_LISTATAREAS_H
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
|
||||
//Constantes:
|
||||
const int MAX_TAREAS = 15;
|
||||
const int MAX_TIPOS = 7;
|
||||
const int ANIOS = 5;
|
||||
|
||||
//Tipos:
|
||||
typedef int tPrioridades[ANIOS][MAX_TIPOS];
|
||||
|
||||
typedef struct tTarea {
|
||||
int codigo;
|
||||
std::string descripcion;
|
||||
int tiempo;
|
||||
};
|
||||
|
||||
typedef struct tListaTareas {
|
||||
tTarea tarea[MAX_TAREAS];
|
||||
int cont;
|
||||
};
|
||||
|
||||
//Funciones:
|
||||
bool cargarPrioridades(tPrioridades& prioridad);
|
||||
bool cargarTareas(tListaTareas& lista, tPrioridades&, std::ifstream&);
|
||||
int calcularTiempo(tListaTareas& lista, tPrioridades&);
|
||||
void mostrarTareas(tListaTareas& lista);
|
||||
|
||||
#endif // !H_LISTATAREAS_H
|
@ -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__ , __LINE__ )
|
||||
#define new DBG_NEW
|
||||
#endif
|
||||
#endif
|
@ -0,0 +1,23 @@
|
||||
3
|
||||
Sanchez Gomez, Juan
|
||||
12345678A
|
||||
1700
|
||||
2
|
||||
1
|
||||
Docencia en Ingenieria del Software
|
||||
7
|
||||
Publicacion de articulos y conferencias
|
||||
Martin Vazquez, Alberto
|
||||
87654321A
|
||||
1600
|
||||
1
|
||||
7
|
||||
Publicacion de articulos y conferencias
|
||||
Gonzalez Fernandez, Patricia
|
||||
32323232B
|
||||
1700
|
||||
2
|
||||
2
|
||||
Docencia en Ingenieria de Computadores
|
||||
7
|
||||
Publicacion de articulos y conferencias
|
94
Exámenes Resueltos (Segundo Semestre)/Junio2018CEG/main.cpp
Normal file
94
Exámenes Resueltos (Segundo Semestre)/Junio2018CEG/main.cpp
Normal file
@ -0,0 +1,94 @@
|
||||
//Examen Junio 2018 - FP
|
||||
//Grupos C, E y G.
|
||||
//Fernando M<>ndez Torrubiano
|
||||
|
||||
#include "Departamentos.h"
|
||||
#include "checkML.h"
|
||||
using namespace std;
|
||||
|
||||
int menu();
|
||||
|
||||
int main() {
|
||||
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); //Muestra fugas de memoria.
|
||||
system("chcp 1252"); //Castellano.
|
||||
system("cls");
|
||||
|
||||
tDepartamento dpto;
|
||||
tListaContratos lista;
|
||||
tPrioridades prioridades;
|
||||
tEmpleado empleado;
|
||||
string id, nif;
|
||||
int opcion, pos = -1;
|
||||
|
||||
|
||||
if (cargarPrioridades(prioridades)) {
|
||||
if (cargarContratos(lista, prioridades)) {
|
||||
cout << "Identificador del departamento: ";
|
||||
cin >> id;
|
||||
cout << endl;
|
||||
inicializar(dpto, id);
|
||||
do {
|
||||
opcion = menu();
|
||||
switch (opcion){
|
||||
case 1:
|
||||
pos = seleccionarContratos(lista);
|
||||
if (!insertarEmpleado(lista, dpto, pos)) {
|
||||
cout << "Error al insertar el empleado." << endl;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
cout << "NIF del emplieado: ";
|
||||
cin >> nif;
|
||||
cout << endl;
|
||||
pos = buscarEmpleado(dpto, nif);
|
||||
if (pos != -1) {
|
||||
mostrarTareas(dpto.empleado[pos].puntero->lista);
|
||||
}
|
||||
else {
|
||||
cout << "El empleado no est<73> en el departamento." << endl;
|
||||
}
|
||||
cout << endl;
|
||||
break;
|
||||
case 3:
|
||||
if (dpto.cont != 0) {
|
||||
cout << endl << "Los empleados del departamento '" << dpto.id << "' son:" << endl;
|
||||
mostrarDepartamentos(dpto);
|
||||
}
|
||||
else {
|
||||
cout << "No hay empleados." << endl;
|
||||
}
|
||||
cout << endl;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} while (opcion != 0);
|
||||
|
||||
liberar(lista);
|
||||
liberar(dpto);
|
||||
}
|
||||
else {
|
||||
cout << "Error al cargar la lista de contratos." << endl;
|
||||
}
|
||||
}
|
||||
else {
|
||||
cout << "Error al cargar las prioridades." << endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int menu() {
|
||||
int opc = -1;
|
||||
|
||||
cout << "1.-Insertar empleado en nuevo dpto." << endl;
|
||||
cout << "2.-Mostrar tareas de un empleado." << endl;
|
||||
cout << "3.-Mostrar los empleados actuales de un dpto." << endl;
|
||||
cout << "0.-SALIR." << endl;
|
||||
do {
|
||||
cout << "Introduzca una opc: ";
|
||||
cin >> opc;
|
||||
} while (opc < 0 || opc > 3);
|
||||
|
||||
return opc;
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
5 5 4 3 1 2 4
|
||||
5 5 4 4 2 1 3
|
||||
4 5 3 3 3 2 3
|
||||
5 4 3 2 2 3 3
|
||||
4 5 4 3 3 2 4
|
Reference in New Issue
Block a user