// Programa que demuestra la herencia.
// INCLUDES DE SISTEMA
#include <iostream>
// Definición de una clase base para vehiculos
class VehiculoRodante
{
private :
/* Generalmente en 'private' se sitúan los datos miembros */
int mRuedas=0;
int mPasajeros=0;
public :
void set_ruedas (int num)
{
this->mRuedas = num;
}
int get_ruedas ()
{
return this->mRuedas ;
}
void set_pasajeros (int num)
{
this->mPasajeros = num;
}
int get_pasajeros (void)
{
return this->mPasajeros ;
}
};
// Definición de una clase 'Camion' derivada de la clase base 'VehiculoRodante'.
class Camion : public VehiculoRodante
{
public :
void set_carga (int size)
{
this->mCarga = size;
}
int get_carga (void)
{
return this->mCarga ;
}
void Mostrar (void);
private :
int mCarga ;
};
void Camion ::Mostrar (void)
{
std::cout << "ruedas: " << this->get_ruedas() << "\n";
std::cout << "pasajeros: " << this->get_pasajeros () << std::endl;
std::cout << "Capacidad de carga en pies cúbicos: " << this->get_carga () <<
std::endl;
}
enum tipo {deportivo , berlina , turismo };
class Automovil : public VehiculoRodante
{
public :
void set_tipo (tipo t)
{
this->mTipoDeAutomovil = t;
}
enum tipo get_tipo (void)
{
return this->mTipoDeAutomovil ;
};
void Mostrar (void);
private :
enum tipo mTipoDeAutomovil ;
};
void Automovil ::Mostrar (void)
{
std::cout << "ruedas: " << this->get_ruedas() << std::endl;
std::cout << "pasajeros: " << this->get_pasajeros () << std::endl;
std::cout << "tipo: " ;
switch (this->get_tipo ())
{
case deportivo :
std::cout << "deportivo" ;
break ;
case berlina :
std::cout << "berlina" ;
break ;
case turismo :
std::cout << "turismo" ;
}
std::cout << std::endl;
}
int main(void)
{
Camion Camion1 ;
Camion Camion2 ;
Automovil Automovil1 ;
Camion1.set_ruedas(18);
Camion1.set_pasajeros(2);
Camion1.set_carga(3200);
Camion2.set_ruedas(6);
Camion2.set_pasajeros(3);
Camion2.set_carga(1200);
Camion1.Mostrar();
std::cout << std::endl;
Camion2 .Mostrar();
std::cout << std::endl;
Automovil1.set_ruedas(4);
Automovil1.set_pasajeros(6);
Automovil1.set_tipo(tipo::deportivo );
Automovil1.Mostrar();
return 0;
}