Skip to content

Instantly share code, notes, and snippets.

@FraGoTe
Created April 28, 2018 04:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FraGoTe/ea6f6d3a5bdc35b67eae256d53d90405 to your computer and use it in GitHub Desktop.
Save FraGoTe/ea6f6d3a5bdc35b67eae256d53d90405 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string>
using namespace std;
class Mascota
{
public:
Mascota(string nombre, int patas);
string hablar();
private:
virtual string palabra();
string nombre;
int patas;
};
Mascota::Mascota(string nombre, int patas):nombre(nombre),patas(patas)
{
cout << "Acaba de nacer tu mascota "<<nombre<<" con "<<patas<<"patas"<<endl;
}
string Mascota::palabra()
{
return "BUUU";
}
string Mascota::hablar()
{
return nombre+" dice: "+this->palabra();
}
class Perro : public Mascota
{
public:
Perro(string nombre);
string palabra();
};
Perro::Perro(string nombre):Mascota(nombre, 4)
{
}
string Perro::palabra()
{
return "GUAU";
}
class Gato : public Mascota
{
public:
Gato(string nombre);
string palabra();
};
Gato::Gato(string nombre):Mascota(nombre, 4)
{
}
string Gato::palabra()
{
return "MIAU";
}
int main()
{
Mascota *m, *g;
m=new Perro("Ramiro");
g=new Gato("Lancelot");
cout << m->hablar() << endl;
cout << g->hablar() << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment