Created
April 28, 2018 04:56
-
-
Save FraGoTe/ea6f6d3a5bdc35b67eae256d53d90405 to your computer and use it in GitHub Desktop.
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 <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