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,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
|
Reference in New Issue
Block a user