Created
October 26, 2025 03:53
-
-
Save HiroNakamura/00e68694789bd6bdf972c4f804475d8b to your computer and use it in GitHub Desktop.
Calculadora de IMC y Pulsaciones en C++
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "calculos.hpp" | |
| double getIMC(double peso, double talla) | |
| { | |
| return peso / (talla * talla); | |
| } | |
| double getPulsaciones(int edad) | |
| { | |
| if (OPC_1 == 1) | |
| { | |
| return HOMBRE_PULS - (0.7 * edad); | |
| } | |
| else if (OPC_2 == 2) | |
| { | |
| return MUJER_PULS - (0.8 * edad); | |
| } | |
| else | |
| { | |
| return 0.0; | |
| } | |
| } | |
| std::string clasificarIMC(double imc) | |
| { | |
| std::string cad = ""; | |
| if (imc < 16.00) | |
| { | |
| cad = "Infrapeso: Delgadez Severa"; | |
| } | |
| else if (imc <= 16.99) | |
| { | |
| cad = "Infrapeso: Delgadez moderada"; | |
| } | |
| else if (imc <= 18.49) | |
| { | |
| cad = "Infrapeso: Delgadez aceptable"; | |
| } | |
| else if (imc <= 24.99) | |
| { | |
| cad = "Peso Normal"; | |
| } | |
| else if (imc <= 29.99) | |
| { | |
| cad = "Sobrepeso"; | |
| } | |
| else if (imc <= 34.99) | |
| { | |
| cad = "Obeso: Tipo I"; | |
| } | |
| else if (imc <= 35.00 || imc == 40.00) | |
| { | |
| cad = "Obeso: Tipo III"; | |
| } | |
| else | |
| { | |
| cad = "no existe clasificacion"; | |
| } | |
| return cad; | |
| } | |
| void obtenerCalcImc(Register r1) | |
| { | |
| double imc = getIMC(r1.getPeso(), r1.getTalla()); | |
| r1.mostrar(); | |
| cout << "El IMC es de " << imc << " kg/(m*m)" << endl; | |
| cout << "Diagnostico: " << clasificarIMC(imc) << endl; | |
| } | |
| void limpiarPantalla() { | |
| #ifdef _WIN32 | |
| system("cls"); | |
| #else | |
| system("clear"); | |
| #endif | |
| } | |
| void obtenerCalcPuls(Register r1) | |
| { r1.mostrar(); | |
| cout << "El no. de pulsaciones es de " << getPulsaciones(r1.getEdad()) << " por minuto." << endl; | |
| } | |
| int menu() | |
| { | |
| int opc; | |
| cout << "\t ******* MENU ******" << endl; | |
| cout << "\t 1. Obtener IMC." << endl; | |
| cout << "\t 2. Obtener pulsaciones." << endl; | |
| cout << "\t 3. Salir." << endl; | |
| do | |
| { | |
| cout << "Introduce opcion:" << endl; | |
| cin >> opc; | |
| } while (opc < 0 || opc > 3); | |
| return opc; | |
| } | |
| string nombre; | |
| double peso, talla; | |
| int edad, genero; | |
| Register r1; | |
| void introduceDatos() | |
| { | |
| cout << "\t *********************************" << endl; | |
| cout << "Introduce nombre de la persona: " << endl; | |
| cin >> nombre; | |
| cout << "Introduce talla: " << endl; | |
| cin >> talla; | |
| cout << "Introduce peso: " << endl; | |
| cin >> peso; | |
| cout << "Introduce edad: " << endl; | |
| cin >> edad; | |
| cout << "Introduce tu genero [Masculino: 1, Femenino: 2]:" << endl; | |
| cin >> genero; | |
| cout << "\t *********************************" << endl; | |
| r1.setNombre(nombre); | |
| r1.setEdad(edad); | |
| r1.setTalla(talla); | |
| r1.setPeso(peso); | |
| } | |
| void inicia(void) | |
| { | |
| limpiarPantalla(); | |
| int opcion = 0; | |
| for (;;) | |
| { | |
| opcion = menu(); | |
| cout << "Tu opcion fue: " << opcion << endl; | |
| switch (opcion) | |
| { | |
| case 1: | |
| introduceDatos(); | |
| obtenerCalcImc(r1); | |
| break; | |
| case 2: | |
| introduceDatos(); | |
| obtenerCalcPuls(r1); | |
| break; | |
| case 3: | |
| exit(0); | |
| break; | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #ifndef CALCULOS_H | |
| #define CALCULOS_H | |
| #define HOMBRE_PULS 220 | |
| #define MUJER_PULS 226 | |
| #define OPC_1 1 | |
| #define OPC_2 2 | |
| #include <ctime> | |
| #include <iostream> | |
| #include <string> | |
| #include <iomanip> | |
| using namespace std; | |
| class Register | |
| { | |
| private: | |
| time_t hora_dia; | |
| string nombre; | |
| int edad; | |
| double talla; | |
| double peso; | |
| public: | |
| Register() : hora_dia(time(nullptr)), nombre(""), edad(0), talla(0.0), peso(0.0) {} | |
| Register(const string &nombre_, int edad_, double talla_, double peso_) | |
| : hora_dia(time(nullptr)), nombre(nombre_), edad(edad_), talla(talla_), peso(peso_) {} | |
| time_t getHoraDia() const { return hora_dia; } | |
| string getNombre() const { return nombre; } | |
| int getEdad() const { return edad; } | |
| double getTalla() const { return talla; } | |
| double getPeso() const { return peso; } | |
| void setNombre(const string &nombre_) { nombre = nombre_; } | |
| void setEdad(int edad_) { edad = edad_; } | |
| void setTalla(double talla_) { talla = talla_; } | |
| void setPeso(double peso_) { peso = peso_; } | |
| void setHoraDia(time_t hora_) { hora_dia = hora_; } | |
| void mostrar() const | |
| { | |
| tm *tiempo_local = localtime(&hora_dia); | |
| cout << "Registro:" << endl; | |
| cout << "Nombre: " << nombre << endl; | |
| cout << "Edad: " << edad << " años" << endl; | |
| cout << "Talla: " << talla << " m" << endl; | |
| cout << "Peso: " << peso << " kg" << endl; | |
| cout << "Hora del día: " << put_time(tiempo_local, "%Y-%m-%d %H:%M:%S") << endl; | |
| } | |
| }; | |
| void limpiarPantalla(void); | |
| void introduceDatos(void); | |
| double getIMC(double peso, double talla); | |
| double getPulsaciones(int edad); | |
| void inicia(void); | |
| int menu(void); | |
| void obtenerCalcImc(Register r1); | |
| void obtenerCalcPuls(Register r1); | |
| std::string clasificarIMC(double imc); | |
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "calculos.cpp" | |
| int main(int argc, char const *argv[]) | |
| { | |
| inicia(); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment