POLIMORFISM pointers [closed]

-3

I need the program to use polymorphism in the int main, this accommodating it but it makes an error and says "no matching function for call to FrecuenciaCardiacas"

//Frecuencia Cardiaca
#include <iostream>
#include <stdlib.h>
#include <iomanip>

using namespace std;

class FrecuenciasCardiacas
{
 public: //Atributos
    string nombrePersona;
    string apellidoPersona,sexo;
    int mes,dia,anio,da,ma,aa,edad;
    float frecuencia;


//Metodos_
    void datos(string nombre,string apellido,int _mes, int _dia, int _anio,int _da, int _ma, int _aa,int _edad,string _sexo,float _frecuencia)//Constructor
    {
        nombrePersona=nombre;
        apellidoPersona=apellido;
        mes=_mes;
        dia=_dia;
        anio=_anio;
        da=_da;
        ma=_ma;
        aa=_aa;
        edad=_edad;
        sexo=_sexo;
        frecuencia=_frecuencia;//SE PUSO A FRECUENCIA COMO UNA VARIABLE GLOBAL PARA PODER UTILIZARLA EN TODO EL CODIGO
    }

};

class FrecuenciasCardiacasEntrenamiento: public FrecuenciasCardiacas
{
public:
    FrecuenciasCardiacasEntrenamiento (string nombre,string apellido,int _mes, int _dia, int _anio,int _da, int _ma, int _aa,int _edad,string _sexo,float _frecuencia)
    {
        datos (nombre,apellido,_mes,_dia,_anio,_da,_ma,_aa,_edad,_sexo,_frecuencia);
    }

    void establecerNombrePersona(string nombre)//nombre
    {
        nombrePersona = nombre;
    }

    string obtenerNombrePersona() const
        {
            return nombrePersona;
        }


    void establecerApellido(string apellido)//apellido
        {
            apellidoPersona=apellido;
        }

    string obtenerApellido() const
        {
            return apellidoPersona;
        }

      void establecerDia(int _dia)//DIA
        {
            dia=_dia;
        }
        int obtenerDia() const
        {
            return dia;
        }

        void establecerMes(int _mes)//MES
        {
            mes = _mes;
        }
        int obtenerMes() const
        {
            return mes;
        }

        void establecerAnio(int _anio)//ANIO
        {
            anio = _anio;
        }
        int obtenerAnio()
        {
            return anio;
        }

    int obtenerFecha ()
    {

        if(ma>=mes)
            {
                if(da>=dia)
                {
                    edad=aa-anio;
                }
                else if(da<dia)
                {
                    edad=aa-anio-1;
                }
            }
            else if(dia!=da || mes!=ma)
            {
                edad=aa-anio-1;
            }
            return edad;
    }

    int ObtenerEdad()
    {
        aa=aa-anio;//ANIOS

        return aa;
    }


     void establecerFrecuenciaCardiacaMaxima(float _frecuencia)//FRECUENCIA CARDIACA MAXIMA
     {
        frecuencia = _frecuencia;
     }

     float obtenerFrecuenciaCardiacaMaxima()//FRECUENCIA CARDIACA MAXIMA
     {

        frecuencia=220-edad;
        return frecuencia;
     }


     string obtenerFrecuenciaCardiacaEsperada()//FRECUENCIA CARDIACA ESPERADA
    {
        string parametro;
        if (edad >=0 && edad<1)
        {
            parametro="80 a 160 lpm";
        }
        else if (edad >=1 && edad<=2)
        {
            parametro="80 a 130 lpm";
        }
        else if (edad >=3 && edad<=4)
        {
            parametro="80 a 120 lpm";
        }
        else if (edad >=5 && edad<=9)
        {
            parametro="75 a 115 lpm";
        }
        else if (edad >=10)
        {
            parametro="50 a 100 lpm";
        }
        return parametro;
    }


    void establecerSexoPersona(string _sexo)//SEXOPERSONA
    {
        sexo=_sexo;
    }

    string obtenerSexoPersona() const
    {
        return sexo;
    }

    float obtenerFrecuenciasCardiacasEntrenamiento()//CALCULA LA ZONA DE ENTRENAMIENTOS SEGUN SUS PULSACIONES
    {
        float fce,reposo,intensidad;

        cout<<"\nIntroduzca el valor de su frecuencia cardiaca cuando se encuentra en reposo :  ";
        cin>>reposo;

        cout<<"\nEn una escala de 1-100% escriba la instensidad sobre la cual quiere calcular la zona de entrenamiento:";
        cin>>intensidad;

        fce=((frecuencia-reposo)* intensidad)+reposo;

        if (fce>=50 && fce<60)
        {
            cout <<"Su zona de entrenamiento es ZONA 1 : MUY SUAVE:) "<<endl;
        }

        else if (fce>=60 && fce<70)
        {
            cout <<"Su zona de entrenamiento es ZONA 2 : SUAVE/FACIL "<<endl;
        }

        else if (fce>=70 && fce<80)
        {
            cout <<"Su zona de entrenamiento es ZONA 3 : MODERADA "<<endl;
        }

        else if (fce>=80 && fce<90)
        {
            cout <<"Su zona de entrenamiento es ZONA 4 : INTENSA "<<endl;
        }

        else if (fce>=90 && fce<100)
        {
            cout <<"Su zona de entrenamiento es ZONA 5 : MAXIMA "<<endl;
        }

        return fce;

    }

};

int main()
{
    FrecuenciasCardiacasEntrenamiento fre;
    FrecuenciasCardiacas * ap1 = &fre;
    ap1 -> datos ();

    cout << fre.obtenerNombrePersona() << '\n';

    return 0;
}
    
asked by user103440 11.11.2018 в 07:23
source

1 answer

1

First, as you have been told, you have to present a minimum example that reproduces the problem.

Making a minimum example is important because it can help you find the source of the problem on your own.

In your case the minimum example for the first error could look like this:

class FrecuenciasCardiacasEntrenamiento
{
public:
  FrecuenciasCardiacasEntrenamiento (string nombre,string apellido,int _mes, int _dia, int _anio,int _da, int _ma, int _aa,int _edad,string _sexo,float _frecuencia)
  { }
};

int main()
{
  FrecuenciasCardiacasEntrenamiento fre;
}

Four lines of code that reproduce the error message. There is no polymorphism or pointers ...

The problem here is that the class FrecuenciasCardiacasEntrenamiento does not have a default constructor. In C ++ all classes have a default constructor ... until specific constructors are declared, in which case you have to declare the default constructor explicitly if you want to continue using it:

class FrecuenciasCardiacasEntrenamiento
{
public:
  // c++11
  FrecuenciasCardiacasEntrenamiento() = default;

  // c++98
  FrecuenciasCardiacasEntrenamiento()
  { }

  FrecuenciasCardiacasEntrenamiento (string nombre,string apellido,int _mes, int _dia, int _anio,int _da, int _ma, int _aa,int _edad,string _sexo,float _frecuencia)
  { }
};

The second error is practically identical:

Startprog.cc: In function 'int main()':
prog.cc:219:19: error: no matching function for call to 'FrecuenciasCardiacas::datos()'
 219 | ap1 -> datos ();
     | ^

The problem is that you do not have a datos function that does not support parameters:

class FrecuenciasCardiacas
{
public:
  void datos(string nombre,string apellido,int _mes, int _dia, int _anio,int _da, int _ma, int _aa,int _edad,string _sexo,float _frecuencia)
  { }
};

You have to create a version of datos that does not accept arguments ... or ask all those data to the user and call the function datos that you already have ... the decision is yours.

As you can see, the errors have nothing to do with the polymorphism but are called to functions that do not exist.

    
answered by 11.11.2018 в 13:37