Exámenes Resueltos FP - Primer Semestre
Para uso exclusivo con fines de estudio. Se prohíbe su uso para entregas calificables y/o uso comercial.
This commit is contained in:
		| @@ -0,0 +1,289 @@ | ||||
| //Examen Febrero 2011 - Grupos A, B y C. | ||||
| //Fernando M<>ndez Torrubiano | ||||
|  | ||||
| #include <iostream> | ||||
| #include <string> | ||||
| #include <fstream> | ||||
| #include <iomanip> | ||||
| using namespace std; | ||||
|  | ||||
|  | ||||
| //Constantes: | ||||
| /*EJERCICIO 1*/ | ||||
| const int MAX_NUM = 1000; | ||||
| const int NUM_CIFRAS = 5; | ||||
| /*EJERCICIO 2*/ | ||||
| const int NUM_PIEZAS = 16 * 2; | ||||
| const int NUM_JUGADORES = 2; | ||||
| const int DIMENSIONES = 8; | ||||
|  | ||||
| //Tipos: | ||||
| /*EJERCICIO 1*/ | ||||
| typedef struct tNumero { | ||||
| 	int numero; | ||||
| 	int contadorCifra; | ||||
| }; | ||||
| typedef tNumero tNumeros[MAX_NUM]; | ||||
| typedef struct tListaNumeros { | ||||
| 	tNumeros numeros; | ||||
| 	int contador; | ||||
| }; | ||||
| /*EJERCICIO 2*/ | ||||
| typedef enum tPieza { vacia, peon, torre, caballo, alfil, reina, rey }; | ||||
| typedef enum tColor { blanca, negra }; | ||||
| typedef struct tCelda { | ||||
| 	tPieza pieza; | ||||
| 	tColor color; | ||||
| }; | ||||
| typedef tCelda tTablero[DIMENSIONES][DIMENSIONES]; | ||||
| typedef struct tPartida { | ||||
| 	tTablero tablero; | ||||
| 	int contador; | ||||
| }; | ||||
|  | ||||
| //Funciones: | ||||
| void ejecutarMenu(tListaNumeros&, tPartida&); | ||||
| int menu(); | ||||
| /*EJERCICIO 1*/ | ||||
| void inicializa(tListaNumeros&); | ||||
| bool cargar(tListaNumeros&); | ||||
| void procesar(tListaNumeros&); | ||||
| bool guardar(tListaNumeros&); | ||||
| /*EJERCICIO 2*/ | ||||
| void iniciaTablero(tPartida&); | ||||
| bool cargar(tPartida&); | ||||
| void colocar(tPartida&, const char&, const char&, const int&, const int&); | ||||
| void posicion(tPartida&); | ||||
| void mostrarCasilla(tPartida&, const int&, const int&); | ||||
|  | ||||
|  | ||||
|  | ||||
| int main() { | ||||
| 	tListaNumeros listaNum; | ||||
| 	tPartida partida; | ||||
| 	 | ||||
| 	ejecutarMenu(listaNum, partida); | ||||
|  | ||||
| 	return 0; | ||||
| } | ||||
|  | ||||
| void ejecutarMenu(tListaNumeros& listaNum, tPartida& partida) { | ||||
| 	int opc = 1; | ||||
|  | ||||
| 	while (opc != 0) { | ||||
| 		opc = menu(); | ||||
| 		switch (opc){ | ||||
| 		case 0: break; | ||||
| 		case 1: | ||||
| 			if (cargar(listaNum)) { | ||||
| 				cout << "Cargado correctamente." << endl; | ||||
| 				if (guardar(listaNum)) { | ||||
| 					cout << "Guardado correctamente." << endl; | ||||
| 				} | ||||
| 				else { | ||||
| 					cout << "Vauelva a intentarlo." << endl; | ||||
| 				} | ||||
| 			} | ||||
| 			else { | ||||
| 				cout << "FIN DEL PROGRAMA." << endl; | ||||
| 			} | ||||
| 			system("PAUSE"); | ||||
| 			break; | ||||
| 		case 2: | ||||
| 			if (cargar(partida)) { | ||||
| 				posicion(partida); | ||||
| 			} | ||||
| 			break; | ||||
| 		default: | ||||
| 			break; | ||||
| 		} | ||||
| 		system("cls"); | ||||
| 	} | ||||
| } | ||||
|  | ||||
| int menu() { | ||||
| 	int opc = 0; | ||||
|  | ||||
| 	cout << setw(35) << setfill('=') << "MENU" << setw(35) << "\n" << setfill(char(0)); | ||||
| 	cout << "1.-Contar numero de cifras de los numeros del archivo 'entrada.txt'." << endl; | ||||
| 	cout << "2.-Partida de ajedrez." << endl; | ||||
| 	cout << "0.-Salir." << endl; | ||||
| 	cout << setw(70) << setfill('=') << "\n" << setfill(char(0)); | ||||
|  | ||||
| 	do { | ||||
| 		cout << "Introduzca una opcion: "; | ||||
| 		cin >> opc; | ||||
| 	} while (opc < 0 || opc > 2); | ||||
|  | ||||
| 	return opc; | ||||
| } | ||||
|  | ||||
| /*EJERCICIO 1*/ | ||||
| void inicializa(tListaNumeros& listaNum) { | ||||
| 	listaNum.contador = 0; | ||||
|  | ||||
| 	for (int i = 0; i < MAX_NUM; i++) { | ||||
| 		listaNum.numeros[i].numero = 0; | ||||
| 		listaNum.numeros[i].contadorCifra = 1; | ||||
| 	} | ||||
| } | ||||
|  | ||||
| bool cargar(tListaNumeros& listaNum) { | ||||
| 	bool carga = false; | ||||
| 	ifstream archivo; | ||||
|  | ||||
| 	inicializa(listaNum); | ||||
| 	archivo.open("entrada.txt"); | ||||
| 	if (!archivo.is_open()) { | ||||
| 		cout << "Error al cargar el archivo." << endl; | ||||
| 		carga = false; | ||||
| 	} | ||||
| 	else{ | ||||
| 		while ((!archivo.eof()) && (listaNum.contador < MAX_NUM)) { | ||||
| 			archivo >> listaNum.numeros[listaNum.contador].numero; | ||||
| 			procesar(listaNum); | ||||
| 			listaNum.contador++; | ||||
| 		} | ||||
| 		carga = true; | ||||
| 	} | ||||
| 	archivo.close(); | ||||
|  | ||||
| 	return carga; | ||||
| } | ||||
|  | ||||
| void procesar(tListaNumeros& listaNum) { | ||||
| 	int aux = 0; | ||||
|  | ||||
| 	aux = listaNum.numeros[listaNum.contador].numero; | ||||
| 	while (aux > 10) { | ||||
| 		aux /= 10; | ||||
| 		listaNum.numeros[listaNum.contador].contadorCifra++; | ||||
| 	} | ||||
| } | ||||
|  | ||||
| bool guardar(tListaNumeros& listaNum) { | ||||
| 	bool guardado = false; | ||||
| 	ofstream archivo; | ||||
|  | ||||
| 	archivo.open("salida.txt"); | ||||
| 	if (!archivo.is_open()) { | ||||
| 		cout << "Error al guardar." << endl; | ||||
| 		guardado = false; | ||||
| 	} | ||||
| 	else { | ||||
| 		archivo << setw(6) << right << "NUMERO" << setw(22) << "NUMERO DE CIFRAS" << endl; | ||||
| 		archivo << setw(30) << setfill('=') << "\n" << setfill(char(0)); | ||||
| 		for (int i = 0; i < listaNum.contador; i++){ | ||||
| 			archivo << setw(5) << right << listaNum.numeros[i].numero << setw(15) << setfill('.') << listaNum.numeros[i].contadorCifra << setfill(char(0)) << endl; | ||||
| 		} | ||||
| 		guardado = true; | ||||
| 	} | ||||
| 	archivo.close(); | ||||
|  | ||||
| 	return guardado; | ||||
| } | ||||
|  | ||||
|  | ||||
|  | ||||
| /*EJERCICIO 2*/ | ||||
| void iniciaTablero(tPartida& partida) { | ||||
| 	partida.contador = 0; | ||||
| 	for (int i = 0; i < DIMENSIONES; i++){ | ||||
| 		for (int j = 0; j < DIMENSIONES; j++){ | ||||
| 			partida.tablero[i][j].pieza = vacia; | ||||
| 			partida.tablero[i][j].color = blanca; | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
| bool cargar(tPartida& partida) { | ||||
| 	bool carga = false; | ||||
| 	ifstream archivo; | ||||
| 	char tipo, color; | ||||
| 	int fila, columna; | ||||
|  | ||||
| 	iniciaTablero(partida); | ||||
| 	archivo.open("tablero.txt"); | ||||
| 	if (!archivo.is_open()) { | ||||
| 		cout << "Error al cargar." << endl; | ||||
| 		carga = false; | ||||
| 	} | ||||
| 	else { | ||||
| 		while ((!archivo.eof()) && (partida.contador < NUM_PIEZAS)) { | ||||
| 			archivo >> tipo; | ||||
| 			archivo >> color; | ||||
| 			archivo >> fila; | ||||
| 			archivo >> columna; | ||||
| 			colocar(partida, tipo, color, fila, columna); | ||||
| 			partida.contador++; | ||||
| 		} | ||||
| 		carga = true; | ||||
| 	} | ||||
| 	archivo.close(); | ||||
|  | ||||
| 	return carga; | ||||
| } | ||||
|  | ||||
| void colocar(tPartida& partida, const char& tipo, const char& color, const int& fila, const int& columna) { | ||||
| 	 | ||||
| 	if (color == 'B') { | ||||
| 		partida.tablero[fila][columna].color = blanca; | ||||
| 	} | ||||
| 	else { | ||||
| 		partida.tablero[fila][columna].color = negra; | ||||
| 	} | ||||
| 	switch (tipo){ | ||||
| 	case 'P': partida.tablero[fila][columna].pieza = peon; break; | ||||
| 	case 'T': partida.tablero[fila][columna].pieza = torre; break; | ||||
| 	case 'A': partida.tablero[fila][columna].pieza = alfil; break; | ||||
| 	case 'C': partida.tablero[fila][columna].pieza = caballo; break; | ||||
| 	case 'Q': partida.tablero[fila][columna].pieza = reina; break; | ||||
| 	case 'R': partida.tablero[fila][columna].pieza = rey; break; | ||||
| 	default: partida.tablero[fila][columna].pieza = vacia; | ||||
| 		break; | ||||
| 	} | ||||
| } | ||||
|  | ||||
| void posicion(tPartida& partida) { | ||||
| 	char continuar = 'N'; | ||||
| 	int fila = 0, columna = 0; | ||||
|  | ||||
| 	do { | ||||
| 		do { | ||||
| 			cout << "Introduzca una fila: "; | ||||
| 			cin >> fila; | ||||
| 		} while (fila < 0 || fila >= DIMENSIONES); | ||||
| 		do { | ||||
| 			cout << "Introduzca una columna: "; | ||||
| 			cin >> columna; | ||||
| 		} while (columna < 0 || columna >= DIMENSIONES); | ||||
| 		 | ||||
| 		mostrarCasilla(partida, fila, columna); | ||||
|  | ||||
| 		cout << "Quiere continuar (S/n)?"; | ||||
| 		cin >> continuar; | ||||
| 	} while (continuar == 'S' || continuar == 's'); | ||||
| } | ||||
|  | ||||
| void mostrarCasilla(tPartida& partida, const int& fila, const int& columna) { | ||||
|  | ||||
| 	switch (partida.tablero[fila][columna].pieza){ | ||||
| 	case peon: cout << "Figura: PEON  "; break; | ||||
| 	case torre: cout << "Figura: TORRE  "; break; | ||||
| 	case alfil: cout << "Figura: ALFIL  "; break; | ||||
| 	case caballo: cout << "Figura: CABALLO  "; break; | ||||
| 	case reina: cout << "Figura: REINA  "; break; | ||||
| 	case rey: cout << "Figura: REY  "; break; | ||||
| 	default: | ||||
| 		cout << "Figura: NINGUNA" << endl; | ||||
| 		break; | ||||
| 	} | ||||
| 	 | ||||
| 	switch (partida.tablero[fila][columna].color){ | ||||
| 	case blanca: cout << "Color: BLANCA" << endl; break; | ||||
| 	case negra: cout << "Color: NEGRA" << endl; break; | ||||
| 	default: | ||||
| 		break; | ||||
| 	} | ||||
|  | ||||
| } | ||||
										
											Binary file not shown.
										
									
								
							| @@ -0,0 +1,93 @@ | ||||
| 12345 | ||||
| 1 | ||||
| 2 | ||||
| 3 | ||||
| 4 | ||||
| 5 | ||||
| 2134 | ||||
| 65 | ||||
| 789 | ||||
| 44 | ||||
| 432 | ||||
| 123 | ||||
| 3 | ||||
| 561 | ||||
| 32 | ||||
| 24567 | ||||
| 46 | ||||
| 53767 | ||||
| 7655 | ||||
| 12347 | ||||
| 98765 | ||||
| 9 | ||||
| 788 | ||||
| 654 | ||||
| 12 | ||||
| 134 | ||||
| 5658 | ||||
| 542 | ||||
| 456 | ||||
| 876 | ||||
| 3 | ||||
| 56 | ||||
| 32333 | ||||
| 3233 | ||||
| 323 | ||||
| 32 | ||||
| 3 | ||||
| 12345 | ||||
| 1234 | ||||
| 123 | ||||
| 12 | ||||
| 1 | ||||
| 12 | ||||
| 123 | ||||
| 1234 | ||||
| 12345 | ||||
| 9 | ||||
| 98 | ||||
| 987 | ||||
| 9876 | ||||
| 98765 | ||||
| 9876 | ||||
| 987 | ||||
| 98 | ||||
| 9 | ||||
| 5567 | ||||
| 54664 | ||||
| 5 | ||||
| 75 | ||||
| 342 | ||||
| 19 | ||||
| 22 | ||||
| 23 | ||||
| 20 | ||||
| 75 | ||||
| 57 | ||||
| 10000 | ||||
| 1000 | ||||
| 100 | ||||
| 10 | ||||
| 1 | ||||
| 0 | ||||
| 96 | ||||
| 99 | ||||
| 1996 | ||||
| 1999 | ||||
| 98 | ||||
| 35 | ||||
| 9 | ||||
| 8 | ||||
| 3 | ||||
| 5 | ||||
| 7654 | ||||
| 743 | ||||
| 5 | ||||
| 32526 | ||||
| 2 | ||||
| 5 | ||||
| 5676 | ||||
| 23 | ||||
| 687 | ||||
| 54367 | ||||
| 9 | ||||
| @@ -0,0 +1,32 @@ | ||||
| P B 0 4 | ||||
| P B 1 6 | ||||
| P B 4 3 | ||||
| P B 2 7 | ||||
| P B 6 5 | ||||
| P B 5 4 | ||||
| P B 2 0 | ||||
| P B 0 2 | ||||
| R B 1 1 | ||||
| Q B 7 3 | ||||
| A B 0 0 | ||||
| A B 0 3 | ||||
| C B 4 4 | ||||
| C B 1 5 | ||||
| T B 3 2 | ||||
| T B 6 6 | ||||
| P N 4 2 | ||||
| P N 7 5 | ||||
| P N 7 7 | ||||
| P N 4 1 | ||||
| P N 3 1 | ||||
| P N 6 1 | ||||
| P N 2 2 | ||||
| P N 6 0 | ||||
| R N 3 0 | ||||
| Q N 5 0 | ||||
| A N 0 7 | ||||
| A N 4 5 | ||||
| C N 5 3 | ||||
| C N 3 7 | ||||
| T N 3 6 | ||||
| T N 4 7 | ||||
| @@ -0,0 +1,205 @@ | ||||
| //Ex<45>men Febrero 2012 - Grupos A, B, D y G. | ||||
| //Fernando M<>ndez Torrrubiano. | ||||
|  | ||||
| #include <iostream> | ||||
| #include <string> | ||||
| #include <fstream> | ||||
| #include <iomanip> | ||||
| using namespace std; | ||||
|  | ||||
|  | ||||
| //Constantes: | ||||
| const int NUMEROS = 50; | ||||
| const int N = 5; | ||||
|  | ||||
| //Tipos: | ||||
| typedef int tNumeros[NUMEROS]; | ||||
| typedef struct tSecuencia { | ||||
| 	tNumeros numero; | ||||
| 	int contador; | ||||
| }; | ||||
|  | ||||
| //Funciones: | ||||
| void ejecutarMenu(); | ||||
| int menu(); | ||||
| void inicializa(tSecuencia&); | ||||
| void getSecuencia(tSecuencia&, const int&); | ||||
| double calcularEx(const int&, const int&); | ||||
| int factorial(const int&); | ||||
| bool guardar(tSecuencia&); | ||||
| bool esCapicua(tSecuencia&, int&); | ||||
| bool inverso(const int&); | ||||
| void guardarAnteriores(tSecuencia, const int&); | ||||
|  | ||||
|  | ||||
|  | ||||
| int main() { | ||||
|  | ||||
| 	ejecutarMenu(); | ||||
|  | ||||
| 	return 0; | ||||
| } | ||||
|  | ||||
| void ejecutarMenu() { | ||||
| 	tSecuencia secuencia; | ||||
| 	int opc = 1, n = N, i = 0; | ||||
|  | ||||
| 	while (opc != 0){ | ||||
| 		opc = menu(); | ||||
| 		switch (opc){ | ||||
| 		case 0: break; | ||||
| 		case 1:  | ||||
| 			getSecuencia(secuencia, n);  | ||||
| 			n += 2;  | ||||
| 			system("PAUSE");  | ||||
| 			break; | ||||
| 		case 2:  | ||||
| 			if (guardar(secuencia)) { | ||||
| 				if (esCapicua(secuencia, i)) { | ||||
| 					cout << "El numero " << secuencia.numero[i] << " de la posicion " << i + 1<< " es capicua." << endl; | ||||
| 					guardarAnteriores(secuencia, i); | ||||
| 				} | ||||
| 				else { | ||||
| 					cout << "No se ha encontrado ningun numero capicua." << endl; | ||||
| 				} | ||||
| 			} | ||||
| 			else { | ||||
| 				cout << "No se han podido guardar los numeros anteriores." << endl; | ||||
| 			} | ||||
| 				system("PAUSE");  | ||||
| 				break; | ||||
| 		default: | ||||
| 			break; | ||||
| 		} | ||||
| 		system("cls"); | ||||
| 	} | ||||
| } | ||||
|  | ||||
| int menu() { | ||||
| 	int opc = 0; | ||||
|  | ||||
| 	cout << setw(25) << setfill('=') << "MENU" << setw(25) << "\n" << setfill(char(0)); | ||||
| 	cout << "1.-Calculos de 'e' elevado a 'x'" << endl; | ||||
| 	cout << "2.-Detecta capicua" << endl; | ||||
| 	cout << "0.-Salir" << endl; | ||||
| 	cout << setw(50) << setfill('=') << "\n" << setfill(char(0)); | ||||
|  | ||||
| 	do { | ||||
| 		cout << "Introduzca una opcion: "; | ||||
| 		cin >> opc; | ||||
| 	} while (opc < 0 || opc > 2); | ||||
|  | ||||
| 	return opc; | ||||
| } | ||||
|  | ||||
| void inicializa(tSecuencia& secuencia) { | ||||
| 	secuencia.contador = 0; | ||||
| 	for (int i = 0; i < NUMEROS; i++){ | ||||
| 		secuencia.numero[i] = 0; | ||||
| 	} | ||||
| } | ||||
|  | ||||
| void getSecuencia(tSecuencia& secuencia, const int& n) { | ||||
| 	inicializa(secuencia); | ||||
|  | ||||
| 	do { | ||||
| 		cout << "Introduzca un numero (-1 para terminar): "; | ||||
| 		cin >> secuencia.numero[secuencia.contador]; | ||||
| 		if (secuencia.numero[secuencia.contador] >= 0) { | ||||
| 			secuencia.contador++; | ||||
| 		} | ||||
| 	} while ((secuencia.numero[secuencia.contador] != -1)); | ||||
|  | ||||
| 	cout << endl; | ||||
| 	for (int i = 0; i < secuencia.contador; i++){ | ||||
| 		cout << "'e' elevado a " << secuencia.numero[i] << " da como resultado: " << fixed << setprecision(2) << calcularEx(secuencia.numero[i], n) << endl; | ||||
| 	} | ||||
| } | ||||
|  | ||||
| double calcularEx(const int& x, const int& n) { | ||||
| 	double eALAx = 0; | ||||
|  | ||||
| 	for (int i = 0; i < n; i++){ | ||||
| 		eALAx += (pow(x, i)) / (factorial(i)); | ||||
| 	} | ||||
|  | ||||
| 	return eALAx; | ||||
| } | ||||
|  | ||||
| int factorial(const int& n) { | ||||
| 	int factorial = 1; | ||||
|  | ||||
| 	if (n == 0) { | ||||
| 		factorial = 1; | ||||
| 	} | ||||
| 	else { | ||||
| 		for (int i = 1; i <= n; i++) { | ||||
| 			factorial *= i; | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return factorial; | ||||
| } | ||||
|  | ||||
| bool guardar(tSecuencia& secuencia) { | ||||
| 	bool guardado = false; | ||||
| 	ofstream archivo; | ||||
|  | ||||
| 	archivo.open("input.txt"); | ||||
| 	if (!archivo.is_open()) { | ||||
| 		cout << "Error al guardar." << endl; | ||||
| 		guardado = false; | ||||
| 	} | ||||
| 	else { | ||||
| 		for (int i = 0; i <= secuencia.contador; i++){ | ||||
| 			archivo << secuencia.numero[i] << endl; | ||||
| 		} | ||||
| 		guardado = true; | ||||
| 	} | ||||
| 	archivo.close(); | ||||
|  | ||||
| 	return guardado; | ||||
| } | ||||
|  | ||||
| bool esCapicua(tSecuencia& secuencia, int& i) { | ||||
| 	bool encontrado = false; | ||||
|  | ||||
| 	while ((!encontrado) && (i < secuencia.contador)) { | ||||
| 		if (inverso(secuencia.numero[i])) { | ||||
| 			encontrado = true; | ||||
| 		} | ||||
| 		else { | ||||
| 			i++; | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return encontrado; | ||||
| } | ||||
|  | ||||
| bool inverso(const int& numero) { | ||||
| 	string num = to_string(numero); | ||||
| 	string aux; | ||||
|  | ||||
| 	if (numero >= 10) { | ||||
| 		for (int i = num.length() - 1; i >= 0; i--) { | ||||
| 			aux += num[i]; | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return (num == aux) ? true : false; | ||||
| } | ||||
|  | ||||
| void guardarAnteriores(tSecuencia secuencia, const int& i) { | ||||
| 	ofstream archivo; | ||||
|  | ||||
| 	archivo.open("output.txt"); | ||||
| 	if (!archivo.is_open()) { | ||||
| 		cout << "Error al guardar." << endl; | ||||
| 	} | ||||
| 	else { | ||||
| 		for (int j = 0; j < i; j++) { | ||||
| 			archivo << secuencia.numero[j] << endl; | ||||
| 		} | ||||
| 	} | ||||
| 	archivo.close(); | ||||
| } | ||||
										
											Binary file not shown.
										
									
								
							| @@ -0,0 +1,194 @@ | ||||
| //Examen Febrero 2013 - Grupos A, B, D y G. | ||||
| //Fernando M<>ndez Torrubiano | ||||
|  | ||||
| #include <iostream> | ||||
| #include <string> | ||||
| #include <fstream> | ||||
| #include <iomanip> | ||||
| using namespace std; | ||||
|  | ||||
|  | ||||
| //Constantes: | ||||
| const int MAX_NUM = 100; | ||||
|  | ||||
| //Tipos: | ||||
| typedef int tNumeros[MAX_NUM]; | ||||
| typedef struct tSecuencia { | ||||
| 	tNumeros numeros; | ||||
| 	int contador; | ||||
| }; | ||||
|  | ||||
|  | ||||
| //Funciones: | ||||
| void ejecutarMenu(); | ||||
| int menu(); | ||||
| bool generar(tSecuencia&, const int&); | ||||
| bool guardar(tSecuencia&); | ||||
| void recorrer(tSecuencia&); | ||||
| bool esFeliz(int&); | ||||
| bool buscar(tSecuencia&, int&, int&); | ||||
|  | ||||
|  | ||||
| int main() { | ||||
|  | ||||
| 	ejecutarMenu(); | ||||
|  | ||||
| 	return 0; | ||||
| } | ||||
|  | ||||
| void ejecutarMenu() { | ||||
| 	tSecuencia secuencia; | ||||
| 	int opc = 1, maximo, error, i = 1; | ||||
| 	bool generado = false; | ||||
|  | ||||
| 	while (opc != 0) { | ||||
| 		opc = menu(); | ||||
| 		switch (opc){ | ||||
| 		case 0: break; | ||||
| 		case 1:  | ||||
| 			cout << "Introduzca el limite superior para los numeros de la secuencia: "; | ||||
| 			cin >> maximo; | ||||
| 			if (generar(secuencia, maximo)) { | ||||
| 				cout << "Secuencia generada correctamente." << endl; | ||||
| 				generado = true; | ||||
| 			} | ||||
| 			else { | ||||
| 				cout << "Error al generar la secuencia." << endl; | ||||
| 			} | ||||
| 			system("PAUSE"); | ||||
| 			break; | ||||
| 		case 2: | ||||
| 			if (generado == true) { | ||||
| 				recorrer(secuencia); | ||||
| 			} | ||||
| 			else { | ||||
| 				cout << "Primero debes generar una secuencia." << endl; | ||||
| 			} | ||||
| 			system("PAUSE");  | ||||
| 			break; | ||||
| 		case 3:  | ||||
| 			if (generado == true) { | ||||
| 				cout << "Introduzca un error: "; | ||||
| 				cin >> error; | ||||
| 				if (buscar(secuencia, error, i)) { | ||||
| 					cout << "Encontrado en la linea " << i << " (diferencia: " << error << ")." << endl; | ||||
| 				} | ||||
| 				else { | ||||
| 					cout << "No encontrado." << endl; | ||||
| 				} | ||||
| 			} | ||||
| 			else { | ||||
| 				cout << "Primero debes generar una secuencia." << endl; | ||||
| 			} | ||||
| 			system("PAUSE"); | ||||
| 			break; | ||||
| 		default: | ||||
| 			break; | ||||
| 		} | ||||
| 		system("cls"); | ||||
| 	} | ||||
| } | ||||
|  | ||||
| int menu() { | ||||
| 	int opc = 0; | ||||
|  | ||||
| 	cout << setw(25) << setfill('=') << "MENU" << setw(25) << "\n" << setfill(char(0)); | ||||
| 	cout << "1.-Generar una secuencia." << endl; | ||||
| 	cout << "2.-Procesar la secuencia" << endl; | ||||
| 	cout << "3.-Buscar en la secuencia." << endl; | ||||
| 	cout << "0.-Salir" << endl; | ||||
| 	cout << setw(50) << setfill('=') << "\n" << setfill(char(0)); | ||||
|  | ||||
| 	do { | ||||
| 		cout << "Introduzca una opcion: "; | ||||
| 		cin >> opc; | ||||
| 	} while (opc < 0 || opc > 3); | ||||
|  | ||||
| 	return opc; | ||||
| } | ||||
|  | ||||
| bool generar(tSecuencia& secuencia, const int& maximo) { | ||||
| 	secuencia.contador = 0; | ||||
|  | ||||
| 	do{ | ||||
| 		cout << "Introduzca un numero (0 para terminar): "; | ||||
| 		cin >> secuencia.numeros[secuencia.contador]; | ||||
| 		if ((secuencia.numeros[secuencia.contador] < maximo) && (secuencia.numeros[secuencia.contador] > 0)) { | ||||
| 			secuencia.contador++; | ||||
| 		} | ||||
| 	} while ((secuencia.numeros[secuencia.contador] != 0)); | ||||
|  | ||||
| 	return guardar(secuencia) ? true : false; | ||||
| } | ||||
|  | ||||
| bool guardar(tSecuencia& secuencia) { | ||||
| 	bool save = false; | ||||
| 	ofstream archivo; | ||||
|  | ||||
| 	archivo.open("datos.txt"); | ||||
| 	if (!archivo.is_open()) { | ||||
| 		save = false; | ||||
| 	} | ||||
| 	else { | ||||
| 		for (int i = 0; i < secuencia.contador; i++){ | ||||
| 			archivo << secuencia.numeros[i] << endl; | ||||
| 		} | ||||
| 		archivo << -1; | ||||
| 		save = true; | ||||
| 	} | ||||
|  | ||||
| 	return save; | ||||
| } | ||||
|  | ||||
| void recorrer(tSecuencia& secuencia) { | ||||
| 	int numero = 0; | ||||
|  | ||||
| 	for (int i = 0; i < secuencia.contador; i++){ | ||||
| 		numero = secuencia.numeros[i]; | ||||
| 		if (esFeliz(numero)) { cout << "El numero: " << secuencia.numeros[i] << " ES FELIZ." << endl; } | ||||
| 		else { cout << "El numero: " << secuencia.numeros[i] << " NO ES FELIZ." << endl; } | ||||
| 	 | ||||
| 	} | ||||
| } | ||||
|  | ||||
| bool esFeliz(int& num) { | ||||
| 	int digito[10] = { 0,0,0,0,0,0,0,0,0,0 }, i = 0, aux; | ||||
|  | ||||
| 	do { | ||||
| 		if (num > 10) { //Igualamos una variable auxiliar al valor anterior del n<>mero (si el n<>mero, es mayor de 10). | ||||
| 			aux = num;  | ||||
| 		}  | ||||
| 		else { //Si el n<>mero es menor que 10, igualamos el auxiliar a 10 para que entre en el bucle y procese el n<>mero. | ||||
| 			aux = 10;  | ||||
| 		}  | ||||
| 		while (aux >= 10) { //Si el auxiliar es mayor o igual a 10, significa que el n<>mero aun tiene m<>s de dos cifras y por tanto hay que continuar extrayendo dichas cifras. | ||||
| 			digito[i] = num % 10; //Hacemos el m<>dulo 10 del n<>mero para extraer el digito correspondiente a las unidades. | ||||
| 			num -= digito[i]; //Restamos al n<>mero el valor de las unidades, para hacerlo potencia de 10. | ||||
| 			aux = num; //Igualamos una variable auxiliar al valor anterior del n<>mero. Porque en la siguiente comprobaci<63>n del bucle, el n<>mero estar<61> dividido entre 10 y dar<61>a una vuelta menos. | ||||
| 			num /= 10; //Dividimos el n<>mero entre 10 para en la siguiente vuelta del bucle, seguir extrayendo el pr<70>ximo d<>gito, que antes eran las decenas y ahora correcponder<65> a las unidades. | ||||
| 			i++; //Sumamos uno para guardar la siguiente cifra en la pr<70>xima posici<63>n del vector. Como vamos a sumar los d<>gitos, nos da igual que se guarden en orden inverso. | ||||
| 		} | ||||
|  | ||||
| 		num = 0; | ||||
| 		for (int j = 0; j < i; j++) { | ||||
| 			num += pow(digito[j], 2); //Calculamos la suma de las potencias cuadradas de cada uno de los d<>gitos del n<>mero. | ||||
| 		} | ||||
| 		i = 0; | ||||
| 	} while (num >= 10); | ||||
|  | ||||
| 	return (num == 1) ? true : false; | ||||
| } | ||||
|  | ||||
| bool buscar(tSecuencia& secuencia, int& error, int& i) { | ||||
| 	bool encontrado = false; | ||||
|  | ||||
| 	while ((!encontrado) && (i < secuencia.contador)) { | ||||
| 		if ((secuencia.numeros[i] - secuencia.numeros[i - 1]) < error) { | ||||
| 			error = secuencia.numeros[i] - secuencia.numeros[i - 1]; | ||||
| 			encontrado = true; | ||||
| 		} | ||||
| 		i++; | ||||
| 	} | ||||
|  | ||||
| 	return encontrado; | ||||
| } | ||||
										
											Binary file not shown.
										
									
								
							| @@ -0,0 +1,5 @@ | ||||
| 7 | ||||
| 97 | ||||
| 137 | ||||
| 250 | ||||
| -1 | ||||
| @@ -0,0 +1,243 @@ | ||||
| //Examen Febrero 2014 - Grupos A, B e I. | ||||
| //Fernando M<>ndez Torrubiano. | ||||
|  | ||||
| #include <iostream> | ||||
| #include <string> | ||||
| #include <fstream> | ||||
| #include <iomanip> | ||||
| using namespace std; | ||||
|  | ||||
| //Constantes: | ||||
| const int NPO = 10; | ||||
| const int NPNecesitados = 1; | ||||
|  | ||||
|  | ||||
| //Tipos: | ||||
| typedef struct tProducto { | ||||
| 	string nombre; | ||||
| 	float peso; | ||||
| 	float precio; | ||||
| }; | ||||
| typedef tProducto tProductos[NPO]; | ||||
| typedef struct tListaProductos { | ||||
| 	tProductos producto; | ||||
| 	int contador; | ||||
| }; | ||||
|  | ||||
|  | ||||
| //Funciones: | ||||
| void inicializa(tListaProductos&); | ||||
| bool cargar(tListaProductos&); | ||||
| void ejecutarMenu(tListaProductos&); | ||||
| int menu(); | ||||
| bool guardar(tListaProductos&); | ||||
| tListaProductos leerCesta(tListaProductos&); | ||||
| int buscarProducto(tListaProductos&, const string&); | ||||
| void realizarCompra(tListaProductos&, tListaProductos&); | ||||
| void mostrarAgotados(tListaProductos&); | ||||
|  | ||||
|  | ||||
| int main() { | ||||
| 	tListaProductos productos; | ||||
|  | ||||
| 	if (cargar(productos)) { | ||||
| 		ejecutarMenu(productos); | ||||
| 		if (guardar(productos)) { | ||||
| 			cout << "Guardado correctamente." << endl; | ||||
| 		} | ||||
| 		else { | ||||
| 			cout << "Error al guardar." << endl; | ||||
| 		} | ||||
| 	} | ||||
| 	else { | ||||
| 		cout << "Fin del programa." << endl; | ||||
| 	} | ||||
| 	system("PAUSE"); | ||||
|  | ||||
| 	return 0; | ||||
| } | ||||
|  | ||||
| void inicializa(tListaProductos& productos) { | ||||
| 	productos.contador = 0; | ||||
| 	for (int i = 0; i < NPO; i++){ | ||||
| 		productos.producto[i].nombre = ""; | ||||
| 		productos.producto[i].peso = 0; | ||||
| 		productos.producto[i].precio = 0; | ||||
| 	} | ||||
| } | ||||
|  | ||||
| bool cargar(tListaProductos& productos) { | ||||
| 	bool carga = false; | ||||
| 	ifstream archivo; | ||||
|  | ||||
| 	inicializa(productos); | ||||
| 	archivo.open("almacen.txt"); | ||||
| 	if (!archivo.is_open()) { | ||||
| 		cout << "No se ha encotrado el archivo." << endl; | ||||
| 		carga = false; | ||||
| 	} | ||||
| 	else { | ||||
| 		getline(archivo, productos.producto[productos.contador].nombre); | ||||
| 		while ((productos.producto[productos.contador].nombre != "XXX") && (productos.contador < NPO)) { | ||||
| 			archivo >> productos.producto[productos.contador].peso; | ||||
| 			archivo >> productos.producto[productos.contador].precio; | ||||
| 			productos.contador++; | ||||
| 			archivo.ignore(1, ' '); | ||||
| 			getline(archivo, productos.producto[productos.contador].nombre); | ||||
| 		} | ||||
| 		carga = true; | ||||
| 	} | ||||
| 	archivo.close(); | ||||
|  | ||||
| 	return carga; | ||||
| } | ||||
|  | ||||
| void ejecutarMenu(tListaProductos& productos) { | ||||
| 	tListaProductos cesta; | ||||
| 	int opc = 1; | ||||
|  | ||||
| 	while (opc != 0) { | ||||
| 		opc = menu(); | ||||
| 		switch (opc){ | ||||
| 		case 0: break; | ||||
| 		case 1: realizarCompra(productos, cesta); system("PAUSE"); break; | ||||
| 		case 2: mostrarAgotados(productos); system("PAUSE"); break; | ||||
| 		default: | ||||
| 			break; | ||||
| 		} | ||||
| 		system("cls"); | ||||
| 	} | ||||
| } | ||||
|  | ||||
| int menu() { | ||||
| 	int opc = 0; | ||||
|  | ||||
| 	cout << setw(20) << setfill('=') << "MENU" << setw(20) << "\n" << setfill(char(0)); | ||||
| 	cout << "1.-Realizar la compra" << endl; | ||||
| 	cout << "2.-Ver productos agotados" << endl; | ||||
| 	cout << "0.-Salir" << endl; | ||||
| 	cout << setw(40) << setfill('=') << "\n" << setfill(char(0)); | ||||
|  | ||||
| 	do { | ||||
| 		cout << "Introduzca una opcion: "; | ||||
| 		cin >> opc; | ||||
| 	} while (opc < 0 || opc > 2); | ||||
|  | ||||
| 	return opc; | ||||
| } | ||||
|  | ||||
| bool guardar(tListaProductos& productos) { | ||||
| 	bool guardado = false; | ||||
| 	ofstream archivo; | ||||
|  | ||||
| 	archivo.open("almacen.txt"); | ||||
| 	if (!archivo.is_open()) { | ||||
| 		guardado = false; | ||||
| 	} | ||||
| 	else { | ||||
| 		for (int i = 0; i < productos.contador; i++){ | ||||
| 			archivo << productos.producto[i].nombre << endl; | ||||
| 			archivo << productos.producto[i].peso << endl; | ||||
| 			archivo << productos.producto[i].precio << endl; | ||||
| 		} | ||||
| 		archivo << "XXX"; | ||||
| 		guardado = true; | ||||
| 	} | ||||
| 	archivo.close(); | ||||
|  | ||||
| 	return guardado; | ||||
| } | ||||
|  | ||||
| tListaProductos leerCesta(tListaProductos& productos) { | ||||
| 	tListaProductos cesta; | ||||
| 	cesta.contador = 0; | ||||
| 	string nombre; | ||||
| 	int pos = 0; | ||||
|  | ||||
| 	while (cesta.contador < NPNecesitados) { | ||||
| 		do { | ||||
| 			cout << "Introduzca un produto: "; | ||||
| 			getline(cin, nombre); | ||||
| 			pos = buscarProducto(productos, nombre); | ||||
| 		} while (pos == -1); | ||||
| 		cesta.producto[cesta.contador].nombre = nombre; | ||||
| 		do { | ||||
| 			cout << "Introduzca cantidad (KG): "; | ||||
| 			cin >> cesta.producto[cesta.contador].peso; | ||||
| 		} while (cesta.producto[cesta.contador].peso > productos.producto[pos].peso); | ||||
| 		productos.producto[pos].peso -= cesta.producto[cesta.contador].peso; | ||||
| 		cesta.producto[cesta.contador].precio = cesta.producto[cesta.contador].peso * productos.producto[pos].precio; | ||||
| 		cesta.contador++; | ||||
| 	} | ||||
|  | ||||
| 	return cesta; | ||||
| } | ||||
|  | ||||
| //SCARLETT JONHANSON ESTUVO AQU<51> | ||||
| //No, solo eres eva intentando gastar bromas | ||||
| //NO NO NO NO NOOOOO, bueno si. Me hacia ilu jo :,( | ||||
| //Eres idiota | ||||
| //Teniendo en cunta que tu eres yo y que yo soy tu, te estas llamando idiota a ti misma.  | ||||
| //-_- | ||||
| //:3 | ||||
| //PONTE A ESTUDIAR O TE MATO!! | ||||
| // AH! 0-0 si se<73>ora. | ||||
|  | ||||
|  | ||||
| int buscarProducto(tListaProductos& productos, const string& nombre) { | ||||
| 	int pos = productos.contador; | ||||
| 	bool encontrado = false; | ||||
|  | ||||
| 	while ((!encontrado) && (pos > -1)) { | ||||
| 		if (productos.producto[pos].nombre == nombre) { | ||||
| 			encontrado = true; | ||||
| 		} | ||||
| 		else { | ||||
| 			pos--; | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return pos; | ||||
| } | ||||
|  | ||||
| void realizarCompra(tListaProductos& productos, tListaProductos& cesta) { | ||||
|  | ||||
| 	cout << setw(15) << right << "NOMBRE" | ||||
| 		<< setw(15) << "CANTIDAD" | ||||
| 		<< setw(15) << "PRECIO" << endl; | ||||
| 	cout << setw(25) << setfill('=') << "ALMACEN" << setw(25) << "\n" << setfill(char(0)); | ||||
| 	for (int i = 0; i < productos.contador; i++) { | ||||
| 		cout << setw(15) << right << productos.producto[i].nombre | ||||
| 			<< setw(15) << productos.producto[i].peso | ||||
| 			<< setw(15) << productos.producto[i].precio << endl; | ||||
| 	} | ||||
| 	cout << setw(50) << setfill('=') << "\n" << setfill(char(0)); | ||||
|  | ||||
| 	cesta = leerCesta(productos); | ||||
|  | ||||
| 	cout << setw(15) << right << "NOMBRE" | ||||
| 		<< setw(15) << "CANTIDAD" | ||||
| 		<< setw(15) << "PRECIO" << endl; | ||||
| 	cout << setw(25) << setfill('=') << "CESTA" << setw(25) << "\n" << setfill(char(0)); | ||||
| 	for (int i = 0; i < cesta.contador; i++){ | ||||
| 		cout << setw(15) << right << cesta.producto[i].nombre | ||||
| 			<< setw(15) << cesta.producto[i].peso | ||||
| 			<< setw(15) << cesta.producto[i].precio << endl; | ||||
| 	} | ||||
| 	cout << setw(50) << setfill('=') << "\n" << setfill(char(0)); | ||||
| } | ||||
|  | ||||
| void mostrarAgotados(tListaProductos& productos) { | ||||
| 	cout << setw(15) << right << "NOMBRE" | ||||
| 		<< setw(15) << "CANTIDAD" | ||||
| 		<< setw(15) << "PRECIO" << endl; | ||||
| 	cout << setw(25) << setfill('=') << "AGOTADOS" << setw(25) << "\n" << setfill(char(0)); | ||||
| 	for (int i = 0; i < productos.contador; i++) { | ||||
| 		if (productos.producto[i].peso == 0) { | ||||
| 			cout << setw(15) << right << productos.producto[i].nombre | ||||
| 				<< setw(15) << productos.producto[i].peso | ||||
| 				<< setw(15) << productos.producto[i].precio << endl; | ||||
| 		} | ||||
| 	} | ||||
| 	cout << setw(50) << setfill('=') << "\n" << setfill(char(0)); | ||||
| } | ||||
										
											Binary file not shown.
										
									
								
							| @@ -0,0 +1,25 @@ | ||||
| Atun rojo | ||||
| 80.00 | ||||
| 15.95 | ||||
| Besugo | ||||
| 80.70 | ||||
| 15.95 | ||||
| Mejillon | ||||
| 12.50 | ||||
| 3.00 | ||||
| Caballa | ||||
| 355.00 | ||||
| 3.00 | ||||
| Lubina salvaje | ||||
| 410.00 | ||||
| 5.85 | ||||
| Gamba | ||||
| 150.00 | ||||
| 9.95 | ||||
| Merluza | ||||
| 475.00 | ||||
| 12.50 | ||||
| Salmonete | ||||
| 200.40 | ||||
| 6.30 | ||||
| XXX | ||||
| @@ -0,0 +1,240 @@ | ||||
| //Ex<45>men Febrero 2014 - Grupos C, E y F. | ||||
| //Fernando M<>ndez Torrubinao | ||||
|  | ||||
| #include <iostream> | ||||
| #include <string> | ||||
| #include <fstream> | ||||
| #include <iomanip> | ||||
| using namespace std; | ||||
|  | ||||
|  | ||||
| //Constantes: | ||||
| const int NUM_PLAYERS = 10; | ||||
|  | ||||
| //Tipos: | ||||
| typedef struct tJugador { | ||||
| 	string nombre; | ||||
| 	string equipo; | ||||
| 	int numPartidos; | ||||
| 	int minutos; | ||||
| 	int goles; | ||||
| }; | ||||
| typedef tJugador tJugadores[NUM_PLAYERS]; | ||||
| typedef struct tListaJugadores { | ||||
| 	tJugadores jugador; | ||||
| 	int contador; | ||||
| }; | ||||
|  | ||||
| //Funciones: | ||||
| void inicializa(tListaJugadores&); | ||||
| bool cargar(tListaJugadores&); | ||||
| void ejecutarMenu(tListaJugadores&); | ||||
| int menu(); | ||||
| void filtrarLista(tListaJugadores&, const string&); | ||||
| bool actualizarJugador(tListaJugadores&, const string&, const int&, const int&, int& pos); | ||||
| void consultarMaxGoleador(tListaJugadores& jugadores); | ||||
| void guardar(tListaJugadores&); | ||||
|  | ||||
| int main() { | ||||
| 	tListaJugadores jugadores; | ||||
|  | ||||
| 	if (cargar(jugadores)) { | ||||
| 		ejecutarMenu(jugadores); | ||||
| 		guardar(jugadores); | ||||
| 	} | ||||
| 	else { | ||||
| 		cout << "Fin del programa." << endl; | ||||
| 		system("PAUSE"); | ||||
| 	} | ||||
|  | ||||
| 	return 0; | ||||
| } | ||||
|  | ||||
| void inicializa(tListaJugadores& jugadores) { | ||||
| 	jugadores.contador = 0; | ||||
| 	for (int i = 0; i < NUM_PLAYERS; i++){ | ||||
| 		jugadores.jugador[i].nombre = ""; | ||||
| 		jugadores.jugador[i].equipo = ""; | ||||
| 		jugadores.jugador[i].numPartidos = 0; | ||||
| 		jugadores.jugador[i].minutos = 0; | ||||
| 		jugadores.jugador[i].goles = 0; | ||||
| 	} | ||||
| } | ||||
|  | ||||
| bool cargar(tListaJugadores& jugadores) { | ||||
| 	bool cargado = false; | ||||
| 	ifstream archivo; | ||||
|  | ||||
| 	inicializa(jugadores); | ||||
| 	archivo.open("players.txt"); | ||||
| 	if (!archivo.is_open()) { | ||||
| 		cout << "Error al cargar el archivo." << endl; | ||||
| 		cargado = false; | ||||
| 	} | ||||
| 	else { | ||||
| 		archivo >> jugadores.jugador[jugadores.contador].nombre; | ||||
| 		while ((jugadores.jugador[jugadores.contador].nombre != "XXX") && (jugadores.contador < NUM_PLAYERS)) { | ||||
| 			archivo >> jugadores.jugador[jugadores.contador].equipo; | ||||
| 			archivo >> jugadores.jugador[jugadores.contador].numPartidos; | ||||
| 			archivo >> jugadores.jugador[jugadores.contador].minutos; | ||||
| 			archivo >> jugadores.jugador[jugadores.contador].goles; | ||||
| 			jugadores.contador++; | ||||
| 			archivo >> jugadores.jugador[jugadores.contador].nombre; | ||||
| 		} | ||||
| 		cargado = true; | ||||
| 	} | ||||
| 	archivo.close(); | ||||
|  | ||||
| 	return cargado; | ||||
| } | ||||
|  | ||||
| void ejecutarMenu(tListaJugadores& jugadores) { | ||||
| 	int opc = 1; | ||||
| 	string codigo, nombre; | ||||
| 	int min, goles, pos = 0;; | ||||
|  | ||||
| 	while (opc != 0) { | ||||
| 		opc = menu(); | ||||
| 		switch (opc){ | ||||
| 		case 0: break; | ||||
| 		case 1: | ||||
| 			cout << "Introduzca equipo ('TODOS' para ver todos los jugadores): "; | ||||
| 			cin >> codigo; | ||||
| 			filtrarLista(jugadores, codigo);  | ||||
| 			break; | ||||
| 		case 2: | ||||
| 			cout << "Introduzca nombre del jugador: "; | ||||
| 			cin >> nombre; | ||||
| 			cout << "Introduzca minutos jugados: "; | ||||
| 			cin >> min; | ||||
| 			cout << "Introduzca goles marcados: "; | ||||
| 			cin >> goles; | ||||
| 			if (actualizarJugador(jugadores, nombre, min, goles, pos)) { | ||||
| 				cout << "Actualizado correctamente:" << endl; | ||||
| 				cout << setw(25) << setfill('-') << "\n" << setfill(char(0)) | ||||
| 					<< jugadores.jugador[pos].nombre << setw(5) | ||||
| 					<< jugadores.jugador[pos].equipo << setw(5) | ||||
| 					<< jugadores.jugador[pos].numPartidos << setw(5) | ||||
| 					<< jugadores.jugador[pos].minutos << setw(5) | ||||
| 					<< jugadores.jugador[pos].goles << endl | ||||
| 					<< setw(25) << setfill('-') << "\n" << setfill(char(0)); | ||||
| 			} | ||||
| 			else { | ||||
| 				cout << "Error al actualizar" << endl; | ||||
| 			} | ||||
| 			break; | ||||
| 		case 3: consultarMaxGoleador(jugadores); break; | ||||
| 		default: | ||||
| 			break; | ||||
| 		} | ||||
| 		system("PAUSE"); | ||||
| 		system("cls"); | ||||
| 	} | ||||
| } | ||||
|  | ||||
| int menu() { | ||||
| 	int opc = 0; | ||||
|  | ||||
| 	cout << setw(40) << setfill('=') << "\n" << setfill(char(0)); | ||||
| 	cout << "1.-Filtrar lista." << endl; | ||||
| 	cout << "2.-Actualizar jugador." << endl; | ||||
| 	cout << "3.-Consultar maximo goleador" << endl; | ||||
| 	cout << "0.-SALIR" << endl; | ||||
| 	cout << setw(40) << setfill('=') << "\n" << setfill(char(0)); | ||||
|  | ||||
| 	do { | ||||
| 		cout << "Introduzca una opcion: "; | ||||
| 		cin >> opc; | ||||
| 	} while (opc < 0 || opc > 3); | ||||
|  | ||||
| 	return opc; | ||||
| } | ||||
|  | ||||
| void filtrarLista(tListaJugadores& jugadores, const string& codigo) { | ||||
| 	cout << setw(70) << setfill('_') << "\n" << setfill(char(0)); | ||||
| 	cout << endl << setw(15) << right << "JUGADOR" | ||||
| 		<< setw(20) << "PARTIDOS JUGADOS" | ||||
| 		<< setw(20) << "MINUTOS JUGADOS" | ||||
| 		<< setw(10) << "GOLES" << endl; | ||||
| 	cout << setw(70) << setfill('_') << "\n" << endl; | ||||
| 	cout << setw(35) << setfill('=') << codigo << setw(35) << "\n" << setfill(char(0)); | ||||
| 	for (int i = 0; i < jugadores.contador; i++){ | ||||
| 		if ((jugadores.jugador[i].equipo == codigo) || (codigo == "TODOS") || (codigo == "todos")) { | ||||
| 			cout << setw(15) << right << jugadores.jugador[i].nombre | ||||
| 				<< setw(15) << jugadores.jugador[i].numPartidos | ||||
| 				<< setw(20) << jugadores.jugador[i].minutos | ||||
| 				<< setw(15) << jugadores.jugador[i].goles << endl; | ||||
| 		} | ||||
| 	} | ||||
| 	cout << setw(70) << setfill('=') << "\n" << setfill(char(0)); | ||||
| } | ||||
|  | ||||
| bool actualizarJugador(tListaJugadores& jugadores, const string& nombre, const int& min, const int& goles, int& i) { | ||||
| 	bool actualizado = false; | ||||
|  | ||||
| 	while ((!actualizado) && (i < jugadores.contador)) { | ||||
| 		if ((jugadores.jugador[i].nombre == nombre) && (min > 0) && (goles > 0)) { | ||||
| 			jugadores.jugador[i].minutos += min; | ||||
| 			jugadores.jugador[i].goles += goles; | ||||
| 			jugadores.jugador[i].numPartidos++; | ||||
| 			actualizado = true; | ||||
| 		} | ||||
| 		else { | ||||
| 			i++; | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return actualizado; | ||||
| } | ||||
|  | ||||
| void consultarMaxGoleador(tListaJugadores& jugadores) { | ||||
| 	int maxGoles = 0; | ||||
| 	tListaJugadores goleadores; | ||||
|  | ||||
| 	for (int i = 0; i < jugadores.contador; i++){ | ||||
| 		if (jugadores.jugador[i].goles > maxGoles) { | ||||
| 			maxGoles = jugadores.jugador[i].goles; | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	goleadores.contador = 0; | ||||
| 	cout << setw(20) << setfill('-') << "PICHICHIS" << setw(20) << setfill('-') << "\n" << setfill(char(0)); | ||||
| 	for (int i = 0; i < jugadores.contador; i++){ | ||||
| 		if (jugadores.jugador[i].goles == maxGoles) { | ||||
| 			goleadores.jugador[goleadores.contador].nombre = jugadores.jugador[i].nombre; | ||||
| 			goleadores.jugador[goleadores.contador].equipo = jugadores.jugador[i].equipo; | ||||
| 			goleadores.jugador[goleadores.contador].numPartidos = jugadores.jugador[i].numPartidos; | ||||
| 			goleadores.jugador[goleadores.contador].minutos = jugadores.jugador[i].minutos; | ||||
| 			goleadores.jugador[goleadores.contador].goles = jugadores.jugador[i].goles; | ||||
| 			cout << setw(10) << right << goleadores.jugador[goleadores.contador].nombre << setw(5) | ||||
| 				<< goleadores.jugador[goleadores.contador].equipo << setw(5) | ||||
| 				<< goleadores.jugador[goleadores.contador].numPartidos << setw(5) | ||||
| 				<< goleadores.jugador[goleadores.contador].minutos << setw(5) | ||||
| 				<< goleadores.jugador[goleadores.contador].goles << endl; | ||||
| 			goleadores.contador++; | ||||
| 		} | ||||
| 	} | ||||
| 	cout << setw(40) << setfill('-') << "\n" << setfill(char(0)); | ||||
| 	 | ||||
| } | ||||
|  | ||||
| void guardar(tListaJugadores& jugadores) { | ||||
| 	ofstream archivo; | ||||
|  | ||||
| 	archivo.open("players.txt"); | ||||
| 	if (!archivo.is_open()) { | ||||
| 		cout << "Error al guardar." << endl; | ||||
| 		system("PAUSE"); | ||||
| 	} | ||||
| 	else { | ||||
| 		for (int i = 0; i < jugadores.contador; i++){ | ||||
| 			archivo << jugadores.jugador[i].nombre << " " | ||||
| 				<< jugadores.jugador[i].equipo << " " | ||||
| 				<< jugadores.jugador[i].numPartidos << " " | ||||
| 				<< jugadores.jugador[i].minutos << " " | ||||
| 				<< jugadores.jugador[i].goles << endl; | ||||
| 		} | ||||
| 		archivo << "XXX"; | ||||
| 	} | ||||
| 	archivo.close(); | ||||
| } | ||||
										
											Binary file not shown.
										
									
								
							| @@ -0,0 +1,7 @@ | ||||
| Messi BCN 9 810 7 | ||||
| Oblack ATM 17 1545 0 | ||||
| Griezmann ATM 15 1312 4 | ||||
| Bale RMA 5 457 3 | ||||
| Casillas RMA 0 0 0 | ||||
| Costa ATM 10 755 9 | ||||
| XXX | ||||
| @@ -0,0 +1,281 @@ | ||||
| //Examen Febrero 2014 - Grupos D y G. | ||||
| //Fernando M<>ndez Torrubiano | ||||
|  | ||||
| #include <iostream> | ||||
| #include <string> | ||||
| #include <fstream> | ||||
| #include <iomanip> | ||||
| using namespace std; | ||||
|  | ||||
| //Constantes: | ||||
| const int NP = 10; | ||||
| const int CLASES = 4; | ||||
|  | ||||
| //Tipos: | ||||
| typedef enum tClase{papeleria, alimentacion, limpieza, informatica}; | ||||
| typedef struct tProveedor { | ||||
| 	string CIF; | ||||
| 	tClase clase; | ||||
| 	int pedidos; | ||||
| 	int coste; | ||||
| }; | ||||
| typedef tProveedor tProveedores[NP]; | ||||
| typedef struct tListaProveedores { | ||||
| 	tProveedores proveedor; | ||||
| 	int contador; | ||||
| }; | ||||
|  | ||||
| typedef struct tGastos { | ||||
| 	tClase clase; | ||||
| 	int gasto; | ||||
| }; | ||||
| typedef tGastos tListaGastos[CLASES]; | ||||
|  | ||||
| //Funciones: | ||||
| void inicializa(tListaProveedores&); | ||||
| bool carga(tListaProveedores&); | ||||
| void tIntToClase(tListaProveedores&, const int&); | ||||
| void ejecutarMenu(tListaProveedores&); | ||||
| int menu(); | ||||
| bool guardar(tListaProveedores&); | ||||
| int buscarProveedor(tListaProveedores&, const string&); | ||||
| void nuevoPedido(tListaProveedores&, const string&, const int&); | ||||
| void mostrar(tListaProveedores&); | ||||
| void mostrarIntervalo(tListaProveedores&, const int&, const int&); | ||||
| void totalesXclase(tListaProveedores&); | ||||
| void iniciaGastos(tListaGastos&); | ||||
|  | ||||
| int main() { | ||||
| 	tListaProveedores proveedores; | ||||
|  | ||||
| 	if (carga(proveedores)) { | ||||
| 		ejecutarMenu(proveedores); | ||||
| 		if (guardar(proveedores)) { | ||||
| 			cout << "Guardado correctamente." << endl; | ||||
| 		} | ||||
| 		else { | ||||
| 			cout << "Error al guardar el archivo." << endl; | ||||
| 		} | ||||
| 	} | ||||
| 	else { | ||||
| 		cout << "Error al cargar el archivo." << endl; | ||||
| 		system("PAUSE"); | ||||
| 	} | ||||
|  | ||||
| 	return 0; | ||||
| } | ||||
|  | ||||
| void inicializa(tListaProveedores& proveedores) { | ||||
| 	proveedores.contador = 0; | ||||
| 	for (int i = 0; i < NP; i++){ | ||||
| 		proveedores.proveedor[i].CIF = ""; | ||||
| 		proveedores.proveedor[i].clase = informatica; | ||||
| 		proveedores.proveedor[i].pedidos = 0; | ||||
| 		proveedores.proveedor[i].coste = 0; | ||||
| 	} | ||||
| } | ||||
|  | ||||
| bool carga(tListaProveedores& proveedores) { | ||||
| 	bool cargado = false; | ||||
| 	ifstream archivo; | ||||
| 	int claseAUX; | ||||
|  | ||||
| 	inicializa(proveedores); | ||||
| 	archivo.open("proveedores.txt"); | ||||
| 	if (!archivo.is_open()) { | ||||
| 		cargado = false; | ||||
| 	} | ||||
| 	else { | ||||
| 		archivo >> proveedores.proveedor[proveedores.contador].CIF; | ||||
| 		while ((proveedores.proveedor[proveedores.contador].CIF != "X") && (proveedores.contador < NP)) { | ||||
| 			archivo >> claseAUX; | ||||
| 			tIntToClase(proveedores, claseAUX); | ||||
| 			archivo >> proveedores.proveedor[proveedores.contador].pedidos; | ||||
| 			archivo >> proveedores.proveedor[proveedores.contador].coste; | ||||
| 			proveedores.contador++; | ||||
| 			archivo >> proveedores.proveedor[proveedores.contador].CIF; | ||||
| 		} | ||||
| 		cargado = true; | ||||
| 	} | ||||
| 	archivo.close(); | ||||
|  | ||||
| 	return cargado; | ||||
| } | ||||
|  | ||||
| void tIntToClase(tListaProveedores& proveedores, const int& aux) { | ||||
| 	switch (aux){ | ||||
| 	case 0: proveedores.proveedor[proveedores.contador].clase = papeleria; break; | ||||
| 	case 1: proveedores.proveedor[proveedores.contador].clase = alimentacion; break; | ||||
| 	case 2: proveedores.proveedor[proveedores.contador].clase = limpieza; break; | ||||
| 	case 3: proveedores.proveedor[proveedores.contador].clase = informatica; break; | ||||
| 	default: | ||||
| 		break; | ||||
| 	} | ||||
| } | ||||
|  | ||||
| void ejecutarMenu(tListaProveedores& proveedores) { | ||||
| 	int opc = 1, coste, max, min; | ||||
| 	string CIF; | ||||
|  | ||||
| 	while (opc != 0) { | ||||
| 		opc = menu(); | ||||
| 		switch (opc){ | ||||
| 		case 0: break; | ||||
| 		case 1:  | ||||
| 			mostrar(proveedores); | ||||
| 			cout << endl << "Introduzca el CIF para el pedido: "; | ||||
| 			cin >> CIF; | ||||
| 			cout << "Introduzca el coste del pedido: "; | ||||
| 			cin >> coste; | ||||
| 			nuevoPedido(proveedores, CIF, coste); | ||||
| 			break; | ||||
| 		case 2: | ||||
| 			cout << "Introduzca un minimo: "; | ||||
| 			cin >> min; | ||||
| 			cout << "Introduzca un maximo: "; | ||||
| 			cin >> max; | ||||
| 			mostrarIntervalo(proveedores, max, min); | ||||
| 			break; | ||||
| 		case 3: totalesXclase(proveedores); break; | ||||
| 		default: | ||||
| 			break; | ||||
| 		} | ||||
| 		system("PAUSE"); | ||||
| 		system("cls"); | ||||
| 	} | ||||
| } | ||||
|  | ||||
| int menu() { | ||||
| 	int opc = 0; | ||||
|  | ||||
| 	cout << setw(25) << setfill('=') << "MENU" << setw(25) << "\n" << setfill(char(0)); | ||||
| 	cout << "1.-Nuevo pedido." << endl; | ||||
| 	cout << "2.-Proveedores con numero de pedidos en un intervalo." << endl; | ||||
| 	cout << "3.-Gastos por clase de proveedor." << endl; | ||||
| 	cout << "0.-SALIR." << endl; | ||||
| 	cout << setw(50) << setfill('=') << "\n" << setfill(char(0)); | ||||
|  | ||||
| 	do { | ||||
| 		cout << "Introduzca una opcion: "; | ||||
| 		cin >> opc; | ||||
| 	} while (opc < 0 || opc > 3); | ||||
|  | ||||
| 	return opc; | ||||
| } | ||||
|  | ||||
| bool guardar(tListaProveedores& proveedores) { | ||||
| 	bool guardado = false; | ||||
| 	ofstream archivo; | ||||
|  | ||||
| 	archivo.open("proveedores.txt"); | ||||
| 	if (!archivo.is_open()) { | ||||
| 		guardado = false; | ||||
| 	} | ||||
| 	else { | ||||
| 		for (int i = 0; i < proveedores.contador; i++) | ||||
| 		{ | ||||
| 			archivo << proveedores.proveedor[i].CIF << " " | ||||
| 				<< proveedores.proveedor[i].clase << " " | ||||
| 				<< proveedores.proveedor[i].pedidos << " " | ||||
| 				<< proveedores.proveedor[i].coste << endl; | ||||
| 		} | ||||
| 		archivo << "X"; | ||||
| 		guardado = true; | ||||
| 	} | ||||
| 	archivo.close(); | ||||
|  | ||||
| 	return guardado; | ||||
| } | ||||
|  | ||||
| int buscarProveedor(tListaProveedores& proveedores, const string& CIF) { | ||||
| 	int pos = proveedores.contador; | ||||
| 	bool encontrado = false; | ||||
|  | ||||
| 	while ((!encontrado) && (pos > -1)) { | ||||
| 		if (proveedores.proveedor[pos].CIF == CIF) { | ||||
| 			encontrado = true; | ||||
| 		} | ||||
| 		else { | ||||
| 			pos--; | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return pos; | ||||
| } | ||||
|  | ||||
| void nuevoPedido(tListaProveedores& proveedores, const string& CIF, const int& coste) { | ||||
| 	int pos = buscarProveedor(proveedores, CIF); | ||||
|  | ||||
| 	if (pos != -1) { | ||||
| 		proveedores.proveedor[pos].coste += coste; | ||||
| 		proveedores.proveedor[pos].pedidos++; | ||||
| 		cout << "Actualizado correctamente." << endl; | ||||
| 	} | ||||
| 	else { | ||||
| 		cout << "CIF no encontrado." << endl; | ||||
| 	} | ||||
| } | ||||
|  | ||||
| void mostrar(tListaProveedores& proveedores) { | ||||
| 	cout << endl << setw(7) << "CIF" | ||||
| 		<< setw(20) << "PROVEEDOR" | ||||
| 		<< setw(13) << "NUM_PEDIDOS" | ||||
| 		<< setw(7) << "COSTE" << endl; | ||||
| 	cout << setw(50) << setfill('=') << "\n" << setfill(char(0)); | ||||
| 	for (int i = 0; i < proveedores.contador; i++){ | ||||
| 		cout << setw(10) << right << proveedores.proveedor[i].CIF | ||||
| 			<< setw(10) << proveedores.proveedor[i].clase | ||||
| 			<< setw(13) << proveedores.proveedor[i].pedidos | ||||
| 			<< setw(12) << proveedores.proveedor[i].coste << endl; | ||||
| 	} | ||||
| 	cout << setw(50) << setfill('=') << "\n" << setfill(char(0)); | ||||
| } | ||||
|  | ||||
| void mostrarIntervalo(tListaProveedores& proveedores, const int& max, const int& min) { | ||||
| 	cout << endl << setw(7) << "CIF" | ||||
| 		<< setw(20) << "PROVEEDOR" | ||||
| 		<< setw(13) << "NUM_PEDIDOS" | ||||
| 		<< setw(7) << "COSTE" << endl; | ||||
| 	cout << setw(50) << setfill('=') << "\n" << setfill(char(0)); | ||||
| 	for (int i = 0; i < proveedores.contador; i++) { | ||||
| 		if ((proveedores.proveedor[i].pedidos <= max) && (proveedores.proveedor[i].pedidos >= min)) { | ||||
| 			cout << setw(10) << right << proveedores.proveedor[i].CIF | ||||
| 				<< setw(10) << proveedores.proveedor[i].clase | ||||
| 				<< setw(13) << proveedores.proveedor[i].pedidos | ||||
| 				<< setw(12) << proveedores.proveedor[i].coste << endl; | ||||
| 		} | ||||
| 	} | ||||
| 	cout << setw(50) << setfill('=') << "\n" << setfill(char(0)); | ||||
| } | ||||
|  | ||||
| void totalesXclase(tListaProveedores& proveedores) { | ||||
| 	tListaGastos gastos; | ||||
|  | ||||
| 	iniciaGastos(gastos); | ||||
| 	for (int i = 0; i < CLASES; i++){ | ||||
| 		for (int j = 0; j < NP; j++){ | ||||
| 			if (proveedores.proveedor[j].clase == gastos[i].clase) { | ||||
| 				gastos[i].gasto += proveedores.proveedor[j].coste; | ||||
| 			} | ||||
| 		} | ||||
| 		switch (gastos[i].clase){ | ||||
| 		case 0: cout << setw(12) << right << "Papeleria"; break; | ||||
| 		case 1: cout << setw(12) << right << "Alimentacion"; break; | ||||
| 		case 2: cout << setw(12) << right << "Limpieza"; break; | ||||
| 		case 3: cout << setw(12) << right << "Informatica"; break; | ||||
| 		default: | ||||
| 			break; | ||||
| 		} | ||||
| 		cout << setw(10) << right << gastos[i].gasto << endl; | ||||
| 	} | ||||
| } | ||||
|  | ||||
| void iniciaGastos(tListaGastos& gastos) { | ||||
| 	gastos[0].clase = papeleria; | ||||
| 	gastos[1].clase = alimentacion; | ||||
| 	gastos[2].clase = limpieza; | ||||
| 	gastos[3].clase = informatica; | ||||
| 	for (int i = 0; i < CLASES; i++){ | ||||
| 		gastos[i].gasto = 0; | ||||
| 	} | ||||
| } | ||||
										
											Binary file not shown.
										
									
								
							| @@ -0,0 +1,6 @@ | ||||
| A00112233 2 4 232 | ||||
| B95637245 2 1 112 | ||||
| F00148231 0 22 728 | ||||
| F00166230 1 3 94 | ||||
| A12345678 0 123 6057 | ||||
| X | ||||
| @@ -0,0 +1,193 @@ | ||||
| //Ex<45>men Febrero 2015 - Grupos A, B, D, I y G. | ||||
| //Fernando M<>ndez Torrubiano | ||||
|  | ||||
| #include <iostream> | ||||
| #include <string> | ||||
| #include <fstream> | ||||
| #include <iomanip> | ||||
| using namespace std; | ||||
|  | ||||
| //Constantes: | ||||
| const int NUM_ASIG = 6; | ||||
| const int MAX_RESERVAS = 3; | ||||
|  | ||||
| //Tipos: | ||||
| typedef struct tAsignatura { | ||||
| 	string nombre; | ||||
| 	float creditos; | ||||
| 	int numGrupos; | ||||
| }; | ||||
| typedef tAsignatura tAsignaturas[NUM_ASIG]; | ||||
|  | ||||
| typedef struct tReserva { | ||||
| 	string nombre; | ||||
| 	int grupos; | ||||
| }; | ||||
| typedef tReserva tReservas[MAX_RESERVAS]; | ||||
|  | ||||
| typedef struct tProfesor { | ||||
| 	tAsignaturas asignatura; | ||||
| 	tReservas reserva; | ||||
| 	int contadorA; | ||||
| 	int contadorR; | ||||
| }; | ||||
|  | ||||
| //Funciones: | ||||
| void inicia(tProfesor&); | ||||
| bool cargar(tProfesor&); | ||||
| bool guardar(tProfesor&); | ||||
| void mostrarDisponibles(tProfesor&); | ||||
| void leerReservas(tProfesor&); | ||||
| int buscarAsignatura(tProfesor&, const string&); | ||||
| void realizaReserva(tProfesor&, const int&); | ||||
|  | ||||
|  | ||||
| int main() { | ||||
| 	tProfesor profesor; | ||||
|  | ||||
| 	inicia(profesor); | ||||
| 	if (cargar(profesor)) { | ||||
| 		mostrarDisponibles(profesor); | ||||
| 		leerReservas(profesor);  | ||||
| 		mostrarDisponibles(profesor); | ||||
| 		if (guardar(profesor)) { | ||||
| 			cout << "Guardado correctamente." << endl; | ||||
| 		} | ||||
| 		else { | ||||
| 			cout << "Intentelo de nuevo." << endl; | ||||
| 		} | ||||
| 	} | ||||
| 	else { | ||||
| 		cout << "Fin del programa." << endl; | ||||
| 	} | ||||
| 	system("PAUSE"); | ||||
|  | ||||
| 	return 0; | ||||
| } | ||||
|  | ||||
| void inicia(tProfesor& profesor) { | ||||
| 	profesor.contadorA = 0; | ||||
| 	profesor.contadorR = 0; | ||||
| 	for (int i = 0; i < NUM_ASIG; i++){ | ||||
| 		profesor.asignatura[i].nombre = ""; | ||||
| 		profesor.asignatura[i].creditos = 0; | ||||
| 		profesor.asignatura[i].numGrupos = 0; | ||||
| 		if (i < MAX_RESERVAS) { | ||||
| 			profesor.reserva[i].nombre = ""; | ||||
| 			profesor.reserva[i].grupos = 0; | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
| bool cargar(tProfesor& profesor) { | ||||
| 	bool carga = false; | ||||
| 	ifstream archivo; | ||||
|  | ||||
| 	archivo.open("asignaturas.txt"); | ||||
| 	if (!archivo.is_open()) { | ||||
| 		cout << "Error al cargar las asignaturas." << endl; | ||||
| 		carga = false; | ||||
| 	} | ||||
| 	else { | ||||
| 		archivo >> profesor.asignatura[profesor.contadorA].nombre; | ||||
| 		while ((profesor.asignatura[profesor.contadorA].nombre != "XXX") && (profesor.contadorA < NUM_ASIG)) { | ||||
| 			archivo >> profesor.asignatura[profesor.contadorA].creditos; | ||||
| 			archivo >> profesor.asignatura[profesor.contadorA].numGrupos; | ||||
| 			profesor.contadorA++; | ||||
| 			archivo >> profesor.asignatura[profesor.contadorA].nombre; | ||||
| 		} | ||||
| 		carga = true; | ||||
| 	} | ||||
| 	archivo.close(); | ||||
|  | ||||
| 	return carga; | ||||
| } | ||||
|  | ||||
| bool guardar(tProfesor& profesor) { | ||||
| 	bool guardado = false; | ||||
| 	ofstream archivo; | ||||
|  | ||||
| 	archivo.open("asignaturas.txt"); | ||||
| 	if (!archivo.is_open()) { | ||||
| 		cout << "Error al guardar las asignaturas." << endl; | ||||
| 		guardado = false; | ||||
| 	} | ||||
| 	else { | ||||
| 		for (int i = 0; i < profesor.contadorA; i++) { | ||||
| 			archivo << profesor.asignatura[i].nombre << " "; | ||||
| 			archivo << profesor.asignatura[i].creditos << " "; | ||||
| 			archivo << profesor.asignatura[i].numGrupos << endl; | ||||
| 		} | ||||
| 		archivo << "XXX"; | ||||
| 		guardado = true; | ||||
| 	} | ||||
| 	archivo.close(); | ||||
|  | ||||
| 	return guardado; | ||||
| } | ||||
|  | ||||
| void mostrarDisponibles(tProfesor& profesor) { | ||||
| 	cout << setw(3) << right << "NOMBRE" | ||||
| 		<< setw(10) << "CREDITOS" | ||||
| 		<< setw(20) << "GRUPOS DISPONIBLES" << endl; | ||||
| 	cout << setw(40) << setfill('=') << "\n" << setfill(char(0)); | ||||
| 	for (int i = 0; i < profesor.contadorA; i++){ | ||||
| 		if (profesor.asignatura[i].numGrupos > 0) { | ||||
| 			cout << setw(3) << right << profesor.asignatura[i].nombre | ||||
| 				<< setw(10) << profesor.asignatura[i].creditos | ||||
| 				<< setw(20) << profesor.asignatura[i].numGrupos << endl; | ||||
| 		} | ||||
| 	} | ||||
| 	cout << setw(40) << setfill('=') << "\n" << setfill(char(0)); | ||||
| } | ||||
|  | ||||
| void leerReservas(tProfesor& profesor) { | ||||
| 	string nombre; | ||||
| 	int existe = 0, numCreditos = 0; | ||||
|  | ||||
| 	while ((nombre != "XXX") && (profesor.contadorR < MAX_RESERVAS)) { | ||||
| 		cout << "Introduzca nombre de la asignatura a reservar: "; | ||||
| 		cin >> nombre; | ||||
| 		existe = buscarAsignatura(profesor, nombre); | ||||
| 		if (existe != -1) { | ||||
| 			profesor.reserva[profesor.contadorR].nombre = nombre; | ||||
| 			realizaReserva(profesor, existe); | ||||
| 			numCreditos += profesor.asignatura[existe].creditos; | ||||
| 			profesor.contadorR++; | ||||
| 		} | ||||
| 		else { | ||||
| 			if (nombre != "XXX") { | ||||
| 				cout << "Asignatura no encontrada." << endl; | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 	cout << endl << "Creditos reservados: " << numCreditos << endl << endl; | ||||
| } | ||||
|  | ||||
| int buscarAsignatura(tProfesor& profesor, const string& nombre) { | ||||
| 	int i = NUM_ASIG - 1; | ||||
| 	bool encontrado = false; | ||||
|  | ||||
| 	while ((profesor.asignatura[i].nombre != nombre) && (i > -1) && (!encontrado)) { | ||||
| 		if (profesor.asignatura[i].nombre == nombre) { | ||||
| 			encontrado = true; | ||||
| 		} | ||||
| 		else { | ||||
| 			i--; | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return i; | ||||
| } | ||||
|  | ||||
| void realizaReserva(tProfesor& profesor, const int& pos) { | ||||
| 	int numGrupos = 0, resta = 0; | ||||
|  | ||||
| 	do { | ||||
| 		cout << "Grupos a reservar (Quedan " << profesor.asignatura[pos].numGrupos << " grupos): "; | ||||
| 		cin >> numGrupos; | ||||
| 		resta = profesor.asignatura[pos].numGrupos - numGrupos; | ||||
| 	} while (resta < 0); | ||||
|  | ||||
| 	profesor.asignatura[pos].numGrupos -= numGrupos; | ||||
| } | ||||
										
											Binary file not shown.
										
									
								
							| @@ -0,0 +1,7 @@ | ||||
| FP 6.00 8 | ||||
| FC 6.00 8 | ||||
| GE 3.00 2 | ||||
| FEE 3.00 2 | ||||
| MMI 6.50 6  | ||||
| MDL 6.00 7  | ||||
| XXX | ||||
| @@ -0,0 +1,210 @@ | ||||
| //Ex<45>men Febrero 2015 - Grupos C, E y F. | ||||
| //Fernando M<>ndez Torrubiano | ||||
|  | ||||
| #include <iostream> | ||||
| #include <string> | ||||
| #include <fstream> | ||||
| #include <iomanip> | ||||
| using namespace std; | ||||
|  | ||||
|  | ||||
| //Constantes: | ||||
| const int MAX_VIAJES = 10; | ||||
| const int NUM_PREFERENCIAS = 3; | ||||
|  | ||||
| //Tipos: | ||||
| typedef enum tCategoria{Mochilero, Turista, Lujo}; | ||||
| typedef struct tViaje { | ||||
| 	string destino; | ||||
| 	int duracion; | ||||
| 	int plazas; | ||||
| 	tCategoria categoria; | ||||
| }; | ||||
| typedef tViaje tViajes[MAX_VIAJES]; | ||||
| typedef struct tListaViajes { | ||||
| 	tViajes viaje; | ||||
| 	int contador; | ||||
| }; | ||||
|  | ||||
| typedef string tPreferencias[NUM_PREFERENCIAS]; | ||||
|  | ||||
| //Funciones: | ||||
| void inicializa(tListaViajes&); | ||||
| bool cargarCatalogo(tListaViajes&); | ||||
| void tIntToCategoria(tListaViajes&, const int&); | ||||
| void mostrarViajesEnCategoria(tListaViajes&, const int&); | ||||
| void convertirCat(const int&, tCategoria&); | ||||
| bool guardarCatalogo(tListaViajes&); | ||||
| void leerPreferencias(tPreferencias&); | ||||
| int buscarDestino(tListaViajes&, tPreferencias&, const int&); | ||||
| bool hacerReserva(tListaViajes&, const int&, tPreferencias&); | ||||
|  | ||||
| int main() { | ||||
| 	tListaViajes viajes; | ||||
| 	tPreferencias preferencia; | ||||
| 	int numCat; | ||||
|  | ||||
| 	if (cargarCatalogo(viajes)) { | ||||
| 		cout << "Escriba una categoria (0 Mochilero, 1 Turista, 2 Lujo): "; | ||||
| 		cin >> numCat; | ||||
| 		mostrarViajesEnCategoria(viajes, numCat); | ||||
| 		leerPreferencias(preferencia); | ||||
| 		if (hacerReserva(viajes, numCat, preferencia)) { | ||||
| 			cout << "Gracias por su reserva." << endl; | ||||
| 			guardarCatalogo(viajes); | ||||
| 		} | ||||
| 		else { | ||||
| 			cout << "Vuelva a intentarlo." << endl; | ||||
| 		} | ||||
| 	} | ||||
| 	else { | ||||
| 		cout << "FIN DEL PROGRAMA." << endl; | ||||
| 	} | ||||
|  | ||||
| 	system("PAUSE"); | ||||
| 	return 0; | ||||
| } | ||||
|  | ||||
| void inicializa(tListaViajes& viajes) { | ||||
| 	viajes.contador = 0; | ||||
| 	for (int i = 0; i < MAX_VIAJES; i++){ | ||||
| 		viajes.viaje[i].destino = ""; | ||||
| 		viajes.viaje[i].duracion = 0; | ||||
| 		viajes.viaje[i].plazas = 0; | ||||
| 		viajes.viaje[i].categoria = Mochilero; | ||||
| 	} | ||||
| } | ||||
|  | ||||
| bool cargarCatalogo(tListaViajes& viajes) { | ||||
| 	bool carga = false; | ||||
| 	ifstream archivo; | ||||
| 	int aux = 0; | ||||
|  | ||||
| 	inicializa(viajes); | ||||
| 	archivo.open("catalogoViajes.txt"); | ||||
| 	if (!archivo.is_open()) { | ||||
| 		cout << "Error al cargar el archivo." << endl; | ||||
| 		carga = false; | ||||
| 	} | ||||
| 	else { | ||||
| 		archivo >> viajes.viaje[viajes.contador].destino; | ||||
| 		while ((viajes.viaje[viajes.contador].destino != "XXX") && (viajes.contador < MAX_VIAJES)) { | ||||
| 			archivo >> viajes.viaje[viajes.contador].duracion; | ||||
| 			archivo >> viajes.viaje[viajes.contador].plazas; | ||||
| 			archivo >> aux; | ||||
| 			tIntToCategoria(viajes, aux); | ||||
| 			viajes.contador++; | ||||
| 			archivo >> viajes.viaje[viajes.contador].destino; | ||||
| 		} | ||||
| 		carga = true; | ||||
| 	} | ||||
| 	archivo.close(); | ||||
|  | ||||
| 	return carga; | ||||
| } | ||||
|  | ||||
| void tIntToCategoria(tListaViajes& viajes, const int& aux) { | ||||
| 	switch (aux) { | ||||
| 	case 0: viajes.viaje[viajes.contador].categoria = Mochilero; break; | ||||
| 	case 1: viajes.viaje[viajes.contador].categoria = Turista; break; | ||||
| 	case 2: viajes.viaje[viajes.contador].categoria = Lujo; break; | ||||
| 	} | ||||
| } | ||||
|  | ||||
| void mostrarViajesEnCategoria(tListaViajes& viajes, const int& numCategoria) { | ||||
| 	tCategoria categoria; | ||||
|  | ||||
| 	convertirCat(numCategoria, categoria); | ||||
|  | ||||
| 	cout << setw(10) << right << "DESTINO" | ||||
| 		<< setw(15) << "DURACION" | ||||
| 		<< setw(15) << "PLAZAS" << endl; | ||||
| 	cout << setw(25) << setfill('=') << categoria << setw(25) << "\n" << setfill(char(0)); | ||||
| 	for (int i = 0; i < viajes.contador; i++){ | ||||
| 		if (viajes.viaje[i].categoria == categoria) { | ||||
| 			cout << setw(10) << right << viajes.viaje[i].destino | ||||
| 				<< setw(15) << viajes.viaje[i].duracion | ||||
| 				<< setw(15) << viajes.viaje[i].plazas << endl; | ||||
| 		} | ||||
| 	} | ||||
| 	cout << setw(50) << setfill('=') << "\n" << setfill(char(0)); | ||||
| } | ||||
|  | ||||
| void convertirCat(const int& numCategoria, tCategoria& categoria) { | ||||
| 	switch (numCategoria) { | ||||
| 	case 0: categoria = Mochilero; break; | ||||
| 	case 1: categoria = Turista; break; | ||||
| 	case 2: categoria = Lujo; break; | ||||
| 	} | ||||
| } | ||||
|  | ||||
| bool guardarCatalogo(tListaViajes& viajes) { | ||||
| 	bool guardado = false; | ||||
| 	ofstream archivo; | ||||
|  | ||||
| 	archivo.open("catalogoViajes.txt"); | ||||
| 	if (!archivo.is_open()) { | ||||
| 		cout << "Error al guardar el archivo." << endl; | ||||
| 		guardado = false; | ||||
| 	} | ||||
| 	else { | ||||
| 		for (int i = 0; i < viajes.contador; i++){ | ||||
| 			archivo << viajes.viaje[i].destino << " " | ||||
| 				<< viajes.viaje[i].duracion << " " | ||||
| 				<< viajes.viaje[i].plazas << " " | ||||
| 				<< viajes.viaje[i].categoria << endl; | ||||
| 		} | ||||
| 		archivo << "XXX"; | ||||
| 		guardado = true; | ||||
| 	} | ||||
| 	archivo.close(); | ||||
|  | ||||
| 	return guardado; | ||||
| } | ||||
|  | ||||
| void leerPreferencias(tPreferencias& preferencia) { | ||||
| 	for (int i = 0; i < NUM_PREFERENCIAS; i++) { | ||||
| 		cout << "Escriba sus destinos preferentes (de mayor a menor): "; | ||||
| 		cin >> preferencia[i]; | ||||
| 	} | ||||
| } | ||||
|  | ||||
| int buscarDestino(tListaViajes& viajes, tPreferencias& preferencias, const int& numCategoria) { | ||||
| 	int i = 0, pos = viajes.contador - 1; | ||||
| 	tCategoria categoria; | ||||
| 	bool encontrado = false; | ||||
|  | ||||
| 	convertirCat(numCategoria, categoria); | ||||
|  | ||||
| 	while ((i < NUM_PREFERENCIAS) && (!encontrado)) { | ||||
| 		pos = viajes.contador - 1; | ||||
| 		while ((pos > -1) && (!encontrado)) { | ||||
| 			if ((viajes.viaje[pos].destino == preferencias[i]) && (viajes.viaje[pos].categoria == categoria) && (viajes.viaje[pos].plazas > 0)) { | ||||
| 				encontrado = true; | ||||
| 			} | ||||
| 			else { | ||||
| 				pos--; | ||||
| 			} | ||||
| 		} | ||||
| 		i++; | ||||
| 	} | ||||
|  | ||||
| 	return pos; | ||||
| } | ||||
|  | ||||
| bool hacerReserva(tListaViajes& viajes, const int& numCategoria, tPreferencias& preferencias) { | ||||
| 	bool reserva = false; | ||||
| 	int posReserva = buscarDestino(viajes, preferencias, numCategoria); | ||||
|  | ||||
| 	if (posReserva != -1) { | ||||
| 		cout << "Reservado viaje a " << viajes.viaje[posReserva].destino << endl; | ||||
| 		viajes.viaje[posReserva].plazas--; | ||||
| 		reserva = true; | ||||
| 	} | ||||
| 	else { | ||||
| 		cout << "No hay disponibilidad para esas preferencias." << endl; | ||||
| 		reserva = false; | ||||
| 	} | ||||
|  | ||||
| 	return reserva; | ||||
| } | ||||
										
											Binary file not shown.
										
									
								
							| @@ -0,0 +1,7 @@ | ||||
| Nepal 10 2 0 | ||||
| Mongolia 15 0 0 | ||||
| Viena 3 8 2 | ||||
| Viena 3 2 1 | ||||
| Sicilia 5 1 1 | ||||
| Las-Vegas 4 2 0 | ||||
| XXX | ||||
| @@ -0,0 +1,255 @@ | ||||
| //Examen Febrero 2015 - Grupos D, G y H | ||||
| //Fernando M<>ndez Torrubiano | ||||
|  | ||||
| #include <iostream> | ||||
| #include <string> | ||||
| #include <fstream> | ||||
| #include <iomanip> | ||||
| using namespace std; | ||||
|  | ||||
|  | ||||
| //Constantes: | ||||
| const int NUM_PROD = 5; | ||||
| const int NUM_PED = 3; | ||||
|  | ||||
| //Tipos: | ||||
| typedef struct tProducto { | ||||
| 	string codigo; | ||||
| 	string descripcion; | ||||
| 	float precio; | ||||
| 	bool oferta; | ||||
| }; | ||||
| typedef tProducto tProductos[NUM_PROD]; | ||||
| typedef struct tListaProductos { | ||||
| 	tProductos producto; | ||||
| 	int contador; | ||||
| }; | ||||
|  | ||||
| typedef struct tCesta { | ||||
| 	string nombre; | ||||
| 	int unidades; | ||||
| 	float precioProducto; | ||||
| }; | ||||
| typedef tCesta tCestas[NUM_PED]; | ||||
| typedef struct tPedidos{ | ||||
| 	tCestas cesta; | ||||
| 	int contador; | ||||
| }; | ||||
|  | ||||
|  | ||||
| //Funciones: | ||||
| void inicia(tListaProductos&, tPedidos&); | ||||
| bool cargar(tListaProductos&); | ||||
| void ejecutarMenu(tListaProductos&, tPedidos&); | ||||
| int menu(); | ||||
| void muestraProductos(tListaProductos&); | ||||
| string tBoolToString(tListaProductos&, const int&); | ||||
| void crearCesta(tListaProductos&, tPedidos&); | ||||
| bool buscarProducto(const tListaProductos&, const tPedidos&); | ||||
| bool procesaCesta(tListaProductos&, tPedidos&); | ||||
| float total(tListaProductos&, tPedidos&, const int&, float&); | ||||
|  | ||||
| int main() { | ||||
| 	tListaProductos productos; | ||||
| 	tPedidos pedidos; | ||||
|  | ||||
| 	inicia(productos, pedidos); | ||||
| 	if (cargar(productos)) { | ||||
| 		ejecutarMenu(productos, pedidos); | ||||
| 	} | ||||
|  | ||||
| 	return 0; | ||||
| } | ||||
|  | ||||
| void inicia(tListaProductos& productos, tPedidos& pedidos) { | ||||
| 	productos.contador = 0; | ||||
| 	pedidos.contador = 0; | ||||
| 	for (int i = 0; i < NUM_PROD; i++){ | ||||
| 		productos.producto[i].codigo = ""; | ||||
| 		productos.producto[i].descripcion = ""; | ||||
| 		productos.producto[i].precio = 0; | ||||
| 		productos.producto[i].oferta = false; | ||||
| 		if (i < NUM_PED) { | ||||
| 			pedidos.cesta[i].nombre = ""; | ||||
| 			pedidos.cesta[i].unidades = 0; | ||||
| 			pedidos.cesta[i].precioProducto = 0; | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
| bool cargar(tListaProductos& productos) { | ||||
| 	bool carga = false; | ||||
| 	ifstream archivo; | ||||
|  | ||||
| 	archivo.open("productos.txt"); | ||||
| 	if (!archivo.is_open()) { | ||||
| 		cout << "Error al cargar la lista de productos." << endl; | ||||
| 		carga = false; | ||||
| 	} | ||||
| 	else { | ||||
| 		archivo >> productos.producto[productos.contador].codigo; | ||||
| 		while ((productos.producto[productos.contador].codigo != "XXX") && (productos.contador < NUM_PROD)) { | ||||
| 			archivo >> productos.producto[productos.contador].precio; | ||||
| 			archivo >> productos.producto[productos.contador].oferta; | ||||
| 			getline(archivo, productos.producto[productos.contador].descripcion); | ||||
| 			productos.contador++; | ||||
| 			archivo >> productos.producto[productos.contador].codigo; | ||||
| 		} | ||||
| 		carga = true; | ||||
| 	} | ||||
| 	archivo.close(); | ||||
|  | ||||
| 	return carga; | ||||
| } | ||||
|  | ||||
| void ejecutarMenu(tListaProductos& productos, tPedidos& pedidos) { | ||||
| 	int opc = 1; | ||||
|  | ||||
| 	while (opc != 0) { | ||||
| 		muestraProductos(productos); | ||||
| 		opc = menu(); | ||||
| 		switch (opc){ | ||||
| 		case 0: break; | ||||
| 		case 1: crearCesta(productos, pedidos); break; | ||||
| 		case 2: procesaCesta(productos, pedidos); break; | ||||
| 		default: | ||||
| 			break; | ||||
| 		} | ||||
| 		system("cls"); | ||||
| 	} | ||||
| } | ||||
|  | ||||
| int menu() { | ||||
| 	int opc = 0; | ||||
|  | ||||
| 	cout << endl << setw(40) << setfill('=') << "\n" << setw(char(0)); | ||||
| 	cout << "1.-A<>adir productos a la cesta." << endl; | ||||
| 	cout << "2.-Confirmar pedido." << endl; | ||||
| 	cout << "0.-SALIR." << endl; | ||||
| 	cout << setw(40) << setfill('=') << "\n" << setw(char(0)); | ||||
|  | ||||
| 	do { | ||||
| 		cout << "Introduzca una opcion: "; | ||||
| 		cin >> opc; | ||||
| 	} while (opc < 0 || opc > 2); | ||||
|  | ||||
| 	return opc; | ||||
| } | ||||
| void muestraProductos(tListaProductos& productos) { | ||||
| 	cout << setw(5) << right << "CODIGO" | ||||
| 		<< setw(25) << "DESCRIPCION" | ||||
| 		<< setw(15) << "PRECIO" | ||||
| 		<< setw(15) << "OFERTA" << endl; | ||||
| 	cout << setw(70) << setfill('=') << "\n" << setfill(char(0)); | ||||
| 	for (int i = 0; i < productos.contador; i++){ | ||||
| 		cout << setw(5) << right << productos.producto[i].codigo | ||||
| 			<< setw(25) << productos.producto[i].descripcion | ||||
| 			<< setw(15) << productos.producto[i].precio | ||||
| 			<< setw(15) << tBoolToString(productos, i) << endl; | ||||
| 	} | ||||
| 	cout << setw(70) << setfill('=') << "\n" << setfill(char(0)); | ||||
| } | ||||
|  | ||||
| string tBoolToString(tListaProductos& productos, const int& pos) { | ||||
| 	string oferta; | ||||
| 	switch (productos.producto[pos].oferta){ | ||||
| 	case false: oferta = "NO"; break; | ||||
| 	case true: oferta = "SI"; break; | ||||
| 	} | ||||
| 	return oferta; | ||||
| } | ||||
|  | ||||
| void crearCesta(tListaProductos& productos, tPedidos& pedidos) { | ||||
| 	int i = 0; | ||||
|  | ||||
| 	while ((pedidos.contador < NUM_PED) && (pedidos.cesta[pedidos.contador].nombre != "XXX")) { | ||||
| 		cout << "Introduzca un codigo de producto: "; | ||||
| 		cin >> pedidos.cesta[pedidos.contador].nombre; | ||||
| 		while (!buscarProducto(productos, pedidos)) { | ||||
| 			cout << "Producto no encontrado. Introduzca otro codigo: "; | ||||
| 			cin >> pedidos.cesta[pedidos.contador].nombre; | ||||
| 		} | ||||
| 		if (pedidos.cesta[pedidos.contador].nombre != "XXX") { | ||||
| 			cout << "Introduzca un cantidad de productos: "; | ||||
| 			cin >> pedidos.cesta[pedidos.contador].unidades; | ||||
| 			pedidos.contador++; | ||||
| 		} | ||||
| 	} | ||||
| 	cout << "Cesta llena." << endl; | ||||
| 	system("PAUSE"); | ||||
| } | ||||
|  | ||||
| bool buscarProducto(const tListaProductos& productos, const tPedidos& pedidos) { | ||||
| 	bool encontrado = false; | ||||
| 	int i = 0; | ||||
|  | ||||
| 	while ((!encontrado) && (i < productos.contador)) { | ||||
| 		if ((pedidos.cesta[pedidos.contador].nombre == productos.producto[i].codigo) || (pedidos.cesta[pedidos.contador].nombre == "XXX")) { | ||||
| 			encontrado = true; | ||||
| 		} | ||||
| 		else { | ||||
| 			i++; | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return encontrado; | ||||
| } | ||||
|  | ||||
| bool procesaCesta(tListaProductos& productos, tPedidos& pedidos) { | ||||
| 	bool procesado = false; | ||||
| 	ofstream archivo; | ||||
| 	float totalPrecio = 0; | ||||
|  | ||||
| 	archivo.open("ticket.txt"); | ||||
| 	if (!archivo.is_open()) { | ||||
| 		cout << "Error al procesar el pedido." << endl; | ||||
| 		procesado = false; | ||||
| 	} | ||||
| 	else { | ||||
| 		for (int i = 0; i < pedidos.contador; i++){ | ||||
| 			archivo << pedidos.cesta[i].nombre << " x " | ||||
| 				<< pedidos.cesta[i].unidades << " = "; | ||||
| 			totalPrecio = total(productos, pedidos, i, totalPrecio); | ||||
| 			archivo << pedidos.cesta[i].precioProducto << endl; | ||||
| 		} | ||||
| 		archivo << "Total compra: " << totalPrecio << endl; | ||||
| 		procesado = true; | ||||
| 	} | ||||
| 	archivo.close(); | ||||
|  | ||||
| 	if(procesado == true){ | ||||
| 		cout << "Precio total: " << totalPrecio << endl; | ||||
| 	} | ||||
| 	else{ | ||||
| 		cout << "Intentelo de nuevo." << endl; | ||||
| 	} | ||||
| 	 | ||||
| 	system("PAUSE"); | ||||
| 	return procesado; | ||||
| } | ||||
|  | ||||
| float total(tListaProductos& productos, tPedidos& pedidos, const int& pos, float& total) { | ||||
| 	int j = 0; | ||||
| 	bool encontrado = false; | ||||
| 	float descuento = 0; | ||||
|  | ||||
| 	while ((!encontrado) && (j < productos.contador)) { | ||||
| 		if (pedidos.cesta[pos].nombre == productos.producto[j].codigo) { | ||||
| 			if (productos.producto[j].oferta) { | ||||
| 				descuento = (productos.producto[j].precio * 0.15); | ||||
| 				total += (productos.producto[j].precio - descuento); | ||||
| 				pedidos.cesta[pos].precioProducto = (productos.producto[j].precio - descuento); | ||||
| 			} | ||||
| 			else { | ||||
| 				total += productos.producto[j].precio; | ||||
| 				pedidos.cesta[pos].precioProducto = productos.producto[j].precio; | ||||
| 			} | ||||
| 			encontrado = true; | ||||
| 		} | ||||
| 		else { | ||||
| 			j++; | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return total; | ||||
| } | ||||
										
											Binary file not shown.
										
									
								
							| @@ -0,0 +1,5 @@ | ||||
| L0001 1.25 0 Leche | ||||
| PC010 3.15 0 Pasta de dientes | ||||
| H0025 1.50 0 Huevos | ||||
| Y8912 1.50 1 Pack de 6 yogures | ||||
| XXX | ||||
| @@ -0,0 +1,279 @@ | ||||
| //Ex<45>men Febro de 2016. | ||||
| //Grupos F y G. | ||||
| //Fernando M<>ndez Torubiano | ||||
|  | ||||
| #include <iostream> | ||||
| #include <string> | ||||
| #include <fstream> | ||||
| #include <iomanip> | ||||
| using namespace std; | ||||
|  | ||||
| //Constantes: | ||||
| const int NUM_EQUIPOS = 25; | ||||
|  | ||||
| //Tipos: | ||||
| typedef enum tCategoria{principiante, intermedio, avanzado, experto}; | ||||
| typedef struct tEquipo { | ||||
| 	string nombre; | ||||
| 	tCategoria liga; | ||||
| 	int partidasJugadas; | ||||
| 	int partidasGanadas; | ||||
| 	bool disponible; | ||||
|  | ||||
| }; | ||||
| typedef tEquipo tEquipos[NUM_EQUIPOS]; | ||||
| typedef struct tListaEquipos { | ||||
| 	tEquipos equipo; | ||||
| 	int contador; | ||||
| }; | ||||
|  | ||||
| //Funciones: | ||||
| void inicializa(tListaEquipos&); | ||||
| bool cargarDatos(tListaEquipos&); | ||||
| void guardarDatos(tListaEquipos&); | ||||
| void tInttoLiga(tListaEquipos&, const int); | ||||
| int menu(); | ||||
| void ejecutarMenu(tListaEquipos&); | ||||
| void jugarPartida(tListaEquipos&); | ||||
| bool buscarEquipos(tListaEquipos&, const string, int&); | ||||
| bool buscarContrarios(tListaEquipos&, const int, string&); | ||||
| void apuntarResultado(tListaEquipos&); | ||||
| void actualizarGanador(tListaEquipos&, const int&); | ||||
| void actualizarPerdedor(tListaEquipos&, const int&); | ||||
|  | ||||
| int main() { | ||||
| 	tListaEquipos equipos; | ||||
|  | ||||
| 	if (cargarDatos(equipos)) { | ||||
| 		ejecutarMenu(equipos); | ||||
| 	} | ||||
| 	else { | ||||
| 		cout << "Fin del programa." << endl; | ||||
| 		system("PAUSE"); | ||||
| 	} | ||||
|  | ||||
| 	return 0; | ||||
| } | ||||
|  | ||||
| void inicializa(tListaEquipos& equipos) { | ||||
| 	equipos.contador = 0; | ||||
| 	for (int i = 0; i < NUM_EQUIPOS; i++){ | ||||
| 		equipos.equipo[i].nombre = ""; | ||||
| 		equipos.equipo[i].liga = principiante; | ||||
| 		equipos.equipo[i].partidasJugadas = 0; | ||||
| 		equipos.equipo[i].partidasGanadas = 0; | ||||
| 		equipos.equipo[i].disponible = false; | ||||
| 	} | ||||
| } | ||||
|  | ||||
| bool cargarDatos(tListaEquipos& equipos) { | ||||
| 	bool carga = false; | ||||
| 	ifstream archivo; | ||||
| 	int AUXliga = 0; | ||||
|  | ||||
| 	inicializa(equipos); | ||||
| 	archivo.open("equipos.txt"); | ||||
| 	if (!archivo.is_open()) { | ||||
| 		cout << "Archivo no encontrado." << endl; | ||||
| 		carga = false; | ||||
| 	} | ||||
| 	else { | ||||
| 		archivo >> equipos.equipo[equipos.contador].nombre; | ||||
| 		while ((equipos.equipo[equipos.contador].nombre != "XXX") && (equipos.contador < NUM_EQUIPOS)) { | ||||
| 			archivo >> AUXliga; | ||||
| 			tInttoLiga(equipos, AUXliga); | ||||
| 			archivo >> equipos.equipo[equipos.contador].partidasJugadas; | ||||
| 			archivo >> equipos.equipo[equipos.contador].partidasGanadas; | ||||
| 			archivo >> equipos.equipo[equipos.contador].disponible; | ||||
| 			equipos.contador++; | ||||
| 			archivo >> equipos.equipo[equipos.contador].nombre; | ||||
| 		} | ||||
| 		carga = true; | ||||
| 	} | ||||
| 	archivo.close(); | ||||
|  | ||||
| 	return carga; | ||||
| } | ||||
|  | ||||
| void tInttoLiga(tListaEquipos& equipos, const int AUXliga) { | ||||
| 	switch (AUXliga){ | ||||
| 	case 0: equipos.equipo[equipos.contador].liga = principiante; break; | ||||
| 	case 1: equipos.equipo[equipos.contador].liga = intermedio; break; | ||||
| 	case 2: equipos.equipo[equipos.contador].liga = avanzado; break; | ||||
| 	case 3: equipos.equipo[equipos.contador].liga = experto; break; | ||||
| 	} | ||||
| } | ||||
|  | ||||
| int menu() { | ||||
| 	int opc = 0; | ||||
|  | ||||
| 	cout << setw(25) << setfill('=') << "\n"; | ||||
| 	cout << "1.- Jugar Partida." << endl; | ||||
| 	cout << "2.- Apuntar resultado." << endl; | ||||
| 	cout << "0.- Salir." << endl; | ||||
| 	cout << setw(25) << setfill('=') << "\n" << setw(0) << setfill(char(0)); | ||||
|  | ||||
| 	do { | ||||
| 		cout << "Introduzca una opcion: "; | ||||
| 		cin >> opc; | ||||
| 	} while (opc < 0 || opc > 2); | ||||
|  | ||||
| 	return opc; | ||||
| } | ||||
|  | ||||
| void ejecutarMenu(tListaEquipos& equipos) { | ||||
| 	int opc = 1; | ||||
|  | ||||
| 	while (opc != 0) { | ||||
| 		opc = menu(); | ||||
| 		switch (opc){ | ||||
| 		case 1: jugarPartida(equipos); break; | ||||
| 		case 2: apuntarResultado(equipos); break; | ||||
| 		case 0: guardarDatos(equipos); break; | ||||
| 		default: | ||||
| 			break; | ||||
| 		} | ||||
| 		system("cls"); | ||||
| 	} | ||||
| } | ||||
|  | ||||
| void jugarPartida(tListaEquipos& equipos) { | ||||
| 	string nomEquipo, nomContrario; | ||||
| 	int pos = 0; | ||||
|  | ||||
| 	cout << "Introduzca el nombre de su equipo: "; | ||||
| 	cin >> nomEquipo; | ||||
| 	if (buscarEquipos(equipos, nomEquipo, pos)) { | ||||
| 		if (buscarContrarios(equipos, pos, nomContrario)) { | ||||
| 			cout << "Rival encontrado: " << nomContrario << endl; | ||||
| 		} | ||||
| 		else { | ||||
| 			equipos.equipo[pos].disponible = true; | ||||
| 		} | ||||
| 	} | ||||
| 	else { | ||||
| 		cout << "Equipo no encontrado." << endl; | ||||
| 	} | ||||
| 	system("PAUSE"); | ||||
| } | ||||
|  | ||||
| bool buscarEquipos(tListaEquipos& equipos, const string nomEquipo, int& posicion) { | ||||
| 	bool encontrado = false; | ||||
|  | ||||
| 	while ((!encontrado) && (posicion < equipos.contador)) { | ||||
| 		if (equipos.equipo[posicion].nombre == nomEquipo) { | ||||
| 			encontrado = true; | ||||
| 		} | ||||
| 		else { | ||||
| 			posicion++; | ||||
| 		} | ||||
| 	} | ||||
| 	return encontrado; | ||||
| } | ||||
|  | ||||
| bool buscarContrarios(tListaEquipos& equipos, const int pos, string& nomContrario) { | ||||
| 	bool encontrado = false; | ||||
| 	int i = 0; | ||||
| 	int numPartidasJugadas = 25; | ||||
|  | ||||
| 	for (int i = 0; i < equipos.contador; i++) { | ||||
| 		if ((equipos.equipo[i].liga == equipos.equipo[pos].liga) && (i != pos) && (numPartidasJugadas >= equipos.equipo[i].partidasJugadas)) { | ||||
| 			numPartidasJugadas = equipos.equipo[i].partidasJugadas; | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	while ((!encontrado) && (i < equipos.contador)) { | ||||
| 		if ((equipos.equipo[i].liga == equipos.equipo[pos].liga) && (i != pos) && (numPartidasJugadas == equipos.equipo[i].partidasJugadas)) { | ||||
| 			nomContrario = equipos.equipo[i].nombre; | ||||
| 			encontrado = true; | ||||
| 		} | ||||
| 		else { | ||||
| 			i++; | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return encontrado; | ||||
| } | ||||
|  | ||||
| void apuntarResultado(tListaEquipos& equipos) { | ||||
| 	string nomGanador, nomPerdedor; | ||||
| 	int posGanador = 0, posPerdedor = 0; | ||||
|  | ||||
| 	do { | ||||
| 		cout << "Introduzca el nombre del equipo GANADOR: "; | ||||
| 		cin >> nomGanador; | ||||
| 	} while (!buscarEquipos(equipos, nomGanador, posGanador)); | ||||
| 	actualizarGanador(equipos, posGanador); | ||||
|  | ||||
| 	do { | ||||
| 		cout << "Introduzca el nombre del equipo PERDEDOR: "; | ||||
| 		cin >> nomPerdedor; | ||||
| 	} while (!buscarEquipos(equipos, nomPerdedor, posPerdedor)); | ||||
| 	actualizarPerdedor(equipos, posPerdedor); | ||||
|  | ||||
| 	cout << endl << "Resultados actualizados correctamente." << endl; | ||||
| 	system("PAUSE"); | ||||
| } | ||||
|  | ||||
| void actualizarGanador(tListaEquipos& equipos, const int& pos) { | ||||
| 	int partidasPerdidas = 0, diferencia = 0; | ||||
|  | ||||
| 	equipos.equipo[pos].partidasJugadas++; | ||||
| 	equipos.equipo[pos].partidasGanadas++; | ||||
|  | ||||
| 	partidasPerdidas = equipos.equipo[pos].partidasJugadas - equipos.equipo[pos].partidasGanadas; | ||||
| 	diferencia = equipos.equipo[pos].partidasGanadas - partidasPerdidas; | ||||
| 	if (diferencia > 25) { | ||||
| 		switch (equipos.equipo[pos].liga) { | ||||
| 		case principiante: equipos.equipo[pos].liga = intermedio; break; | ||||
| 		case intermedio: equipos.equipo[pos].liga = avanzado; break; | ||||
| 		case avanzado: equipos.equipo[pos].liga = experto; break; | ||||
| 		case experto: equipos.equipo[pos].liga = experto; break; | ||||
| 		} | ||||
| 		equipos.equipo[pos].partidasJugadas = 0; | ||||
| 		equipos.equipo[pos].partidasGanadas = 0; | ||||
| 	} | ||||
| 	 | ||||
| 	equipos.equipo[pos].disponible = false; | ||||
| } | ||||
|  | ||||
| void actualizarPerdedor(tListaEquipos& equipos, const int& pos) { | ||||
| 	int partidasPerdidas = 0; | ||||
|  | ||||
| 	equipos.equipo[pos].partidasJugadas++; | ||||
|  | ||||
| 	partidasPerdidas = equipos.equipo[pos].partidasJugadas - equipos.equipo[pos].partidasGanadas; | ||||
| 	if (partidasPerdidas > 20) { | ||||
| 		switch (equipos.equipo[pos].liga) { | ||||
| 		case principiante: equipos.equipo[pos].liga = principiante; break; | ||||
| 		case intermedio: equipos.equipo[pos].liga = principiante; break; | ||||
| 		case avanzado: equipos.equipo[pos].liga = intermedio; break; | ||||
| 		case experto: equipos.equipo[pos].liga = avanzado; break; | ||||
| 		} | ||||
| 		equipos.equipo[pos].partidasJugadas = 0; | ||||
| 		equipos.equipo[pos].partidasGanadas = 0; | ||||
| 	} | ||||
|  | ||||
| 	equipos.equipo[pos].disponible = false; | ||||
| } | ||||
|  | ||||
| void guardarDatos(tListaEquipos& equipos) { | ||||
| 	ofstream archivo; | ||||
|  | ||||
| 	archivo.open("equipos.txt"); | ||||
| 	if (!archivo.is_open()) { | ||||
| 		cout << "Error al guardar el archivo." << endl; | ||||
| 		system("PAUSE"); | ||||
| 	} | ||||
| 	else { | ||||
| 		for (int i = 0; i < equipos.contador; i++){ | ||||
| 			archivo << equipos.equipo[i].nombre << endl; | ||||
| 			archivo << equipos.equipo[i].liga << " "; | ||||
| 			archivo << equipos.equipo[i].partidasJugadas << " "; | ||||
| 			archivo << equipos.equipo[i].partidasGanadas << " "; | ||||
| 			archivo << equipos.equipo[i].disponible << endl; | ||||
| 		} | ||||
| 		archivo << "XXX"; | ||||
| 	} | ||||
| 	archivo.close(); | ||||
| } | ||||
										
											Binary file not shown.
										
									
								
							| @@ -0,0 +1,21 @@ | ||||
| EquipoA | ||||
| 3 9 8 0 | ||||
| EquipoB | ||||
| 3 4 1 0 | ||||
| EquipoC | ||||
| 0 5 4 0 | ||||
| EquipoD | ||||
| 2 3 2 1 | ||||
| EquipoE | ||||
| 1 2 1 0 | ||||
| EquipoF | ||||
| 2 5 3 1 | ||||
| EquipoG | ||||
| 2 6 1 1 | ||||
| EquipoH | ||||
| 2 5 2 1 | ||||
| EquipoI | ||||
| 1 4 1 0 | ||||
| EquipoJ | ||||
| 0 3 0 1 | ||||
| XXX | ||||
| @@ -0,0 +1,224 @@ | ||||
| //Ex<45>men Febrero 2016 - Grupos A, B, C e I | ||||
| //Fernando M<>ndez Torrubiano | ||||
|  | ||||
| #include <iostream> | ||||
| #include <string> | ||||
| #include <fstream> | ||||
| #include <iomanip> | ||||
| using namespace std; | ||||
|  | ||||
| //Constantes: | ||||
| const int N = 50; | ||||
|  | ||||
| //Tipos: | ||||
| typedef enum { embarcando, operado, retrasado, suspendido }tEstado; | ||||
| typedef struct { | ||||
| 	string numVuelo; | ||||
| 	char terminal; | ||||
| 	int puertaEmb; | ||||
| 	tEstado estVuelo; | ||||
| 	string destino; | ||||
| }tVuelo; | ||||
| typedef tVuelo tVuelos[N]; | ||||
| typedef struct { | ||||
| 	tVuelos vuelo; | ||||
| 	int contador; | ||||
| }tListaVuelos; | ||||
|  | ||||
| //Funciones: | ||||
| void inizializa(tListaVuelos&); | ||||
| bool cargar(tListaVuelos&); | ||||
| void tIntToEstado(tListaVuelos&, const int); | ||||
| int menu(); | ||||
| void ejecutarMenu(tListaVuelos&); | ||||
| void guardar(tListaVuelos&); | ||||
| void obtenerInfoVuelo(tListaVuelos&); | ||||
| void actualizaEstVuelo(tListaVuelos&); | ||||
| int buscarVuelo(tListaVuelos&, const string&); | ||||
| void mostrarVuelo(tListaVuelos&, const string&); | ||||
| void actualizarVuelo(tListaVuelos&, const int&, const int&); | ||||
|  | ||||
|  | ||||
| int main() { | ||||
| 	tListaVuelos vuelos; | ||||
|  | ||||
| 	if (cargar(vuelos)) { | ||||
| 		ejecutarMenu(vuelos); | ||||
| 	} | ||||
| 	else { | ||||
| 		cout << "Fin del programa." << endl; | ||||
| 		system("PAUSE"); | ||||
| 	} | ||||
|  | ||||
| 	return 0; | ||||
| } | ||||
|  | ||||
| void inicializa(tListaVuelos& vuelos) { | ||||
| 	vuelos.contador = 0; | ||||
| 	for (int i = 0; i < N; i++) { | ||||
| 		vuelos.vuelo[i].numVuelo = ""; | ||||
| 		vuelos.vuelo[i].terminal = char(0); | ||||
| 		vuelos.vuelo[i].puertaEmb = 0; | ||||
| 		vuelos.vuelo[i].estVuelo = suspendido; | ||||
| 		vuelos.vuelo[i].destino = ""; | ||||
| 	} | ||||
| } | ||||
|  | ||||
| bool cargar(tListaVuelos& vuelos) { | ||||
| 	bool carga = false; | ||||
| 	int AUX; | ||||
| 	ifstream archivo; | ||||
|  | ||||
| 	inicializa(vuelos); | ||||
| 	archivo.open("salidas.txt"); | ||||
| 	if (!archivo.is_open()) { | ||||
| 		cout << "Error al cargar el archivo." << endl; | ||||
| 		carga = false; | ||||
| 	} | ||||
| 	else { | ||||
| 		archivo >> vuelos.vuelo[vuelos.contador].numVuelo; | ||||
| 		while ((vuelos.vuelo[vuelos.contador].numVuelo != "XXX") && (vuelos.contador < N)) { | ||||
| 			archivo >> vuelos.vuelo[vuelos.contador].terminal; | ||||
| 			archivo >> vuelos.vuelo[vuelos.contador].puertaEmb; | ||||
| 			archivo >> AUX; | ||||
| 			tIntToEstado(vuelos, AUX); | ||||
| 			getline(archivo, vuelos.vuelo[vuelos.contador].destino); | ||||
| 			vuelos.contador++; | ||||
| 			archivo >> vuelos.vuelo[vuelos.contador].numVuelo; | ||||
| 		} | ||||
| 		carga = true; | ||||
| 	} | ||||
| 	archivo.close(); | ||||
|  | ||||
| 	return carga; | ||||
| } | ||||
|  | ||||
| void tIntToEstado(tListaVuelos& vuelos, const int AUX) { | ||||
| 	switch (AUX) { | ||||
| 		case 0: vuelos.vuelo[vuelos.contador].estVuelo = embarcando; break; | ||||
| 		case 1: vuelos.vuelo[vuelos.contador].estVuelo = operado; break; | ||||
| 		case 2: vuelos.vuelo[vuelos.contador].estVuelo = retrasado; break; | ||||
| 		case 3: vuelos.vuelo[vuelos.contador].estVuelo = suspendido; break; | ||||
| 	} | ||||
| } | ||||
|  | ||||
| int menu() { | ||||
| 	int opc = 0; | ||||
|  | ||||
| 	cout << setw(40) << setfill('=') << "\n"; | ||||
| 	cout << "1.-Obtener informacion de un vuelo." << endl; | ||||
| 	cout << "2.-Actualizar estado del un vuelo." << endl; | ||||
| 	cout << "0.-Salir." << endl; | ||||
| 	cout << setw(40) << setfill('=') << "\n" << setw(0) << setfill(char(0)); | ||||
| 	 | ||||
| 	do { | ||||
| 		cout << "Introduzca una opcion: "; | ||||
| 		cin >> opc; | ||||
| 	} while (opc < 0 || opc > 2); | ||||
|  | ||||
| 	return opc; | ||||
| } | ||||
|  | ||||
| void ejecutarMenu(tListaVuelos& vuelos) { | ||||
| 	int opc = 1; | ||||
| 	while (opc != 0) { | ||||
| 		opc = menu(); | ||||
| 		switch (opc) { | ||||
| 		case 1: obtenerInfoVuelo(vuelos); break; | ||||
| 		case 2: actualizaEstVuelo(vuelos); break; | ||||
| 		case 0: guardar(vuelos); break; | ||||
| 		} | ||||
| 		system("cls"); | ||||
| 	} | ||||
| } | ||||
|  | ||||
| void guardar(tListaVuelos& vuelos) { | ||||
| 	ofstream archivo; | ||||
|  | ||||
| 	archivo.open("pendientes.txt"); | ||||
| 	if (!archivo.is_open()) { | ||||
| 		cout << "Error al guardar." << endl; | ||||
| 	} | ||||
| 	else { | ||||
| 		for (int i = 0; i < vuelos.contador; i++){ | ||||
| 			if ((vuelos.vuelo[i].estVuelo == retrasado) || (vuelos.vuelo[i].estVuelo == suspendido)) { | ||||
| 				archivo << vuelos.vuelo[i].numVuelo << " "; | ||||
| 				archivo << vuelos.vuelo[i].terminal << " "; | ||||
| 				archivo << vuelos.vuelo[i].puertaEmb << " "; | ||||
| 				archivo << vuelos.vuelo[i].estVuelo << ""; | ||||
| 				archivo << vuelos.vuelo[i].destino << endl; | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 	archivo.close(); | ||||
| } | ||||
|  | ||||
| void obtenerInfoVuelo(tListaVuelos& vuelos) { | ||||
| 	string numVuelo; | ||||
| 	int encontrado; | ||||
|  | ||||
| 	cout << "Introduzca numero de vuelo: "; | ||||
| 	cin >> numVuelo; | ||||
|  | ||||
| 	encontrado = buscarVuelo(vuelos, numVuelo); | ||||
| 	if (encontrado != -1) { | ||||
| 		mostrarVuelo(vuelos, numVuelo); | ||||
| 	} | ||||
| 	else { | ||||
| 		cout << "Vuelo no encontrado." << endl; | ||||
| 	} | ||||
| 	system("PAUSE"); | ||||
| } | ||||
|  | ||||
| void actualizaEstVuelo(tListaVuelos& vuelos) { | ||||
| 	string numVuelo; | ||||
| 	int encontrado; | ||||
| 	int nuevoEst; | ||||
|  | ||||
| 	do { | ||||
| 		cout << "Introduzca un numero de vuelo: "; | ||||
| 		cin >> numVuelo; | ||||
| 		encontrado = buscarVuelo(vuelos, numVuelo); | ||||
| 	} while (encontrado == -1); | ||||
|  | ||||
| 	cout << endl << "ESTADOS: (0)embarcando, (1)operado, (2)retrasado, (3)suspendido." << endl; | ||||
| 	cout << "Introduzca un nuevo estado: "; | ||||
| 	cin >> nuevoEst; | ||||
| 	actualizarVuelo(vuelos, encontrado, nuevoEst); | ||||
| 	cout << "Actualizado correctamente." << endl; | ||||
| 	system("PAUSE"); | ||||
| } | ||||
|  | ||||
| int buscarVuelo(tListaVuelos& vuelos, const string& numVuelo) { | ||||
| 	int pos = 0; | ||||
|  | ||||
| 	while ((vuelos.vuelo[pos].numVuelo != numVuelo) && (pos < vuelos.contador)) { | ||||
| 		pos++; | ||||
| 	} | ||||
| 	if (pos == vuelos.contador) { | ||||
| 		pos = -1; | ||||
| 	} | ||||
|  | ||||
| 	return pos; | ||||
| } | ||||
|  | ||||
| void mostrarVuelo(tListaVuelos& vuelos, const string& numVuelo) { | ||||
| 	int pos = buscarVuelo(vuelos, numVuelo); | ||||
|  | ||||
| 	cout << setw(50) << setfill('=') << "\n" << setfill(char(0)); | ||||
| 	cout << "Numero de vuelo: " << setw(15) << vuelos.vuelo[pos].numVuelo << endl | ||||
| 		<< "Terminal: " << setw(15) << vuelos.vuelo[pos].terminal << endl | ||||
| 		<< "Puerta de Embarque: " << setw(15) << vuelos.vuelo[pos].puertaEmb << endl | ||||
| 		<< "Estado: " << setw(15) << vuelos.vuelo[pos].estVuelo << endl | ||||
| 		<< "Destino: " << setw(15) << vuelos.vuelo[pos].numVuelo << endl; | ||||
| 	cout << setw(50) << setfill('=') << "\n" << setfill(char(0)); | ||||
| } | ||||
|  | ||||
| void actualizarVuelo(tListaVuelos& vuelos, const int& pos, const int& estadVuelo) { | ||||
| 	switch (estadVuelo) { | ||||
| 	case 0: vuelos.vuelo[pos].estVuelo = embarcando; break; | ||||
| 	case 1: vuelos.vuelo[pos].estVuelo = operado; break; | ||||
| 	case 2: vuelos.vuelo[pos].estVuelo = retrasado; break; | ||||
| 	case 3: vuelos.vuelo[pos].estVuelo = suspendido; break; | ||||
| 	} | ||||
| } | ||||
										
											Binary file not shown.
										
									
								
							| @@ -0,0 +1,9 @@ | ||||
| IB1231 A 2 1 Lisboa | ||||
| AF1231 A 3 1 Paris | ||||
| KLM1231 B 1 2 Amsterdam | ||||
| AL1236 A 3 1 Roma | ||||
| LU1301 A 5 0 Zagreb | ||||
| TP1302 B 2 2 Oporto | ||||
| AM1401 B 1 0 Cancun | ||||
| AV1411 B 3 3 Sao Paulo | ||||
| XXX | ||||
| @@ -0,0 +1,151 @@ | ||||
| // Eva Verd<72> Rodr<64>guez 51220965B | ||||
| // LAB: 10 | ||||
| // PTO: 12 | ||||
|  | ||||
| #include <iostream> | ||||
| #include <string> | ||||
| #include <fstream> | ||||
| #include <iomanip> | ||||
|  | ||||
| using namespace std; | ||||
|  | ||||
| const int MAX_APUNTES = 500; | ||||
|  | ||||
| typedef struct tFecha { | ||||
| 	int dia; | ||||
| 	int mes; | ||||
| 	int a<EFBFBD>o; | ||||
| }; | ||||
|  | ||||
| typedef struct tApunte { | ||||
| 	tFecha fecha; | ||||
| 	float impor; | ||||
| 	string concep; | ||||
| }; | ||||
|  | ||||
| typedef struct tCuenta { | ||||
| 	tApunte apunte [MAX_APUNTES]; | ||||
| 	int cont; | ||||
| }; | ||||
|  | ||||
| int menu(); | ||||
| void cargar(tCuenta & cuenta, string fichero); | ||||
| void Nomina(const tCuenta cuenta); | ||||
| void GastoLuzA<EFBFBD>o(const tCuenta cuenta, int a<EFBFBD>o); | ||||
| void mostrar(const tCuenta cuenta); | ||||
|  | ||||
| int main() { | ||||
| 	int opc, a<EFBFBD>o; | ||||
| 	tCuenta cuenta; | ||||
| 	cuenta.cont = 0; | ||||
| 	string fichero = "apuntes.txt"; | ||||
| 	opc = menu(); | ||||
| 	do{ | ||||
| 		switch (opc) { | ||||
| 		case 1: | ||||
| 			cargar(cuenta, fichero); | ||||
| 			break; | ||||
| 		case 2: | ||||
| 			Nomina(cuenta); | ||||
| 			break; | ||||
| 		case 3: | ||||
| 			cout << "Introduzca a<>o para calcular el gasto medio: "; | ||||
| 			cin >> a<EFBFBD>o; | ||||
| 			GastoLuzA<EFBFBD>o(cuenta, a<EFBFBD>o); | ||||
| 			break; | ||||
| 		case 4: | ||||
| 			mostrar(cuenta); | ||||
| 			break; | ||||
| 		} | ||||
| 		opc = menu(); | ||||
| 	} while (opc != 0); | ||||
|  | ||||
| 	system("pause"); | ||||
| 	return 0; | ||||
| } | ||||
|  | ||||
| int menu() { | ||||
| 	int opc; | ||||
| 	do { | ||||
| 		cout << "Elige una opci<63>n: " << endl; | ||||
| 		cout << "1 Cargar cuenta de fichero" << endl; | ||||
| 		cout << "2 Importe de la primera n<>mina" << endl; | ||||
| 		cout << "3 Gasto medio de luz en un a<>o" << endl; | ||||
| 		cout << "4 Mostrar por pantalla" << endl; | ||||
| 		cout << "0 Salir" << endl; | ||||
| 		cin >> opc; | ||||
| 	} while (opc < 0 || opc > 4); | ||||
|  | ||||
| 	return opc; | ||||
| } | ||||
|  | ||||
| void cargar(tCuenta & cuenta, string fichero){ | ||||
| 	ifstream archivo; | ||||
| 	archivo.open(fichero); | ||||
| 	int aux; | ||||
| 	if (archivo.is_open()) { | ||||
| 		archivo >> aux; | ||||
| 		while (aux != -1 && cuenta.cont != MAX_APUNTES) { | ||||
| 			cuenta.apunte[cuenta.cont].fecha.dia = aux; | ||||
| 			archivo >> cuenta.apunte[cuenta.cont].fecha.mes; | ||||
| 			archivo >> cuenta.apunte[cuenta.cont].fecha.a<EFBFBD>o; | ||||
| 			archivo >> cuenta.apunte[cuenta.cont].impor; | ||||
| 			archivo >> cuenta.apunte[cuenta.cont].concep; | ||||
| 			archivo >> aux; | ||||
| 			cuenta.cont++; | ||||
| 		} | ||||
| 		archivo.close(); | ||||
| 	} | ||||
| 	else { | ||||
| 		cout << "Archivo no encontrado" << endl; | ||||
| 	} | ||||
| } | ||||
|  | ||||
| void Nomina(const tCuenta cuenta) { | ||||
| 	float nomina = 0; | ||||
| 	bool found = false; | ||||
| 	int i = 0; | ||||
| 	while (i < cuenta.cont && !found) { | ||||
| 		if (cuenta.apunte[i].concep == "Salario") { | ||||
| 			nomina = cuenta.apunte[i].impor; | ||||
| 			found = true; | ||||
| 		} | ||||
| 		else { | ||||
| 			i++; | ||||
| 		} | ||||
| 	} | ||||
| 	if (nomina != 0) { | ||||
| 		cout << "El importe de la primera nomina es: " << fixed << setprecision(2) << nomina << " euros." << endl; | ||||
| 	} | ||||
| 	else { | ||||
| 		cout << "No hay salarios" << endl; | ||||
| 	} | ||||
| 	 | ||||
| } | ||||
|  | ||||
| void GastoLuzA<EFBFBD>o(const tCuenta cuenta, int a<EFBFBD>o) { | ||||
| 	float numLuz = 0; | ||||
| 	float sum = 0; | ||||
| 	float media = 0; | ||||
| 	for (int i = 0; i < cuenta.cont; i++) { | ||||
| 		if (cuenta.apunte[i].fecha.a<EFBFBD>o == a<EFBFBD>o && cuenta.apunte[i].concep == "Luz") { | ||||
| 			sum += cuenta.apunte[i].impor; | ||||
| 			numLuz++; | ||||
| 		} | ||||
| 	} | ||||
| 	media = sum / numLuz; | ||||
| 	media = media * -1; | ||||
| 	cout << " Gasto medio del a<>o " << a<EFBFBD>o << " es: " << media << endl; | ||||
| } | ||||
|  | ||||
| void mostrar(const tCuenta cuenta) { | ||||
| 	for (int i = 0; i < cuenta.cont; i++){ | ||||
| 	 | ||||
| 		cout << setfill('0') << setw(2) << internal << cuenta.apunte[i].fecha.dia <<" " | ||||
| 			 << setw(2) << cuenta.apunte[i].fecha.mes << " " | ||||
| 			 << setfill(' ') << setw(5) << cuenta.apunte[i].fecha.a<EFBFBD>o | ||||
| 			 << right << fixed << setprecision(2) << setw(10) << cuenta.apunte[i].impor  << " " | ||||
| 			 << setw(10) << left << cuenta.apunte[i].concep << " " << endl; | ||||
| 		 | ||||
| 	} | ||||
| } | ||||
| @@ -0,0 +1,185 @@ | ||||
| //Examen Febrero 2017 - Grupos: A, E, D y G. | ||||
| //Fernando M<>ndez Torrubiano | ||||
|  | ||||
| #include <iostream> | ||||
| #include <string> | ||||
| #include <fstream> | ||||
| #include <iomanip> | ||||
| using namespace std; | ||||
|  | ||||
|  | ||||
| //Constantes: | ||||
| const int MAX_APUNTES = 500; | ||||
|  | ||||
|  | ||||
| //Tipos: | ||||
| typedef struct { | ||||
| 	int dia; | ||||
| 	int mes; | ||||
| 	int anio; | ||||
| }tFecha; | ||||
|  | ||||
| typedef struct { | ||||
| 	tFecha fecha; | ||||
| 	float importe; | ||||
| 	string concepto; | ||||
| }tApunte; | ||||
|  | ||||
| typedef tApunte tApuntes[MAX_APUNTES]; | ||||
|  | ||||
| typedef struct { | ||||
| 	tApuntes apunte; | ||||
| 	int contador; | ||||
| }tCuenta; | ||||
|  | ||||
|  | ||||
| //Funciones: | ||||
| void inicializa(tCuenta&); | ||||
| bool cargar(tCuenta&); | ||||
| int menu(); | ||||
| void ejecutarMenu(tCuenta&); | ||||
| float nomina(tCuenta&); | ||||
| float gastoLuz(tCuenta&, const int&); | ||||
| void mostrar(tCuenta&); | ||||
|  | ||||
|  | ||||
|  | ||||
| int main() { | ||||
| 	tCuenta cuentas; | ||||
|  | ||||
| 	ejecutarMenu(cuentas); | ||||
|  | ||||
| 	return 0; | ||||
| } | ||||
|  | ||||
| void inicializa(tCuenta& cuentas) { | ||||
| 	cuentas.contador = 0; | ||||
| 	for (int i = 0; i < MAX_APUNTES; i++) { | ||||
| 		cuentas.apunte[i].fecha.dia = 0; | ||||
| 		cuentas.apunte[i].fecha.mes = 0; | ||||
| 		cuentas.apunte[i].fecha.anio = 0; | ||||
| 		cuentas.apunte[i].importe = 0; | ||||
| 		cuentas.apunte[i].concepto = ""; | ||||
| 	} | ||||
| } | ||||
|  | ||||
| bool cargar(tCuenta& cuentas) { | ||||
| 	bool carga = false; | ||||
| 	string nombreFichero; | ||||
| 	ifstream archivo; | ||||
|  | ||||
| 	inicializa(cuentas); | ||||
|  | ||||
| 	cout << "Introduzca nombre del archivo: "; | ||||
| 	cin >> nombreFichero; | ||||
| 	nombreFichero += ".txt"; | ||||
| 	archivo.open(nombreFichero); | ||||
| 	if (!archivo.is_open()) { | ||||
| 		cout << "Error al cargar el archivo." << endl; | ||||
| 		carga = false; | ||||
| 	} | ||||
| 	else { | ||||
| 		archivo >> cuentas.apunte[cuentas.contador].fecha.dia; | ||||
| 		while ((cuentas.apunte[cuentas.contador].fecha.dia != -1) && (cuentas.contador < MAX_APUNTES)) { | ||||
| 			archivo >> cuentas.apunte[cuentas.contador].fecha.mes; | ||||
| 			archivo >> cuentas.apunte[cuentas.contador].fecha.anio; | ||||
| 			archivo >> cuentas.apunte[cuentas.contador].importe; | ||||
| 			archivo >> cuentas.apunte[cuentas.contador].concepto; | ||||
| 			cuentas.contador++; | ||||
| 			archivo >> cuentas.apunte[cuentas.contador].fecha.dia; | ||||
| 		} | ||||
| 		carga = true; | ||||
| 	} | ||||
| 	archivo.close(); | ||||
|  | ||||
| 	return carga; | ||||
| } | ||||
|  | ||||
| int menu() { | ||||
| 	int opc = 0; | ||||
|  | ||||
| 	cout << setw(35) << setfill('=') << "\n" << setw(0) << setfill(char(0)); | ||||
| 	cout << "1.-Cargar cuenta de fichero." << endl; | ||||
| 	cout << "2.-Importe de la primera nomina." << endl; | ||||
| 	cout << "3.-Gasto medio de la luz en un anio." << endl; | ||||
| 	cout << "4.-Mostrar por pantalla." << endl; | ||||
| 	cout << "0.-Salir." << endl; | ||||
| 	cout << setw(35) << setfill('=') << "\n" << setw(0) << setfill(char(0)); | ||||
|  | ||||
| 	do { | ||||
| 		cout << "Introduzca una opcion: "; | ||||
| 		cin >> opc; | ||||
| 	} while ((opc < 0) || (opc > 4)); | ||||
|  | ||||
| 	return opc; | ||||
| } | ||||
|  | ||||
| void ejecutarMenu(tCuenta& cuentas) { | ||||
| 	int opc = 1; | ||||
| 	int anio = 0; | ||||
|  | ||||
| 	while (opc != 0) { | ||||
| 		opc = menu(); | ||||
| 		switch (opc) { | ||||
| 		case 1:  | ||||
| 			if (cargar(cuentas)) {  | ||||
| 				cout << "Cargado correctamente." << endl;  | ||||
| 			} | ||||
| 			else { | ||||
| 				cout << "Vuelva a intentarlo." << endl;  | ||||
| 			} break; | ||||
| 		case 2: cout << "Primera nomina: " << nomina(cuentas) << endl; break; | ||||
| 		case 3: cout << "Introduzca un anio: "; | ||||
| 			cin >> anio; | ||||
| 			cout << "Gasto en " << anio << ": " << gastoLuz(cuentas, anio) << endl; break; | ||||
| 		case 4: mostrar(cuentas); break; | ||||
| 		case 0: break; | ||||
| 		} | ||||
| 		system("PAUSE"); | ||||
| 		system("cls"); | ||||
| 	} | ||||
| } | ||||
|  | ||||
| float nomina(tCuenta& cuentas) { | ||||
| 	bool encontrado = false; | ||||
| 	int i = 0; | ||||
|  | ||||
| 	while ((!encontrado) && (i < cuentas.contador)) { | ||||
| 		if (cuentas.apunte[i].concepto == "Salario") { | ||||
| 			encontrado = true; | ||||
| 		} | ||||
| 		else { | ||||
| 			i++; | ||||
| 		} | ||||
| 	} | ||||
| 	return cuentas.apunte[i].importe; | ||||
| } | ||||
|  | ||||
| float gastoLuz(tCuenta& cuentas, const int& anio) { | ||||
| 	int i = 0; | ||||
| 	float gasto = 0; | ||||
| 	float importePositivo = 0; | ||||
|  | ||||
| 	while (i < cuentas.contador) { | ||||
| 		if ((cuentas.apunte[i].concepto == "Luz") && (cuentas.apunte[i].fecha.anio == anio)) { | ||||
| 			importePositivo = -1 * cuentas.apunte[i].importe; | ||||
| 			gasto += importePositivo; | ||||
| 		} | ||||
| 		i++; | ||||
| 	} | ||||
|  | ||||
| 	return gasto; | ||||
| } | ||||
|  | ||||
| void mostrar(tCuenta& cuentas) { | ||||
| 	cout << "FECHA" << "     " << "IMPORTE" << "  " << right << "CONCEPTO" << endl; | ||||
| 	cout << setw(35) << setfill('-') << "\n" << setw(0) << setfill(char(0)); | ||||
| 	for (int i = 0; i < cuentas.contador; i++) { | ||||
| 		cout << cuentas.apunte[i].fecha.dia << "/" | ||||
| 			<< cuentas.apunte[i].fecha.mes << "/" | ||||
| 			<< cuentas.apunte[i].fecha.anio << "     "  << left | ||||
| 			<< cuentas.apunte[i].importe << "  " << right | ||||
| 			<< cuentas.apunte[i].concepto << endl; | ||||
| 	} | ||||
| 	cout << setw(35) << setfill('-') << "\n" << setw(0) << setfill(char(0)); | ||||
| } | ||||
| @@ -0,0 +1,185 @@ | ||||
| //Examen Febrero 2017 - Grupos A, E, D y G. | ||||
| //Fernando M<>ndez Torrubiano | ||||
|  | ||||
| #include <iostream> | ||||
| #include <string> | ||||
| #include <fstream> | ||||
| #include <iomanip> | ||||
| using namespace std; | ||||
|  | ||||
| //Constantes: | ||||
| const int MAX_APUNTES = 500; | ||||
|  | ||||
| //Tipos: | ||||
| typedef struct tFecha { | ||||
| 	int dia, mes, anio; | ||||
| }; | ||||
| typedef struct tApunte { | ||||
| 	tFecha fecha; | ||||
| 	float importe; | ||||
| 	string concepto; | ||||
| }; | ||||
| typedef tApunte tApuntes[MAX_APUNTES]; | ||||
| typedef struct tCuenta { | ||||
| 	tApuntes apunte; | ||||
| 	int contador; | ||||
| }; | ||||
|  | ||||
| //Funciones: | ||||
| void inicializa(tCuenta&); | ||||
| bool cargar(tCuenta&); | ||||
| float nomina(tCuenta&); | ||||
| float gastoMedio(tCuenta&, const int&); | ||||
| void mostrar(tCuenta&); | ||||
| void ejecutarMenu(tCuenta&); | ||||
| int menu(); | ||||
|  | ||||
|  | ||||
| int main() { | ||||
| 	tCuenta cuenta; | ||||
|  | ||||
| 	ejecutarMenu(cuenta); | ||||
|  | ||||
| 	return 0; | ||||
| } | ||||
|  | ||||
| void inicializa(tCuenta& cuenta) { | ||||
| 	cuenta.contador = 0; | ||||
| 	for (int i = 0; i < MAX_APUNTES; i++){ | ||||
| 		cuenta.apunte[i].fecha.dia = 0; | ||||
| 		cuenta.apunte[i].fecha.mes = 0; | ||||
| 		cuenta.apunte[i].fecha.anio = 0; | ||||
| 		cuenta.apunte[i].importe = 0; | ||||
| 		cuenta.apunte[i].concepto = ""; | ||||
| 	} | ||||
| } | ||||
|  | ||||
| bool cargar(tCuenta& cuenta) { | ||||
| 	bool carga = false; | ||||
| 	ifstream archivo; | ||||
| 	string nomArchivo; | ||||
|  | ||||
| 	inicializa(cuenta); | ||||
|  | ||||
| 	cout << "Introduzca nombre del archivo (sin extension): "; | ||||
| 	cin >> nomArchivo; | ||||
| 	nomArchivo += ".txt"; | ||||
| 	archivo.open(nomArchivo); | ||||
| 	if (!archivo.is_open()){ | ||||
| 		cout << "Error al cargar el archivo." << endl; | ||||
| 		carga = false; | ||||
| 	} | ||||
| 	else { | ||||
| 		archivo >> cuenta.apunte[cuenta.contador].fecha.dia; | ||||
| 		while ((cuenta.apunte[cuenta.contador].fecha.dia != -1) && (cuenta.contador < MAX_APUNTES)) { | ||||
| 			archivo >> cuenta.apunte[cuenta.contador].fecha.mes; | ||||
| 			archivo >> cuenta.apunte[cuenta.contador].fecha.anio; | ||||
| 			archivo >> cuenta.apunte[cuenta.contador].importe; | ||||
| 			archivo >> cuenta.apunte[cuenta.contador].concepto; | ||||
| 			cuenta.contador++; | ||||
| 			archivo >> cuenta.apunte[cuenta.contador].fecha.dia; | ||||
| 		} | ||||
| 		carga = true; | ||||
| 	} | ||||
| 	archivo.close(); | ||||
|  | ||||
| 	return carga; | ||||
| } | ||||
|  | ||||
| float nomina(tCuenta& cuenta) { | ||||
| 	bool encontrado = false; | ||||
| 	int i = 0; | ||||
| 	float nomina = 0; | ||||
|  | ||||
| 	while ((!encontrado) && (i < cuenta.contador)) { | ||||
| 		if (cuenta.apunte[i].concepto == "Salario") { | ||||
| 			nomina = cuenta.apunte[i].importe; | ||||
| 			encontrado = true; | ||||
| 		} | ||||
| 		else { | ||||
| 			i++; | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return nomina; | ||||
| } | ||||
|  | ||||
| float gastoMedio(tCuenta& cuenta, const int& anio) { | ||||
| 	float gasto = 0; | ||||
| 	int i = 0; | ||||
|  | ||||
| 	while ((i < cuenta.contador)) { | ||||
| 		if ((cuenta.apunte[i].fecha.anio == anio) && (cuenta.apunte[i].concepto == "Luz")) { | ||||
| 			gasto += (-1 * cuenta.apunte[i].importe); | ||||
| 		} | ||||
| 		i++; | ||||
| 	} | ||||
|  | ||||
| 	return gasto; | ||||
| } | ||||
|  | ||||
| void mostrar(tCuenta& cuenta) { | ||||
| 	cout << setw(2) << right << "DIA" | ||||
| 		<< setw(5) << "MES" | ||||
| 		<< setw(10) << "ANIO" | ||||
| 		<< setw(10) << "IMPORTE" | ||||
| 		<< setw(15) << "CONCEPTO" << endl; | ||||
| 	cout << setw(50) << setfill('=') << "\n" << setfill(char(0)); | ||||
| 	for (int i = 0; i < cuenta.contador; i++){ | ||||
| 		cout << setw(2) << right << cuenta.apunte[i].fecha.dia | ||||
| 			<< setw(5) << cuenta.apunte[i].fecha.mes | ||||
| 			<< setw(10) << cuenta.apunte[i].fecha.anio | ||||
| 			<< setw(10) << cuenta.apunte[i].importe | ||||
| 			<< setw(15) << cuenta.apunte[i].concepto << endl; | ||||
| 	} | ||||
| 	cout << setw(50) << setfill('=') << "\n" << setfill(char(0)); | ||||
| } | ||||
|  | ||||
| void ejecutarMenu(tCuenta& cuenta) { | ||||
| 	int opc = 1; | ||||
| 	float anio; | ||||
|  | ||||
| 	while (opc != 0) { | ||||
| 		opc = menu(); | ||||
| 		switch (opc){ | ||||
| 		case 0: break; | ||||
| 		case 1:  | ||||
| 			if (cargar(cuenta)) { | ||||
| 				cout << "Cargado correctamente." << endl; | ||||
| 			} | ||||
| 			else { | ||||
| 				cout << "No se ha podido cargar el archivo." << endl; | ||||
| 			} | ||||
| 			break; | ||||
| 		case 2: cout << "El importe de la primera nomina es: " << nomina(cuenta) << endl; break; | ||||
| 		case 3:  | ||||
| 			cout << "Introduzca un anio: "; | ||||
| 			cin >> anio; | ||||
| 			cout << "El gasto medio de la luz en el anio " << anio << " fue: " << gastoMedio(cuenta, anio) << endl; break; | ||||
| 		case 4: mostrar(cuenta); break; | ||||
| 		default: | ||||
| 			break; | ||||
| 		} | ||||
| 		system("PAUSE"); | ||||
| 		system("cls"); | ||||
| 	} | ||||
| } | ||||
|  | ||||
| int menu() { | ||||
| 	int opc = 0; | ||||
|  | ||||
| 	cout << setw(25) << setfill('=') << "MENU" << setw(25) << "\n" << setfill(char(0)); | ||||
| 	cout << "1.-Cargar cuenta de un fichero." << endl; | ||||
| 	cout << "2.-Importe de la ultima nomina." << endl; | ||||
| 	cout << "3.-Gasto medio de luz en un anio." << endl; | ||||
| 	cout << "4.-Mostrar por pantalla" << endl; | ||||
| 	cout << "0.-Salir" << endl; | ||||
| 	cout << setw(50) << setfill('=') <<"\n" << setfill(char(0)); | ||||
|  | ||||
| 	do { | ||||
| 		cout << "Introduzca una opcion: "; | ||||
| 		cin >> opc; | ||||
| 	} while (opc < 0 || opc>4); | ||||
|  | ||||
| 	return opc; | ||||
| } | ||||
										
											Binary file not shown.
										
									
								
							| @@ -0,0 +1,13 @@ | ||||
| 12 01 2015  500.22 Ingreso | ||||
| 12 01 2015  1235.45 Salario | ||||
| 23 01 2015  -324.24 Impuestos | ||||
| 03 02 2015  -35.00 Transferencia | ||||
| 04 02 2015  -1214.12 Transferencia | ||||
| 23 02 2015  -83.15 Luz | ||||
| 22 03 2015  -20.00 Tarjeta | ||||
| 12 05 2015  -124.32 Luz | ||||
| 23 02 2016  -23.54 Luz | ||||
| 03 03 2016  -20.00 Devoluci<63>n | ||||
| 05 03 2016  1111.01 Salario | ||||
| 05 05 2016  1300.01 Salario | ||||
| -1  | ||||
| @@ -0,0 +1,258 @@ | ||||
| //Examen Febrero 2017 - Grupos B, C y D | ||||
| //Fernando M<>ndez Torrubiano | ||||
|  | ||||
| #include <iostream> | ||||
| #include <string> | ||||
| #include <fstream> | ||||
| #include <iomanip> | ||||
| using namespace std; | ||||
|  | ||||
| //Constantes: | ||||
| const int N = 10; | ||||
|  | ||||
| //Tipos: | ||||
| typedef struct tEquipo { | ||||
| 	string nombre; | ||||
| 	int puntos; | ||||
| }; | ||||
| typedef struct tJornada { | ||||
| 	string local, visitante; | ||||
| 	int golesLocal, golesVisitante; | ||||
| }; | ||||
| typedef tEquipo tEquipos[N]; | ||||
| typedef tJornada tPartidos[N / 2]; | ||||
| typedef struct tListaEquipos { | ||||
| 	tEquipos equipo; | ||||
| 	tPartidos partido; | ||||
| 	//En este examen no se necesita un contador. | ||||
| }; | ||||
|  | ||||
| //Funciones: | ||||
| void inicia(tListaEquipos&); | ||||
| bool cargarLiga(tListaEquipos&); | ||||
| bool cargarJornada(tListaEquipos&); | ||||
| void mostrarLiga(tListaEquipos&); | ||||
| void mostrarJornada(tListaEquipos&); | ||||
| int menu(); | ||||
| void ejecutarMenu(tListaEquipos&); | ||||
| bool actualizarLiga(tListaEquipos&); | ||||
| void mostrarPrimero(tListaEquipos&); | ||||
| void guardarLiga(tListaEquipos&); | ||||
| void ordenar(tListaEquipos&); | ||||
|  | ||||
| int main() { | ||||
| 	tListaEquipos equipos; | ||||
|  | ||||
| 	inicia(equipos); | ||||
| 	if ((cargarLiga(equipos)) && (cargarJornada(equipos))) { | ||||
| 		ejecutarMenu(equipos); | ||||
| 		guardarLiga(equipos); | ||||
| 	} | ||||
| 	else { | ||||
| 		cout << "FIN DEL PROGRAMA." << endl; | ||||
| 		system("PAUSE"); | ||||
| 	} | ||||
|  | ||||
| 	return 0; | ||||
| } | ||||
|  | ||||
| void inicia(tListaEquipos& equipos) { | ||||
| 	for (int i = 0; i < N; i++){ | ||||
| 		equipos.equipo[i].nombre = ""; | ||||
| 		equipos.equipo[i].puntos = 0; | ||||
| 		if (i < N / 2) { | ||||
| 			equipos.partido[i].local = ""; | ||||
| 			equipos.partido[i].visitante = ""; | ||||
| 			equipos.partido[i].golesLocal = 0; | ||||
| 			equipos.partido[i].golesVisitante = 0; | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
| bool cargarLiga(tListaEquipos& equipos) { | ||||
| 	bool carga = false; | ||||
| 	ifstream archivo; | ||||
| 	 | ||||
| 	archivo.open("liga.txt"); | ||||
| 	if (!archivo.is_open()) { | ||||
| 		cout << "Error al cargar la liga." << endl; | ||||
| 		carga = false; | ||||
| 	} | ||||
| 	else { | ||||
| 		for (int i = 0; i < N; i++) { | ||||
| 			archivo >> equipos.equipo[i].nombre; | ||||
| 			archivo >> equipos.equipo[i].puntos; | ||||
| 		} | ||||
| 		ordenar(equipos); | ||||
| 		carga = true; | ||||
| 	} | ||||
| 	archivo.close(); | ||||
|  | ||||
| 	return carga; | ||||
| } | ||||
|  | ||||
| void ordenar(tListaEquipos& equipos) { | ||||
| 	string auxiliar; | ||||
| 	int aux, pos; | ||||
|  | ||||
| 	for (int i = 0; i < N; i++) { | ||||
| 		pos = i; | ||||
| 		while ((equipos.equipo[pos].puntos > equipos.equipo[pos - 1].puntos) && (pos > 0)) { | ||||
| 			auxiliar = equipos.equipo[pos].nombre; | ||||
| 			equipos.equipo[pos].nombre = equipos.equipo[pos - 1].nombre; | ||||
| 			equipos.equipo[pos - 1].nombre = auxiliar; | ||||
|  | ||||
| 			aux = equipos.equipo[pos].puntos; | ||||
| 			equipos.equipo[pos].puntos = equipos.equipo[pos - 1].puntos; | ||||
| 			equipos.equipo[pos - 1].puntos = aux; | ||||
|  | ||||
| 			pos--; | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
| bool cargarJornada(tListaEquipos& equipos) { | ||||
| 	bool carga = false; | ||||
| 	ifstream archivo; | ||||
|  | ||||
| 	archivo.open("jornada.txt"); | ||||
| 	if (!archivo.is_open()) { | ||||
| 		cout << "Error al cargar la jornada." << endl; | ||||
| 		carga = false; | ||||
| 	} | ||||
| 	else { | ||||
| 		for (int i = 0; i < N / 2; i++) { | ||||
| 			archivo >> equipos.partido[i].local; | ||||
| 			archivo >> equipos.partido[i].golesLocal; | ||||
| 			archivo >> equipos.partido[i].visitante; | ||||
| 			archivo >> equipos.partido[i].golesVisitante; | ||||
| 		} | ||||
| 		carga = true; | ||||
| 	} | ||||
| 	archivo.close(); | ||||
|  | ||||
| 	return carga; | ||||
| } | ||||
|  | ||||
| void mostrarLiga(tListaEquipos& equipos) { | ||||
| 	cout << setw(7) << right << "EQUIPO" << setw(15) << right << "PUNTOS" << endl; | ||||
| 	cout << setfill('=') << setw(25) << "\n" << setfill(char(0)) << setw(0); | ||||
| 	for (int i = 0; i < N; i++){ | ||||
| 		cout << setw(7) << right << equipos.equipo[i].nombre  | ||||
| 			<< setw(15) << right << equipos.equipo[i].puntos << endl; | ||||
| 	} | ||||
| 	cout << setfill('=') << setw(25) << "\n" << setfill(char(0)) << setw(0); | ||||
| } | ||||
|  | ||||
| void mostrarJornada(tListaEquipos& equipos) { | ||||
| 	cout << setw(5) << right << "LOCAL" << setw(10) << "GOLES" << setw(20) << "VISITANTE" << setw(10) << "GOLES" << endl; | ||||
| 	cout << setfill('=') << setw(50) << "\n" << setfill(char(0)) << setw(0); | ||||
| 	for (int i = 0; i < N/2; i++) { | ||||
| 		cout << setw(4) << right << equipos.partido[i].local << left | ||||
| 			<< setw(2) << right << setw(10) << equipos.partido[i].golesLocal << left | ||||
| 			<< setw(4) << right <<setw(20) << equipos.partido[i].visitante << left | ||||
| 			<< setw(2) << right <<setw(10) << equipos.partido[i].golesVisitante << endl; | ||||
| 	} | ||||
| 	cout << setfill('=') << setw(50) << "\n" << setfill(char(0)) << setw(0); | ||||
| } | ||||
|  | ||||
| int menu() { | ||||
| 	int opc = 0; | ||||
|  | ||||
| 	cout << setw(35) << setfill('=') << "\n" << setfill(char(0)) << setw(0); | ||||
| 	cout << "1.-MOSTRAR CLASIFICACION DE LA LIGA." << endl; | ||||
| 	cout << "2.-MOSTRAR ULTIMA JORNADA." << endl; | ||||
| 	cout << "3.-ACTUALIZAR LIGA." << endl; | ||||
| 	cout << "4.-MOSTRAR PRIMER CLASIFICADO." << endl; | ||||
| 	cout << "0.-SALIR." << endl; | ||||
| 	cout << setw(35) << setfill('=') << "\n" << setfill(char(0)) << setw(0); | ||||
|  | ||||
| 	do { | ||||
| 		cout << "Introduzca una opcion: "; | ||||
| 		cin >> opc; | ||||
| 	} while (opc < 0 || opc > 4); | ||||
|  | ||||
| 	return opc; | ||||
| } | ||||
|  | ||||
| void ejecutarMenu(tListaEquipos& equipos) { | ||||
| 	int opc = 1; | ||||
|  | ||||
| 	while (opc != 0) { | ||||
| 		opc = menu(); | ||||
| 		switch (opc) { | ||||
| 		case 1: mostrarLiga(equipos); break; | ||||
| 		case 2: mostrarJornada(equipos); break; | ||||
| 		case 3: if (actualizarLiga(equipos)) { cout << "ACTUALIZADA CORRECTAMENTE." << endl; } | ||||
| 				else { cout << "ERROR AL ACTUALIZAR." << endl; } break; | ||||
| 		case 4: mostrarPrimero(equipos); break; | ||||
| 		case 0: break; | ||||
| 		} | ||||
| 		system("Pause"); | ||||
| 		system("cls"); | ||||
| 	} | ||||
| } | ||||
|  | ||||
| bool actualizarLiga(tListaEquipos& equipos) { | ||||
| 	bool encontrado = false; | ||||
| 	int j = 0; | ||||
|  | ||||
| 	for (int i = 0; i < N/2; i++){ | ||||
| 		if (equipos.partido[i].golesLocal > equipos.partido[i].golesVisitante) { | ||||
| 			j = 0; | ||||
| 			while (!encontrado && j < N) { | ||||
| 				if (equipos.equipo[j].nombre == equipos.partido[i].local) { | ||||
| 					equipos.equipo[j].puntos += 3; | ||||
| 					encontrado = true; | ||||
| 				} | ||||
| 				j++; | ||||
| 			} | ||||
| 		} | ||||
| 		if (equipos.partido[i].golesLocal < equipos.partido[i].golesVisitante) { | ||||
| 			j = 0; | ||||
| 			while (!encontrado && j < N) { | ||||
| 				if (equipos.equipo[j].nombre == equipos.partido[i].visitante) { | ||||
| 					equipos.equipo[j].puntos += 3; | ||||
| 				} | ||||
| 				j++; | ||||
| 			} | ||||
| 		} | ||||
| 		if (equipos.partido[i].golesLocal == equipos.partido[i].golesVisitante) { | ||||
| 			j = 0; | ||||
| 			while (j < N) { | ||||
| 				if (equipos.equipo[j].nombre == equipos.partido[i].local) { | ||||
| 					equipos.equipo[j].puntos += 1; | ||||
| 				} | ||||
| 				if (equipos.equipo[j].nombre == equipos.partido[i].visitante) { | ||||
| 					equipos.equipo[j].puntos += 1; | ||||
| 				} | ||||
| 				j++; | ||||
| 			} | ||||
| 			encontrado = true; | ||||
| 		} | ||||
| 	} | ||||
| 	ordenar(equipos); | ||||
|  | ||||
| 	return encontrado; | ||||
| } | ||||
|  | ||||
| void mostrarPrimero(tListaEquipos& equipos) { | ||||
| 	ordenar(equipos); | ||||
| 	cout << "Primer equipo en la liga: " << equipos.equipo[0].nombre << " con " << equipos.equipo[0].puntos << " puntos." << endl; | ||||
| } | ||||
|  | ||||
| void guardarLiga(tListaEquipos& equipos) { | ||||
| 	ofstream archivo; | ||||
|  | ||||
| 	archivo.open("liga.txt"); | ||||
| 	if (!archivo.is_open()) { | ||||
| 		cout << "Error al guardar los datos." << endl; | ||||
| 	} | ||||
| 	else { | ||||
| 		for (int i = 0; i < N; i++) { | ||||
| 			archivo << equipos.equipo[i].nombre << " "; | ||||
| 			archivo << equipos.equipo[i].puntos << endl; | ||||
| 		} | ||||
| 	} | ||||
| 	archivo.close(); | ||||
| } | ||||
										
											Binary file not shown.
										
									
								
							| @@ -0,0 +1,5 @@ | ||||
| ATM 5 Celta 0 | ||||
| DEP 3 BCN 1 | ||||
| GET2 4 GET1 4 | ||||
| RM 0 ZARA 9  | ||||
| VAL 1 Sevilla 1 | ||||
| @@ -0,0 +1,10 @@ | ||||
| CELTA 42 | ||||
| GET1 13 | ||||
| ATM 53 | ||||
| DEP 31 | ||||
| BCN 53 | ||||
| GET2 15 | ||||
| ZARA 16 | ||||
| Sevilla 13 | ||||
| VAL 15 | ||||
| RM 49 | ||||
| @@ -0,0 +1,282 @@ | ||||
| //Examen Febrero 2018 - Grupos C, G e I | ||||
| //Fernando M<>ndez Torrubiano | ||||
| //Versi<73>n 2 | ||||
|  | ||||
| #include <iostream> | ||||
| #include <string> | ||||
| #include <fstream> | ||||
| #include <iomanip> | ||||
| using namespace std; | ||||
|  | ||||
| //Constantes: | ||||
| const int MAX_NAV = 24; | ||||
|  | ||||
| //Tipos: | ||||
| typedef struct tNavio { | ||||
| 	string nombre; | ||||
| 	string empresa; | ||||
| 	float eslora; | ||||
| 	float toneladas; | ||||
| 	bool peaje; | ||||
| }; | ||||
| typedef tNavio tNavios[MAX_NAV]; | ||||
| typedef struct tListaNavios { | ||||
| 	tNavios navio; | ||||
| 	int contador; | ||||
| }; | ||||
|  | ||||
| //Funciones: | ||||
| void inicializa(tListaNavios&); | ||||
| bool cargar(tListaNavios&); | ||||
| void muestraNavios(tListaNavios&); | ||||
| bool crearNavio(tListaNavios&); | ||||
| bool insertarNavio(tListaNavios&, tNavio&); | ||||
| bool cobrarNavio(tListaNavios&, const string&); | ||||
| float peajeNavio(tListaNavios&, const int&); | ||||
| float peajePagado(tListaNavios&); | ||||
| void ejecutarMenu(tListaNavios&); | ||||
| int menu(); | ||||
| bool guardar(tListaNavios&); | ||||
|  | ||||
|  | ||||
| int main() { | ||||
| 	tListaNavios navios; | ||||
|  | ||||
| 	if (cargar(navios)) { | ||||
| 		ejecutarMenu(navios); | ||||
| 		if (guardar(navios)) { | ||||
| 			cout << "Guardado correctamente." << endl; | ||||
| 		} | ||||
| 		else { | ||||
| 			cout << "Error al guardar el archivo." << endl; | ||||
| 		} | ||||
| 	} | ||||
| 	else { | ||||
| 		cout << "Fin del programa." << endl; | ||||
| 	} | ||||
|  | ||||
| 	return 0; | ||||
| } | ||||
|  | ||||
| void inicializa(tListaNavios& navios) { | ||||
| 	navios.contador = 0; | ||||
| 	for (int i = 0; i < MAX_NAV; i++){ | ||||
| 		navios.navio[i].nombre = ""; | ||||
| 		navios.navio[i].empresa = ""; | ||||
| 		navios.navio[i].eslora = 0; | ||||
| 		navios.navio[i].toneladas = 0; | ||||
| 		navios.navio[i].peaje = false; | ||||
| 	} | ||||
| } | ||||
|  | ||||
| bool cargar(tListaNavios& navios) { | ||||
| 	bool cargado = false; | ||||
| 	ifstream archivo; | ||||
| 	string aux = ""; | ||||
|  | ||||
| 	inicializa(navios); | ||||
| 	archivo.open("navios.txt"); | ||||
| 	if(!archivo.is_open()){ | ||||
| 		cout << "No se ha podido cargar el archivo." << endl; | ||||
| 		cargado = false; | ||||
| 	} | ||||
| 	else { | ||||
| 		archivo >> navios.navio[navios.contador].nombre; | ||||
| 		while ((navios.navio[navios.contador].nombre != "XXX") && (navios.contador < MAX_NAV)) { | ||||
| 			archivo >> navios.navio[navios.contador].empresa; | ||||
| 			archivo >> navios.navio[navios.contador].eslora; | ||||
| 			archivo >> navios.navio[navios.contador].toneladas; | ||||
| 			archivo >> aux; | ||||
| 			if (aux == "true") { | ||||
| 				navios.navio[navios.contador].peaje = true; | ||||
| 			} | ||||
| 			else { | ||||
| 				navios.navio[navios.contador].peaje = false; | ||||
| 			} | ||||
| 			navios.contador++; | ||||
| 			archivo >> navios.navio[navios.contador].nombre; | ||||
| 		} | ||||
| 		cargado = true; | ||||
| 	} | ||||
| 	archivo.close(); | ||||
|  | ||||
| 	return cargado; | ||||
| } | ||||
|  | ||||
| void muestraNavios(tListaNavios& navios) { | ||||
| 	cout << setw(15) << right << "NOMBRE" | ||||
| 		<< setw(20) << "EMPRESA" | ||||
| 		<< setw(10) << "ESLORA" | ||||
| 		<< setw(15) << "TONELADAS" | ||||
| 		<< setw(25) << "PEAJE" << endl; | ||||
| 	cout << setw(100) << setfill('=') << "\n" << setfill(char(0)); | ||||
| 	for (int i = 0; i < navios.contador; i++){ | ||||
| 		cout << setw(15) << right << navios.navio[i].nombre | ||||
| 			<< setw(20) << navios.navio[i].empresa | ||||
| 			<< setw(10) << fixed << setprecision(2) << navios.navio[i].eslora | ||||
| 			<< setw(15) <<  setprecision(2) << navios.navio[i].toneladas; | ||||
| 		cout << setw(10) << peajeNavio(navios, i) << "$" << setw(12); | ||||
| 		if (navios.navio[i].peaje == true) { | ||||
| 			cout << "PAGADO." << endl; | ||||
| 		} | ||||
| 		else { | ||||
| 			cout << "NO PAGADO." << endl; | ||||
| 		} | ||||
| 	} | ||||
| 	cout << setw(100) << setfill('=') << "\n" << setfill(char(0)); | ||||
| 	cout << "Total pagado: " << peajePagado(navios) << endl; | ||||
| } | ||||
|  | ||||
| bool crearNavio(tListaNavios& navios) { | ||||
| 	tNavio nuevoNavio; | ||||
|  | ||||
| 	cout << "Introduzca nombre del navio: "; | ||||
| 	cin >> nuevoNavio.nombre; | ||||
| 	cout << "Introduzca empressa fabricante: "; | ||||
| 	cin >> nuevoNavio.empresa; | ||||
| 	cout << "Introduzca eslora (en metros): "; | ||||
| 	cin >> nuevoNavio.eslora; | ||||
| 	cout << "Introduzca toneladas de carga: "; | ||||
| 	cin >> nuevoNavio.toneladas; | ||||
| 	nuevoNavio.peaje = false; | ||||
|  | ||||
| 	return insertarNavio(navios, nuevoNavio); | ||||
| } | ||||
|  | ||||
| bool insertarNavio(tListaNavios& navios, tNavio& nuevoNavio) { | ||||
|  | ||||
| 	if (navios.contador < MAX_NAV){ | ||||
| 		navios.navio[navios.contador].nombre = nuevoNavio.nombre; | ||||
| 		navios.navio[navios.contador].empresa = nuevoNavio.empresa; | ||||
| 		navios.navio[navios.contador].eslora = nuevoNavio.eslora; | ||||
| 		navios.navio[navios.contador].toneladas = nuevoNavio.toneladas; | ||||
| 		navios.navio[navios.contador].peaje = nuevoNavio.peaje; | ||||
| 		navios.contador++; | ||||
| 	} | ||||
| 	 | ||||
| 	return (navios.contador < MAX_NAV) ? true : false; | ||||
| } | ||||
|  | ||||
| bool cobrarNavio(tListaNavios& navios, const string& nombre) { | ||||
| 	int i = 0; | ||||
| 	bool encontrado = false; | ||||
|  | ||||
| 	while ((!encontrado) && (i <= navios.contador)) { | ||||
| 		if (navios.navio[i].nombre == nombre) { | ||||
| 			navios.navio[i].peaje = true; | ||||
| 			encontrado = true; | ||||
| 		} | ||||
| 		else { | ||||
| 			i++; | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return (navios.navio[i].nombre == nombre) ? true : false; | ||||
| } | ||||
|  | ||||
| float peajeNavio(tListaNavios& navios, const int& pos) { | ||||
| 	float pago = 0; | ||||
|  | ||||
| 	if (navios.navio[pos].eslora <= 100) { | ||||
| 		pago = navios.navio[pos].toneladas * 2; | ||||
| 	} | ||||
| 	else { | ||||
| 		pago = navios.navio[pos].toneladas * 3; | ||||
| 	} | ||||
| 	 | ||||
| 	return pago; | ||||
| } | ||||
|  | ||||
| float peajePagado(tListaNavios& navios) { | ||||
| 	float total = 0; | ||||
|  | ||||
| 	for (int i = 0; i < navios.contador; i++){ | ||||
| 		if (navios.navio[i].peaje == true) { | ||||
| 			total += peajeNavio(navios, i); | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return total; | ||||
| } | ||||
|  | ||||
| void ejecutarMenu(tListaNavios& navios) { | ||||
| 	int opc = 1; | ||||
| 	string nombre; | ||||
|  | ||||
| 	while (opc != 0){ | ||||
| 		opc = menu(); | ||||
| 		switch (opc){ | ||||
| 		case 0: break; | ||||
| 		case 1: muestraNavios(navios); break; | ||||
| 		case 2:  | ||||
| 			if (crearNavio(navios)) { | ||||
| 				cout << "Insertado correctamente." << endl; | ||||
| 			} | ||||
| 			else { | ||||
| 				cout << "Error al insertar." << endl; | ||||
| 			}  | ||||
| 			break; | ||||
| 		case 3:  | ||||
| 			cout << "Introduzca el nombre del navio a cobrar: "; | ||||
| 			cin >> nombre; | ||||
| 			if (cobrarNavio(navios, nombre)) { | ||||
| 				cout << "Cobrado." << endl; | ||||
| 			} | ||||
| 			else { | ||||
| 				cout << "Navio no encontrado." << endl; | ||||
| 			} | ||||
| 			break; | ||||
| 		default: | ||||
| 			break; | ||||
| 		} | ||||
| 		system("PAUSE"); | ||||
| 		system("cls"); | ||||
| 	} | ||||
| } | ||||
|  | ||||
| int menu() { | ||||
| 	int opc = 0; | ||||
|  | ||||
| 	cout << setw(20) << setfill('=') << "MENU" << setw(20) << "\n" << setfill(char(0)); | ||||
| 	cout << "1.-Mostrar navios." << endl; | ||||
| 	cout << "2.-Insertar nuevo navio." << endl; | ||||
| 	cout << "3.-Realizar pago." << endl; | ||||
| 	cout << setw(40) << setfill('=') << "\n" << setfill(char(0)); | ||||
|  | ||||
| 	do { | ||||
| 		cout << "Introduzca una opcion: "; | ||||
| 		cin >> opc; | ||||
| 	} while (opc < 0 || opc > 4); | ||||
|  | ||||
| 	return opc; | ||||
| } | ||||
|  | ||||
| bool guardar(tListaNavios& navios) { | ||||
| 	bool guardado = false; | ||||
| 	ofstream archivo; | ||||
|  | ||||
| 	archivo.open("navios.txt"); | ||||
| 	if(!archivo.is_open()){ | ||||
| 		cout << "Error al guardar." << endl; | ||||
| 		guardado = false; | ||||
| 	} | ||||
| 	else { | ||||
| 		for (int i = 0; i < navios.contador; i++){ | ||||
| 			archivo << navios.navio[i].nombre << " " | ||||
| 				<< navios.navio[i].empresa << " " | ||||
| 				<< navios.navio[i].eslora << " " | ||||
| 				<< navios.navio[i].toneladas << " "; | ||||
| 			if (navios.navio[i].peaje == true) { | ||||
| 				archivo << "true" << endl; | ||||
| 			} | ||||
| 			else { | ||||
| 				archivo << "false" << endl; | ||||
| 			} | ||||
| 		} | ||||
| 		archivo << "XXX"; | ||||
| 		guardado = true; | ||||
| 	} | ||||
| 	archivo.close(); | ||||
|  | ||||
| 	return guardado; | ||||
| } | ||||
| @@ -0,0 +1,215 @@ | ||||
| /* | ||||
| Apellidos: Verd<72> Rodr<64>guez | ||||
| Nombre: Eva | ||||
| DNI: 51220965B | ||||
| Puesto: 15 | ||||
| */ | ||||
|  | ||||
| #include <iostream> | ||||
| #include <fstream> | ||||
| #include <string> | ||||
| #include <iomanip>  | ||||
| using namespace std; | ||||
|  | ||||
| //Constantes: | ||||
| const int MAX_NAV = 24; | ||||
| const string CENT = "XXX"; | ||||
|  | ||||
| typedef struct tNavios{ | ||||
| 	string nom; | ||||
| 	string empr; | ||||
| 	float esl; | ||||
| 	float ton; | ||||
| 	string pag; | ||||
| }; | ||||
|  | ||||
| typedef tNavios tListaNav[MAX_NAV]; | ||||
|  | ||||
| typedef struct tListaNavios { | ||||
| 	tListaNav lista; | ||||
| 	int cont; | ||||
| }; | ||||
|  | ||||
| //Funciones: | ||||
| int menu(); | ||||
| bool cargar(tListaNavios & lista); //Carga el archivo. | ||||
| void muestraNavios(const tListaNavios lista); | ||||
| float peajeNavio(const tNavios navio); | ||||
| float peajePagado(const tListaNavios lista); | ||||
| void crearNavio(tListaNavios & lista); | ||||
| bool insertaNavio(const tNavios navio, tListaNavios & lista); | ||||
| bool cobrarNavio(tListaNavios & lista, string name); | ||||
|  | ||||
|  | ||||
| int main() { | ||||
| 	tListaNavios lista; | ||||
| 	string name; | ||||
| 	bool cobrar = true; | ||||
| 	bool ok = cargar(lista); | ||||
| 	int opc=0; | ||||
| 	if (ok) { | ||||
| 		do{ | ||||
| 			opc = menu(); | ||||
| 			switch (opc) { | ||||
| 			case 1: | ||||
| 				muestraNavios(lista); | ||||
| 				break; | ||||
| 			case 2: | ||||
| 				crearNavio(lista); | ||||
| 				break; | ||||
| 			case 3: | ||||
| 				cout << "Introduce Nombre del Navio: "; | ||||
| 				cin >> name; | ||||
| 				cobrar = cobrarNavio(lista , name); | ||||
| 				if (!cobrar) { | ||||
| 					cout << "Error. Barco no encontrado" << endl; | ||||
| 				} | ||||
| 				break; | ||||
| 			} | ||||
| 		} while (opc != 0); | ||||
| 	} | ||||
| 	else { | ||||
| 		cout << "Error al abrir el archivo" << endl; | ||||
| 	} | ||||
| 	system("pause"); | ||||
| 	return 0; | ||||
| } | ||||
|  | ||||
| int menu() { | ||||
| 	int opc; | ||||
| 	cout << "---------------------------------" << endl; | ||||
| 	cout << "Elige una opcion: " << endl; | ||||
| 	cout << "1 - Muestra la lista" << endl; | ||||
| 	cout << "2 - Nuevo navio" << endl; | ||||
| 	cout << "3 - Pagar navio" << endl; | ||||
| 	cout << "0 - Salir" << endl; | ||||
| 	cout << "---------------------------------" << endl; | ||||
| 	cin >> opc; | ||||
| 	while (opc < 0 || opc > 3) { | ||||
| 		cout << "Error. Ponga un valor entre 0 y 3." << endl; | ||||
| 	} | ||||
| 	return opc; | ||||
| } | ||||
|  | ||||
| bool cargar(tListaNavios & lista){ | ||||
| 	bool ok = true; | ||||
| 	string aux; | ||||
| 	ifstream archivo; | ||||
| 	lista.cont = 0; | ||||
|  | ||||
| 	archivo.open("navios.txt"); | ||||
| 	if (archivo.is_open()) { | ||||
| 		archivo >> lista.lista[lista.cont].nom; | ||||
| 		while((lista.lista[lista.cont].nom != CENT) && (lista.cont < MAX_NAV)) { | ||||
| 			archivo >> lista.lista[lista.cont].empr; | ||||
| 			archivo >> lista.lista[lista.cont].esl; | ||||
| 			archivo >> lista.lista[lista.cont].ton; | ||||
| 			archivo >> lista.lista[lista.cont].pag; | ||||
| 			lista.cont++; | ||||
| 			archivo >> lista.lista[lista.cont].nom; | ||||
| 		} | ||||
| 		archivo.close(); | ||||
| 	} | ||||
| 	else { | ||||
| 		ok = false; | ||||
| 	} | ||||
| 	 | ||||
| 	return ok; | ||||
| } | ||||
|  | ||||
| void muestraNavios(const tListaNavios lista) { | ||||
| 	int i = 0; | ||||
| 	float peaje = 0; | ||||
| 	cout << "Navio" << setw(20) << "Empresa" << setw(20) << "Eslora" << setw(20) << "Toneladas" << setw(20) << "Peaje" << setw(20) << endl; | ||||
| 	cout << setw(100) << setfill('=') << "\n"; | ||||
| 	cout << setw(100) << setfill(' ') << "\n"; | ||||
| 	for (int i = 0; i < lista.cont; i++){ | ||||
| 		cout << setw(20) << left << lista.lista[i].nom; | ||||
| 		cout << setw(20) << lista.lista[i].empr; | ||||
| 		cout << fixed << setprecision(2) << setw(15) << lista.lista[i].esl; | ||||
| 		cout << setw(15) << lista.lista[i].ton; | ||||
| 		peaje = peajeNavio(lista.lista[i]); | ||||
| 		if (lista.lista[i].pag == "true") { | ||||
| 			cout << setw(10) << right << peaje  << " Pagado"  << endl; | ||||
| 		} | ||||
| 		else { | ||||
| 			cout << setw(10) << right << peaje << " No Pagado" << endl; | ||||
| 		} | ||||
| 	} | ||||
| 	cout << setw(100) << setfill('=') << '\n'; | ||||
| 	float total = peajePagado(lista); | ||||
| 	cout << "Precio total: " << total << endl; | ||||
| 	cout << setw(100) << setfill(' ') << '\n'; | ||||
| } | ||||
|  | ||||
| float peajeNavio(const tNavios navio) { | ||||
| 	float peaje; | ||||
| 	if (navio.esl < 100) { | ||||
| 		peaje = navio.ton * 2; | ||||
| 	} | ||||
| 	else { | ||||
| 		peaje = navio.ton * 3; | ||||
| 	} | ||||
| 	return peaje; | ||||
| } | ||||
|  | ||||
| float peajePagado(const tListaNavios lista) { | ||||
| 	float total = 0; | ||||
| 	for (int i = 0; i < lista.cont; i++){ | ||||
| 		if (lista.lista[i].pag == "true") { | ||||
| 			float peaje = peajeNavio(lista.lista[i]); | ||||
| 			total += peaje; | ||||
| 		} | ||||
| 	} | ||||
| 	return total; | ||||
| } | ||||
|  | ||||
| void crearNavio(tListaNavios & lista) { | ||||
| 	tNavios navio; | ||||
| 	cout << "Introduzca nombre: "; | ||||
| 	cin >> navio.nom; | ||||
| 	cout << "Introduzca compa<70>ia: "; | ||||
| 	cin >> navio.empr; | ||||
| 	cout << "Introduzca eslora: "; | ||||
| 	cin >> navio.esl; | ||||
| 	cout << "Introduzca tonaledas: "; | ||||
| 	cin >> navio.ton; | ||||
| 	navio.pag = "false"; | ||||
| 	if (insertaNavio(navio, lista)) { | ||||
| 		cout << "Se ha insertado correctamente" << endl; | ||||
| 		cout << setw(100) << setfill(' ') << '\n'; | ||||
| 	} | ||||
| 	else { | ||||
| 		cout << "No se pudo introducir" << endl; | ||||
| 		cout << setw(100) << setfill(' ') << '\n'; | ||||
| 	} | ||||
| } | ||||
|  | ||||
| bool insertaNavio(const tNavios navio, tListaNavios & lista) { | ||||
| 	bool insertar = true;; | ||||
| 	if (lista.cont < MAX_NAV) { | ||||
| 		lista.lista[lista.cont].nom = navio.nom; | ||||
| 		lista.lista[lista.cont].empr = navio.empr; | ||||
| 		lista.lista[lista.cont].esl = navio.esl; | ||||
| 		lista.lista[lista.cont].ton = navio.ton; | ||||
| 		lista.lista[lista.cont].pag = navio.pag; | ||||
| 		lista.cont++; | ||||
| 	} | ||||
| 	else { | ||||
| 		insertar = false; | ||||
| 	} | ||||
| 	return insertar; | ||||
| } | ||||
| 	 | ||||
| bool cobrarNavio(tListaNavios & lista, string name) { | ||||
| 	bool cobrar = false; | ||||
| 	int i = 0; | ||||
| 	while (!cobrar && i < lista.cont ) { | ||||
| 		if (lista.lista[i].nom == name) { | ||||
| 			lista.lista[i].pag = "true"; | ||||
| 			cobrar = true; | ||||
| 		} | ||||
| 		i++; | ||||
| 	} | ||||
| 	return cobrar; | ||||
| } | ||||
| @@ -0,0 +1,262 @@ | ||||
| //Examen Febreo 2018 | ||||
| //Fernando M<>ndez Torrubiano | ||||
|  | ||||
| #include <iostream> | ||||
| #include <string> | ||||
| #include <fstream> | ||||
| #include <iomanip> | ||||
| using namespace std; | ||||
|  | ||||
| //Constantes: | ||||
| const int MAX_NAV = 24; | ||||
|  | ||||
| //Tipos: | ||||
| typedef string tNombres[MAX_NAV]; | ||||
| typedef float tMedidas[MAX_NAV]; | ||||
|  | ||||
| typedef struct tNavios { | ||||
| 	tNombres nombre; | ||||
| 	tNombres empresa; | ||||
| 	tMedidas eslora; | ||||
| 	tMedidas toneladas; | ||||
| 	tNombres peaje; | ||||
| 	int contador; | ||||
| }; | ||||
|  | ||||
| //Funciones: | ||||
| void inicializa(tNavios&, tNavios&); | ||||
| bool cargar(tNavios&); | ||||
| void ejecutarMenu(tNavios&, tNavios&); | ||||
| int menu(); | ||||
| void muestraNavios(tNavios&); | ||||
| void crearNavio(tNavios&); | ||||
| bool insertarNavio(tNavios&, tNavios&); | ||||
| bool cobrarNavio(tNavios&); | ||||
| float peajeNavio(tNavios&, const int pos); | ||||
| float peajePagado(tNavios&); | ||||
| void guardar(tNavios&); | ||||
|  | ||||
| int main() { | ||||
| 	tNavios nave; | ||||
| 	tNavios nuevo; | ||||
| 	bool carga = false; | ||||
|  | ||||
| 	inicializa(nave, nuevo); | ||||
| 	carga = cargar(nave); | ||||
| 	if (carga) { | ||||
| 		ejecutarMenu(nave, nuevo); | ||||
| 	} | ||||
| 	else { | ||||
| 		system("PAUSE"); | ||||
| 	} | ||||
| 	guardar(nave); | ||||
|  | ||||
| 	return 0; | ||||
| } | ||||
|  | ||||
| void inicializa(tNavios& nave, tNavios& nuevo) { | ||||
|  | ||||
| 	for (int i = 0; i < MAX_NAV; i++) { | ||||
| 		nave.nombre[i] = ""; | ||||
| 		nave.empresa[i] = ""; | ||||
| 		nave.eslora[i] = 0; | ||||
| 		nave.toneladas [i]= 0; | ||||
| 		nave.peaje[i] = ""; | ||||
| 	} | ||||
| 	nave.contador = 0; | ||||
| 	nuevo.contador = 0; | ||||
| } | ||||
|  | ||||
| bool cargar(tNavios& nave) { | ||||
| 	ifstream archivo; | ||||
| 	bool carga = false; | ||||
|  | ||||
| 	archivo.open("navios.txt"); | ||||
| 	if (!archivo.is_open()) { | ||||
| 		cout << "Error al cargar el archivo." << endl; | ||||
| 		carga = false; | ||||
| 	} | ||||
| 	else { | ||||
| 		archivo >> nave.nombre[nave.contador]; | ||||
| 		while ((nave.nombre[nave.contador] != "XXX") && (nave.contador < MAX_NAV)) { | ||||
| 			archivo >> nave.empresa[nave.contador]; | ||||
| 			archivo >> nave.eslora[nave.contador]; | ||||
| 			archivo >> nave.toneladas[nave.contador]; | ||||
| 			archivo >> nave.peaje[nave.contador]; | ||||
| 			nave.contador++; | ||||
| 			archivo >> nave.nombre[nave.contador]; | ||||
| 		}  | ||||
| 		carga = true; | ||||
| 	} | ||||
| 	archivo.close(); | ||||
|  | ||||
| 	return carga; | ||||
| } | ||||
|  | ||||
| void ejecutarMenu(tNavios& nave, tNavios& nuevo) { | ||||
| 	int opc = 1; | ||||
| 	bool insertado = false; | ||||
|  | ||||
| 	while (opc != 0) { | ||||
| 		system("cls"); | ||||
| 		opc = menu(); | ||||
| 		switch (opc){ | ||||
| 		case 1: muestraNavios(nave); break; | ||||
| 		case 2: crearNavio(nuevo);  | ||||
| 				insertado = insertarNavio(nave, nuevo); | ||||
| 				if (!insertado) { | ||||
| 					cout << "No se ha podido a<>adir un nuevo navio." << endl; | ||||
| 					system("PAUSE"); | ||||
| 				} | ||||
| 				else{ | ||||
| 					cout << "Navio insertado correctamente." << endl; | ||||
| 					system("PAUSE"); | ||||
| 				} | ||||
| 				break; | ||||
| 		case 3: cobrarNavio(nave); break; | ||||
| 		case 0: break; | ||||
| 		default: break; | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
| int menu() { | ||||
| 	int opc = 0; | ||||
|  | ||||
| 	//cout << setfill('-') << setw(25) << "\n"; | ||||
| 	cout << "1.-VER LISTA DE NAVIOS." << "\n"; | ||||
| 	cout << "2.-AGREGAR NAVIO." << "\n"; | ||||
| 	cout << "3.-COBRAR PEAJE." << "\n"; | ||||
| 	cout << "0.-SALIR." << "\n"; | ||||
| 	//cout << setfill('-') << setw(25) << "\n"; | ||||
|  | ||||
| 	do{ | ||||
| 		cout << "\n Intruduzca una opcion: "; | ||||
| 		cin >> opc; | ||||
| 	} while ((opc < 0) || (opc > 3)); | ||||
|  | ||||
| 	return opc; | ||||
| } | ||||
|  | ||||
| void muestraNavios(tNavios& nave) { | ||||
| 	cout << setfill(char(0))  << setw(15) | ||||
| 		<< left << "NOMBRE" << setw(15) | ||||
| 		<< left << "EMPRESA" << setw(15) | ||||
| 		<< left << "ESLORA" << setw(20) | ||||
| 		<< left << "DESPLAZAMIENTO" << setw(20) | ||||
| 		<< left << "PEAJE"; | ||||
|  | ||||
| 	cout << setw(85) << setfill('=') << "\n" << setfill(char(0)) << endl; | ||||
| 	for (int i = 0; i < nave.contador; i++) { | ||||
| 		cout << setw(15) << left << nave.nombre[i] << setw(15) | ||||
| 			<< left << nave.empresa[i] << setw(15) | ||||
| 			<< left  << fixed << setprecision(2) << nave.eslora[i] << setw(20) | ||||
| 			<< left << nave.toneladas[i] << setw(10); | ||||
| 			if (nave.peaje[i] == "true") { | ||||
| 				cout << peajeNavio(nave, i) << "PAGADO\n"; | ||||
| 			} | ||||
| 			else { | ||||
| 				cout << peajeNavio(nave, i) << "NO PAGADO\n"; | ||||
| 			} | ||||
| 	} | ||||
| 	cout << setw(85) << setfill('=') << "\n"; | ||||
| 	cout << setw(0) << setfill(char(0)) << "\n"; | ||||
| 	system("PAUSE"); | ||||
| } | ||||
|  | ||||
| void crearNavio(tNavios& nuevo) { | ||||
| 	string nombre; | ||||
|  | ||||
| 	nuevo.contador++; | ||||
| 	cout << "Introduzca NOMBRE del navio: "; | ||||
| 	cin >> nuevo.nombre[nuevo.contador]; | ||||
| 	cout << "Introduzca EMPRESA fabricante: "; | ||||
| 	cin >> nuevo.empresa[nuevo.contador]; | ||||
| 	cout << "Introduzca ESLORA del navio: "; | ||||
| 	cin >> nuevo.eslora[nuevo.contador]; | ||||
| 	cout << "Introduzca TONELADAS del navio: "; | ||||
| 	cin >> nuevo.toneladas[nuevo.contador]; | ||||
| 	cout << "Introduzca PEAJE (true/false): "; | ||||
| 	cin >> nuevo.peaje[nuevo.contador]; | ||||
|  | ||||
| } | ||||
|  | ||||
| bool insertarNavio(tNavios& nave, tNavios& nuevo) { | ||||
| 	bool insertado = false; | ||||
|  | ||||
| 	if (nave.contador < MAX_NAV) { | ||||
| 		nave.nombre[nave.contador] = nuevo.nombre[nuevo.contador]; | ||||
| 		nave.empresa[nave.contador] = nuevo.empresa[nuevo.contador]; | ||||
| 		nave.eslora[nave.contador] = nuevo.eslora[nuevo.contador]; | ||||
| 		nave.toneladas[nave.contador] = nuevo.toneladas[nuevo.contador]; | ||||
| 		nave.peaje[nave.contador] = nuevo.peaje[nuevo.contador]; | ||||
| 		nave.contador++; | ||||
| 		insertado = true; | ||||
| 	} | ||||
| 	else { | ||||
| 		insertado = false; | ||||
| 	} | ||||
|  | ||||
| 	return insertado; | ||||
| } | ||||
|  | ||||
| bool cobrarNavio(tNavios& nave) { | ||||
| 	bool encontrado = false; | ||||
| 	string nom; | ||||
| 	int i = 0; | ||||
|  | ||||
| 	cout << "Introduzca el nombre del navio que quiere pagar: "; | ||||
| 	cin >> nom; | ||||
|  | ||||
| 	while ((i < nave.contador) && (!encontrado)) { | ||||
| 		if (nave.nombre[i] == nom) { | ||||
| 			nave.peaje[i] = "true"; | ||||
| 			encontrado = true; | ||||
| 		} | ||||
| 		i++; | ||||
| 	} | ||||
|  | ||||
| 	return encontrado; | ||||
| } | ||||
|  | ||||
| float peajeNavio(tNavios& nave, const int pos) { | ||||
| 	float precio = 0; | ||||
|  | ||||
| 	if (nave.eslora[pos] <= 100) { | ||||
| 		precio = nave.toneladas[pos] * 2; | ||||
| 	} | ||||
| 	else { | ||||
| 		precio = nave.toneladas[pos] * 3; | ||||
| 	} | ||||
|  | ||||
| 	return precio; | ||||
| } | ||||
|  | ||||
| float peajePagado(tNavios& nave) { | ||||
| 	float pagos = 0; | ||||
|  | ||||
| 	for (int i = 0; i < nave.contador; i++) { | ||||
| 		if (nave.peaje[i] == "true") { | ||||
| 			pagos += peajeNavio(nave, i); | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return pagos; | ||||
| } | ||||
|  | ||||
| void guardar(tNavios& nave) { | ||||
| 	ofstream archivo; | ||||
|  | ||||
| 	archivo.open("navios.txt"); | ||||
| 	if(archivo.is_open()){ | ||||
| 		for (int i = 0; i < nave.contador; i++) { | ||||
| 			archivo << nave.nombre[i] << " "; | ||||
| 			archivo << nave.empresa[i] << " "; | ||||
| 			archivo << nave.eslora[i] << " "; | ||||
| 			archivo << nave.toneladas[i] << " "; | ||||
| 			archivo << nave.peaje[i] << " " << endl; | ||||
| 		} | ||||
| 		archivo << "XXX"; | ||||
| 	} | ||||
| 	archivo.close(); | ||||
| } | ||||
										
											Binary file not shown.
										
									
								
							| @@ -0,0 +1,6 @@ | ||||
| Prestill pocoImporta 90 2634 true | ||||
| Pluton CAMPSA 104.2 2852 false | ||||
| CostaArrecife Costa 337 183900 false | ||||
| USSuranus UnitedFruit 82.14 3348 true | ||||
| Dedalo ArmadaEspanola 190 13000 false | ||||
| XXX | ||||
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 99 KiB | 
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 78 KiB | 
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 79 KiB | 
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 79 KiB | 
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 80 KiB | 
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 72 KiB | 
| @@ -0,0 +1,238 @@ | ||||
| //Examen Enero 2019 - Grupos A, B, D y G. | ||||
| //Fernando M<>ndez Torrubiano | ||||
|  | ||||
| #include <iostream> | ||||
| #include <string> | ||||
| #include <fstream> | ||||
| #include <iomanip> | ||||
| using namespace std; | ||||
|  | ||||
| //Constantes: | ||||
| const int MAX_PEDIDOS = 50; | ||||
|  | ||||
| //Tipos: | ||||
| typedef struct tPedido { | ||||
| 	string numPedido, nombreCliente, direccion, codRepartidor; | ||||
| 	bool estado; | ||||
| }; | ||||
| typedef tPedido tPedidos[MAX_PEDIDOS]; | ||||
| typedef struct tListaPedidos { | ||||
| 	tPedidos pedido; | ||||
| 	int contador; | ||||
| }; | ||||
|  | ||||
| //Funciones: | ||||
| void inicializa(tListaPedidos&); | ||||
| bool cargar(tListaPedidos&); | ||||
| bool actualizarPedido(tListaPedidos&, const string&); | ||||
| void mostrarPedidos(tListaPedidos&); | ||||
| int posicionRepartidor(tListaPedidos&, const string&); | ||||
| void mostrarPedidosRepartidor(tListaPedidos&, const string&); | ||||
| bool guardarPedidos(tListaPedidos&); | ||||
| void ejecutarMenu(tListaPedidos&); | ||||
| int menu(); | ||||
|  | ||||
|  | ||||
| int main() { | ||||
| 	tListaPedidos pedidos; | ||||
|  | ||||
| 	if (cargar(pedidos)) { | ||||
| 		ejecutarMenu(pedidos); | ||||
| 		if (guardarPedidos(pedidos)) { | ||||
| 			cout << "Guardado correctamente." << endl; | ||||
| 		} | ||||
| 		else { | ||||
| 			cout << "Error al guardar." << endl; | ||||
| 		} | ||||
| 	} | ||||
| 	else { | ||||
| 		cout << "Fin del programa." << endl; | ||||
| 	} | ||||
|  | ||||
| 	system("PAUSE"); | ||||
| 	return 0; | ||||
| } | ||||
|  | ||||
| void inicializa(tListaPedidos& pedidos) { | ||||
| 	pedidos.contador = 0; | ||||
| 	for (int i = 0; i < MAX_PEDIDOS; i++){ | ||||
| 		pedidos.pedido[i].numPedido = ""; | ||||
| 		pedidos.pedido[i].nombreCliente = ""; | ||||
| 		pedidos.pedido[i].direccion = ""; | ||||
| 		pedidos.pedido[i].codRepartidor = ""; | ||||
| 		pedidos.pedido[i].estado = false; | ||||
| 	} | ||||
| } | ||||
|  | ||||
| bool cargar(tListaPedidos& pedidos) { | ||||
| 	bool carga = false; | ||||
| 	ifstream archivo; | ||||
|  | ||||
| 	inicializa(pedidos); | ||||
| 	archivo.open("pedidos.txt"); | ||||
| 	if (!archivo.is_open()) { | ||||
| 		cout << "No se ha podido cargar el archivo." << endl; | ||||
| 		carga = false; | ||||
| 	} | ||||
| 	else { | ||||
| 		while ((!archivo.eof()) && (pedidos.contador < MAX_PEDIDOS)) { | ||||
| 			getline(archivo, pedidos.pedido[pedidos.contador].numPedido); | ||||
| 			getline(archivo, pedidos.pedido[pedidos.contador].nombreCliente); | ||||
| 			getline(archivo, pedidos.pedido[pedidos.contador].direccion); | ||||
| 			getline(archivo, pedidos.pedido[pedidos.contador].codRepartidor); | ||||
| 			pedidos.contador++; | ||||
| 		} | ||||
| 		carga = true; | ||||
| 	} | ||||
| 	archivo.close(); | ||||
|  | ||||
| 	return carga; | ||||
| } | ||||
|  | ||||
| bool actualizarPedido(tListaPedidos& pedidos, const string& numPedido) { | ||||
| 	bool encontrado = false; | ||||
| 	int i = 0; | ||||
|  | ||||
| 	while ((!encontrado) && (i < pedidos.contador)) { | ||||
| 		if (pedidos.pedido[i].numPedido == numPedido) { | ||||
| 			pedidos.pedido[i].estado = true; | ||||
| 			encontrado = true; | ||||
| 		} | ||||
| 		else { | ||||
| 			i++; | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return encontrado; | ||||
| } | ||||
|  | ||||
| void mostrarPedidos(tListaPedidos& pedidos) { | ||||
| 	cout << setw(15) << right << "NUMERO PEDIDO" | ||||
| 		<< setw(25) << "CLIENTE" | ||||
| 		<< setw(40) << "DIRECCION" | ||||
| 		<< setw(15) << "REPARTIDOR" | ||||
| 		<< setw(15) << "ESTADO" << endl; | ||||
| 	cout << setw(115) << setfill('=') << "\n" << setfill(char(0)); | ||||
| 	for (int i = 0; i < pedidos.contador-1; i++) { | ||||
| 		cout << setw(15) << right << pedidos.pedido[i].numPedido | ||||
| 			<< setw(25) << pedidos.pedido[i].nombreCliente | ||||
| 			<< setw(40) << pedidos.pedido[i].direccion | ||||
| 			<< setw(15) << pedidos.pedido[i].codRepartidor; | ||||
| 		if (pedidos.pedido[i].estado == true) { | ||||
| 			cout << setw(15) << "ENTREGADO" << endl; | ||||
| 		} | ||||
| 		else { | ||||
| 			cout << setw(15) << "PENDIENTE" << endl; | ||||
| 		} | ||||
| 	} | ||||
| 	cout << setw(115) << setfill('=') << "\n" << setfill(char(0)); | ||||
| } | ||||
|  | ||||
| int posicionRepartidor(tListaPedidos& pedidos, const string& codRepartidor) { | ||||
| 	int pos = 0; | ||||
| 	bool encontrado = false; | ||||
|  | ||||
| 	while ((!encontrado) && (pos <= pedidos.contador)) { | ||||
| 		if (pedidos.pedido[pos].codRepartidor == codRepartidor) { | ||||
| 			encontrado = true; | ||||
| 		} | ||||
| 		else { | ||||
| 			pos++; | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return pos; | ||||
| } | ||||
|  | ||||
| void mostrarPedidosRepartidor(tListaPedidos& pedidos, const string& codRepartidor) { | ||||
| 	int pos = posicionRepartidor(pedidos, codRepartidor); | ||||
|  | ||||
| 	if (pos < pedidos.contador) { | ||||
| 		cout << endl << "Pedidos pendientes del repartidor: " << codRepartidor << endl; | ||||
| 		cout << setw(70) << setfill('=') << "\n" << setfill(char(0)); | ||||
| 		cout << "Numero de pedido: " << pedidos.pedido[pos].numPedido << endl; | ||||
| 		cout << "Cliente: " << pedidos.pedido[pos].nombreCliente << endl; | ||||
| 		cout << "Direccion de entrega: " << pedidos.pedido[pos].direccion << endl; | ||||
| 		cout << setw(70) << setfill('=') << "\n" << setfill(char(0)); | ||||
| 	} | ||||
| 	else { | ||||
| 		cout << "Repartidor no encontrado." << endl; | ||||
| 	} | ||||
|  | ||||
| } | ||||
|  | ||||
| bool guardarPedidos(tListaPedidos& pedidos) { | ||||
| 	bool save = false; | ||||
| 	ofstream archivo; | ||||
|  | ||||
| 	archivo.open("pendientes.txt"); | ||||
| 	if (!archivo.is_open()) { | ||||
| 		save = false; | ||||
| 	} | ||||
| 	else { | ||||
| 		for (int i = 0; i < pedidos.contador; i++){ | ||||
| 			if (pedidos.pedido[i].estado == false) { | ||||
| 				archivo << pedidos.pedido[i].numPedido << endl | ||||
| 					<< pedidos.pedido[i].nombreCliente << endl | ||||
| 					<< pedidos.pedido[i].direccion << endl | ||||
| 					<< pedidos.pedido[i].codRepartidor << endl; | ||||
| 			} | ||||
| 		} | ||||
| 		save = true; | ||||
| 	} | ||||
| 	archivo.close(); | ||||
|  | ||||
| 	return save; | ||||
| } | ||||
|  | ||||
| void ejecutarMenu(tListaPedidos& pedidos) { | ||||
| 	int opc = 1; | ||||
| 	string codRepartidor, numPedido; | ||||
|  | ||||
| 	while (opc != 0) { | ||||
| 		opc = menu(); | ||||
| 		switch (opc) { | ||||
| 		case 0: break; | ||||
| 		case 1:   | ||||
| 			cout << "Codigo de repartidor: "; | ||||
| 			cin >> codRepartidor; | ||||
| 			mostrarPedidosRepartidor(pedidos, codRepartidor); | ||||
| 			system("PAUSE");  | ||||
| 			break; | ||||
| 		case 2: mostrarPedidos(pedidos); system("PAUSE"); break; | ||||
| 		case 3:  | ||||
| 			cout << "Introduzca numero de pedido: "; | ||||
| 			cin >> numPedido; | ||||
| 			if (actualizarPedido(pedidos, numPedido)) { | ||||
| 				cout << "Pedido " << numPedido << " actualizado correctamente." << endl; | ||||
| 			} | ||||
| 			else { | ||||
| 				cout << "Pedido no encontrado." << endl; | ||||
| 			} | ||||
| 			system("PAUSE");  | ||||
| 			break; | ||||
| 		default: | ||||
| 			break; | ||||
| 		} | ||||
| 		system("cls"); | ||||
| 	} | ||||
|  | ||||
| } | ||||
|  | ||||
| int menu() { | ||||
| 	int opc = 0; | ||||
|  | ||||
| 	cout << setw(20) << setfill('=') << "MENU" << setw(20) << "\n" << setfill(char(0)); | ||||
| 	cout << "1.-Mostrar todos los pedidos pendientes de un repartidor." << endl; | ||||
| 	cout << "2.-Mostrar todos los pedidos." << endl; | ||||
| 	cout << "3.-Registro pedido entregado." << endl; | ||||
| 	cout << "0.-Salir." << endl; | ||||
| 	cout << setw(40) << setfill('=') << "\n" << setfill(char(0)); | ||||
|  | ||||
| 	do { | ||||
| 		cout << "Introduzca una opcion: "; | ||||
| 		cin >> opc; | ||||
| 	} while (opc < 0 || opc > 3); | ||||
|  | ||||
| 	return opc; | ||||
| } | ||||
| @@ -0,0 +1,20 @@ | ||||
| 3421 | ||||
| Pilar Gil | ||||
| Paseo Delicias 52 28046 Madrid | ||||
| R7689 | ||||
| 12345 | ||||
| Carlos Campos | ||||
| Plaza del Carmen 14 28004 Madrid | ||||
| R7689 | ||||
| 5284 | ||||
| Carmen Santos | ||||
| Padilla 6 28001 Madrid | ||||
| R9876 | ||||
| 15289 | ||||
| Carlos Camacho | ||||
| Plaza del Carmen 14 28004 Madrid | ||||
| R9876 | ||||
| 34210 | ||||
| Pilar Alcocer | ||||
| Paseo Delicias 52 28046 Madrid | ||||
| R7000 | ||||
| @@ -0,0 +1,258 @@ | ||||
| //Examen Enero 2019 - Grupos D, E e I. | ||||
| //Fernando M<>ndez Torrubiano | ||||
|  | ||||
|  | ||||
| #include <iostream> | ||||
| #include <string> | ||||
| #include <fstream> | ||||
| #include <iomanip> | ||||
| using namespace std; | ||||
|  | ||||
| //Constantes: | ||||
| const int MAX_MILI = 50; | ||||
| const int MAX_SUB = 24; | ||||
|  | ||||
|  | ||||
| //Tipos: | ||||
| typedef struct tTiempo { | ||||
| 	int horas, minutos, segundos, milisegundos; | ||||
| }; | ||||
| typedef struct tSubtitulo { | ||||
| 	tTiempo tiempoIni, tiempoFin; | ||||
| 	string subtitulo; | ||||
| }; | ||||
| typedef tSubtitulo tSubtitulos[MAX_SUB]; | ||||
| typedef struct tListaSub { | ||||
| 	tSubtitulos subtitulo; | ||||
| 	int contador; | ||||
| }; | ||||
|  | ||||
|  | ||||
| //Funciones: | ||||
| void inicializa(tListaSub&); | ||||
| bool cargar(tListaSub&); | ||||
| int toMilisegundos(tTiempo&); | ||||
| int desajuste(const string&, const int&); | ||||
| void mostrar(tListaSub&); | ||||
| void cambiarTexto(tListaSub&); | ||||
| void buscar(tListaSub&); | ||||
| bool buscarMili(tListaSub&, const int&, int&); | ||||
| bool guardar(tListaSub&); | ||||
| void ejecutarMenu(tListaSub&); | ||||
| int menu(); | ||||
|  | ||||
|  | ||||
|  | ||||
| int main() { | ||||
| 	tListaSub subtitulos; | ||||
| 	system("chcp 1252"); | ||||
| 	system("cls"); | ||||
|  | ||||
| 	if (cargar(subtitulos)) { | ||||
| 		ejecutarMenu(subtitulos); | ||||
| 		if (guardar(subtitulos)) { | ||||
| 			cout << "Guardado correctamente." << endl; | ||||
| 		} | ||||
| 		else { | ||||
| 			cout << "Error al guardar." << endl; | ||||
| 		} | ||||
| 	} | ||||
| 	else { | ||||
| 		cout << "Fin del programa." << endl; | ||||
| 	} | ||||
|  | ||||
| 	system("PAUSE"); | ||||
| 	return 0; | ||||
| } | ||||
|  | ||||
| void inicializa(tListaSub& subtitulos) { | ||||
| 	subtitulos.contador = 0; | ||||
| 	for (int i = 0; i < MAX_SUB; i++){ | ||||
| 		subtitulos.subtitulo[i].tiempoIni.horas = 0; | ||||
| 		subtitulos.subtitulo[i].tiempoIni.minutos = 0; | ||||
| 		subtitulos.subtitulo[i].tiempoIni.segundos = 0; | ||||
| 		subtitulos.subtitulo[i].tiempoIni.milisegundos = 0; | ||||
| 		subtitulos.subtitulo[i].tiempoFin.horas = 0; | ||||
| 		subtitulos.subtitulo[i].tiempoFin.minutos = 0; | ||||
| 		subtitulos.subtitulo[i].tiempoFin.segundos = 0; | ||||
| 		subtitulos.subtitulo[i].tiempoFin.milisegundos = 0; | ||||
| 		subtitulos.subtitulo[i].subtitulo = ""; | ||||
| 	} | ||||
| } | ||||
|  | ||||
| bool cargar(tListaSub& subtitulos) { | ||||
| 	bool cargado = false; | ||||
| 	ifstream archivo; | ||||
|  | ||||
| 	inicializa(subtitulos); | ||||
| 	archivo.open("subtitulos.txt"); | ||||
| 	if (!archivo.is_open()) { | ||||
| 		cout << "Error al cargar el archivo." << endl; | ||||
| 		cargado = false; | ||||
| 	} | ||||
| 	else { | ||||
| 		while ((!archivo.eof()) && (subtitulos.contador < MAX_SUB)) { | ||||
| 			archivo >> subtitulos.subtitulo[subtitulos.contador].tiempoIni.horas; | ||||
| 			archivo.ignore(); | ||||
| 			archivo >> subtitulos.subtitulo[subtitulos.contador].tiempoIni.minutos; | ||||
| 			archivo.ignore(); | ||||
| 			archivo >> subtitulos.subtitulo[subtitulos.contador].tiempoIni.segundos; | ||||
| 			archivo.ignore(); | ||||
| 			archivo >> subtitulos.subtitulo[subtitulos.contador].tiempoIni.milisegundos; | ||||
| 			archivo.ignore(); | ||||
| 			archivo >> subtitulos.subtitulo[subtitulos.contador].tiempoFin.horas; | ||||
| 			archivo.ignore(); | ||||
| 			archivo >> subtitulos.subtitulo[subtitulos.contador].tiempoFin.minutos; | ||||
| 			archivo.ignore(); | ||||
| 			archivo >> subtitulos.subtitulo[subtitulos.contador].tiempoFin.segundos; | ||||
| 			archivo.ignore(); | ||||
| 			archivo >> subtitulos.subtitulo[subtitulos.contador].tiempoFin.milisegundos; | ||||
| 			archivo.ignore(); | ||||
| 			getline(archivo, subtitulos.subtitulo[subtitulos.contador].subtitulo); | ||||
| 			subtitulos.contador++; | ||||
| 		} | ||||
| 		cargado = true; | ||||
| 	} | ||||
| 	archivo.close(); | ||||
|  | ||||
| 	return cargado; | ||||
| } | ||||
|  | ||||
| int toMilisegundos(tTiempo& tiempo) { | ||||
| 	int tiempoMS = 0, tiempoSec = 0, tiempoMin = 0; | ||||
|  | ||||
| 	tiempoMin = (tiempo.horas * 60) + tiempo.minutos; | ||||
| 	tiempoSec = (tiempoMin * 60) + tiempo.segundos; | ||||
| 	tiempoMS = (tiempoSec * 1000) + tiempo.milisegundos; | ||||
|  | ||||
| 	return tiempoMS; | ||||
| } | ||||
|  | ||||
| int desajuste(const string& subtitulo, const int& intervalo) { | ||||
| 	int desajuste = 0, tiempoSub = 0, diferencia = 0; | ||||
|  | ||||
| 	if (intervalo > 0) { | ||||
| 	tiempoSub = subtitulo.length() * MAX_MILI; | ||||
| 	diferencia = tiempoSub - intervalo; | ||||
| 	desajuste = diferencia / MAX_MILI; | ||||
| 	} | ||||
|  | ||||
| 	return desajuste; | ||||
| } | ||||
|  | ||||
| void mostrar(tListaSub& subtitulos) { | ||||
|  | ||||
| 	cout << setw(40) << setfill('=') << "\n" << setfill(char(0)); | ||||
| 	for (int i = 0; i < subtitulos.contador; i++){ | ||||
| 		cout << "Intervalo: " << toMilisegundos(subtitulos.subtitulo[i].tiempoIni) << " --> " << toMilisegundos(subtitulos.subtitulo[i].tiempoFin) << endl | ||||
| 			<< "Texto: " << subtitulos.subtitulo[i].subtitulo << endl << endl; | ||||
| 	} | ||||
| 	cout << setw(40) << setfill('=') << "\n" << setfill(char(0)); | ||||
| } | ||||
|  | ||||
| void cambiarTexto(tListaSub& subtitulos) { | ||||
| 	int pos = 0; | ||||
|  | ||||
| 	cout << endl; | ||||
| 	do { | ||||
| 		cout << "Posicion en la lista: "; | ||||
| 		cin >> pos; | ||||
| 	} while (pos < 0 || pos >= subtitulos.contador); | ||||
|  | ||||
| 	cout << "Texto: "; | ||||
| 	cin.ignore(); | ||||
| 	getline(cin, subtitulos.subtitulo[pos].subtitulo); | ||||
| } | ||||
|  | ||||
| void buscar(tListaSub& subtitulos) { | ||||
| 	int mili = 0, pos = 0, intervalo = 0; | ||||
|  | ||||
| 	cout << setw(40) << setfill('=') << "\n" << setfill(char(0)); | ||||
| 	cout << "Milisegundos: "; | ||||
| 	cin >> mili; | ||||
|  | ||||
| 	if (buscarMili(subtitulos, mili, pos)) { | ||||
| 		cout << "Encontrado en la posicion: " << pos << endl | ||||
| 			<< "Intervalo: " << toMilisegundos(subtitulos.subtitulo[pos].tiempoIni) << " --> " << toMilisegundos(subtitulos.subtitulo[pos].tiempoFin) << endl | ||||
| 			<< "Texto: " << subtitulos.subtitulo[pos].subtitulo << endl; | ||||
| 		intervalo = toMilisegundos(subtitulos.subtitulo[pos].tiempoFin) - toMilisegundos(subtitulos.subtitulo[pos].tiempoIni); | ||||
| 		cout << "Desajuste: " << desajuste(subtitulos.subtitulo[pos].subtitulo, intervalo) << endl; | ||||
| 	} | ||||
| 	else { | ||||
| 		cout << "No encontrado." << endl; | ||||
| 	} | ||||
| 	cout << setw(40) << setfill('=') << "\n" << setfill(char(0)); | ||||
| } | ||||
|  | ||||
| bool buscarMili(tListaSub& subtitulos, const int& mili, int& i) { | ||||
| 	bool encontrado = false; | ||||
|  | ||||
| 	while ((!encontrado) && (i < subtitulos.contador)) { | ||||
| 		if ((mili > toMilisegundos(subtitulos.subtitulo[i].tiempoIni)) && (mili < toMilisegundos(subtitulos.subtitulo[i].tiempoFin))) { | ||||
| 			encontrado = true; | ||||
| 		} | ||||
| 		else {  | ||||
| 			i++;  | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return encontrado; | ||||
| } | ||||
|  | ||||
| bool guardar(tListaSub& subtitulos) { | ||||
| 	bool save = false; | ||||
| 	ofstream archivo; | ||||
|  | ||||
| 	archivo.open("subtitulosEX.txt"); | ||||
| 	if (!archivo.is_open()) { | ||||
| 		save = false; | ||||
| 	} | ||||
| 	else { | ||||
| 		for (int i = 0; i < subtitulos.contador; i++){ | ||||
| 			archivo << toMilisegundos(subtitulos.subtitulo[i].tiempoIni) << " " | ||||
| 				<< toMilisegundos(subtitulos.subtitulo[i].tiempoFin) << " " | ||||
| 				<< subtitulos.subtitulo[i].subtitulo << endl; | ||||
| 		} | ||||
| 		save = true; | ||||
| 	} | ||||
| 	archivo.close(); | ||||
|  | ||||
| 	return save; | ||||
| } | ||||
|  | ||||
| void ejecutarMenu(tListaSub& subtitulos) { | ||||
| 	int opc = 1; | ||||
|  | ||||
| 	while (opc != 0) { | ||||
| 		opc = menu(); | ||||
| 		switch (opc){ | ||||
| 		case 0: break; | ||||
| 		case 1: mostrar(subtitulos); system("PAUSE"); break; | ||||
| 		case 2: cambiarTexto(subtitulos); system("PAUSE"); break; | ||||
| 		case 3: buscar(subtitulos); system("PAUSE"); break; | ||||
| 		default: | ||||
| 			break; | ||||
| 		} | ||||
| 		system("cls"); | ||||
| 	} | ||||
|  | ||||
| } | ||||
|  | ||||
| int menu() { | ||||
| 	int opc = 0; | ||||
|  | ||||
| 	cout << setw(20) << setfill('=') << "MENU" << setw(20) << "\n" << setfill(char(0)); | ||||
| 	cout << "1.-Mostrar lista." << endl; | ||||
| 	cout << "2.-Cambiar texto." << endl; | ||||
| 	cout << "3.-Buscar subtitulo." << endl; | ||||
| 	cout << "0.-Salir." << endl; | ||||
| 	cout << setw(40) << setfill('=') << "\n" << setfill(char(0)); | ||||
|  | ||||
| 	do { | ||||
| 		cout << "Introduzca una opcion: "; | ||||
| 		cin >> opc; | ||||
| 	} while (opc < 0 || opc > 3); | ||||
|  | ||||
| 	return opc; | ||||
| } | ||||
|  | ||||
										
											Binary file not shown.
										
									
								
							| @@ -0,0 +1,5 @@ | ||||
| 00:00:00,394 00:00:03,031 Anteriormente en Sons of Anarchy... | ||||
| 00:00:03,510 00:00:04,260 Ponte esto. Ayudar<61>. | ||||
| 00:10:13,990 00:10:14,703 Texto del subt<62>tulo 4. | ||||
| 00:20:19,008 00:25:19,100 Se veng<6E> de la persona equivocada. Y ahora tiene a mi hijo. | ||||
| 01:00:59,998 01:01:00,123 Texto del subt<62>tulo 11. | ||||
		Reference in New Issue
	
	Block a user