#include "Agencia.h" #include #include #include "Evento.h" Agencia::Agencia() { } int Agencia::correr() { while ( true ) { std::cout << "Agencia de eventos v1.0\n\n" << " 1. Registrar evento\n" << " 2. Ver estadísticas\n" << " 0. Salir\n\n" << "Opción: "; unsigned opcion = 0; std::cin >> opcion; switch ( opcion ) { case 1: registrarEvento(); break; case 2: verEstadisticas(); break; case 0: return 0; } } } bool Agencia::registrarEvento() { std::cout << "Registrar nuevo evento:\n\n" << " 1. Cumpleaños\n" << " 2. Mariachi\n" << " 3. Boda\n" << " 0. Regresar\n\n" << "Opción: "; unsigned tipo = 0; std::cin >> tipo; Evento* evento = crearEvento(tipo); if ( ! evento ) return false; std::cout << "Ingrese evento en formato:\n\n"; evento->imprimirOpcionesDeLectura(); std::cout << std::endl << std::endl; if ( ! (std::cin >> *evento) ) { delete evento; return false; } std::cout << "El costo del evento es de " << evento->calcularCosto() << " colones\n"; std::cout << "¿Guardar evento en disco [SN]? "; char respuesta = 'N'; std::cin >> respuesta; if ( toupper(respuesta) != 'S' ) { delete evento; return true; } std::ofstream archivo("eventos.txt", std::ios::app); if ( ! archivo ) return false; archivo << evento->obtenerTipoEvento() << std::endl << *evento << std::endl; archivo.close(); delete evento; return static_cast(archivo); } #include "Cumpleanos.h" #include "Mariachi.h" #include "Boda.h" Evento* Agencia::crearEvento(unsigned tipo) { switch ( tipo ) { case 1: return new Cumpleanos(); case 2: return new Mariachi(); case 3: return new Boda(); default: return NULL; } } bool Agencia::verEstadisticas() { std::ifstream archivo("eventos.txt"); if ( ! archivo ) return false; Evento::reiniciarEstadisticas(); Cumpleanos::reiniciarEstadisticas(); unsigned tipoEvento = 0; while ( archivo >> tipoEvento ) { Evento* evento = crearEvento(tipoEvento); if ( ! evento ) return false; if ( ! (archivo >> *evento) ) { delete evento; return false; } evento->actualizarEstadisticas(); } Evento::imprimirEstadisticas(); Cumpleanos::imprimirEstadisticas(); return static_cast( std::cout << std::endl ); }