-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOOP_polimorfismo.cpp
More file actions
61 lines (57 loc) · 1.24 KB
/
OOP_polimorfismo.cpp
File metadata and controls
61 lines (57 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <iostream>
#include <deque>
using namespace std;
class persona{
private:
string nombre;
int edad;
public:
persona(string,int);
//polimorfismo
virtual void mostrar();
};
class alumno : public persona{
private:
int nota;
public:
alumno(string,int,int);
void mostrar();
};
class profesor : public persona{
private:
string materia;
public:
profesor(string,int,string);
void mostrar();
};
persona::persona(string _nombre,int _edad){
nombre = _nombre;
edad = _edad;
}
alumno::alumno(string _nombre, int _edad, int _nota) : persona(_nombre, _edad){
nota = _nota;
}
profesor::profesor(string _nombre, int _edad, string _materia) : persona(_nombre,_edad){
materia = _materia;
}
void persona::mostrar(){
cout << nombre << endl;
cout << edad << endl;
}
void alumno::mostrar(){
persona::mostrar();
cout << nota << endl;
}
void profesor::mostrar(){
persona::mostrar();
cout << materia << endl;
}
int main(){
persona *vector[3];
vector[0] = new alumno("Alejandro",20,39);
vector[0] ->mostrar();
vector[1] = new alumno("Maria",2,0);
vector[1] ->mostrar();
vector[2] = new profesor("elmo",99,"algoritmos");
vector[2] -> mostrar();
}