Examen
Examen
Examen
2 ///pregunta 1
3 int residuo(int x,int y){
4 if(x<y)return x;
5 return residuo(x-y,y);
6 }
7
8 //-------------------------------------------------------------------
9 ///pregunta 2
10 ///pregunta 2
11
12 ///archivo ANIMAL.h
13 ///archivo ANIMAL.h
14 #include<iostream>
15 #include<cstdio>
16 #include<cstdlib>
17
18 using namespace std;
19
20 ///definicion
21 class Animal{
22 public:
23 Animal();
24 Animal(string,int);
25 virtual ~Animal();
26
27 virtual void descripcion();
28 ///seter y geters
29 void setNombre(string);
30 void setAnioOrigen(int);
31 string getNombre()const;
32 int getAnioOrigen()const;
33
34 protected:
35 string nombre;
36 int anio_origen;
37
38 private:
39 };
40
41 class Terrestre:public Animal{
42 public:
43
44 Terrestre();
45 Terrestre(string,int);
46 Terrestre(string,int,int,string);
47 ~Terrestre();
48
49 void correr();
50 void descripcion();
51 //set y get
52 void setNumPatas(int);
53 void setAlimento(string);
54 int getNumPatas()const;
55 string getAlimento()const;
56
57 protected:
58 private:
59
60 int num_patas;
61 string alimento;
62 };
63
64
65 class Acuatico:public Animal{
66 public:
67 Acuatico();
68 Acuatico(string,int);
69 Acuatico(string,int,string);
70
71 ~Acuatico();
72 void nadar();
73 void descripcion();
74
75 //set y get
76 void getTipoAgua(string);
77 string getTipoAgua()const;
78
79 protected:
80 private:
81 string tipo_agua;
82 };
83
84 class Aereo:public Animal{
85 public:
86 Aereo();
87 Aereo(string,int);
88 Aereo(string,int,char,float);
89
90 ~Aereo();
91
92 void volar();
93 void descripcion();
94 //set y get
95 void setGenero(char);
96 void setLongAlas(float);
97 char getGenero()const;
98 float getLongAlas()const;
99
100 protected:
101 private:
102 char genero;
103 float long_alas;
104 };
105
106 ///archivo ANIMAL.cpp
107 ///archivo ANIMAL.cpp
108 #include "ANIMAL.h"
109 ///implementacion
110 Animal::Animal(){}
111 Animal::Animal(string n,int a){
112 nombre = n;
113 anio_origen = a;
114 }
115 Animal::~Animal(){}
116
117 void Animal::descripcion(){
118 cout<<"(Animal) Nombre: "<<nombre<<" , A"<<(char)164<<"o Origen: "<<anio_origen;
119 }
120 ///seter y geters
121 void Animal::setNombre(string n){nombre = n;}
122 void Animal::setAnioOrigen(int a){anio_origen=a;}
123 string Animal::getNombre()const{return nombre;}
124 int Animal::getAnioOrigen()const{return anio_origen;}
125
126
127
128 Terrestre::Terrestre():Animal(){}
129 Terrestre::Terrestre(string n,int a):Animal(n,a){}
130 Terrestre::Terrestre(string n,int a,int np,string al):Animal(n,a){
131 num_patas = np;
132 alimento = al;
133 }
134 Terrestre::~Terrestre(){}
135
136 void Terrestre::correr(){
137 cout<<"Terrestre Corriendo.."<<endl;
138 }
139 void Terrestre::descripcion(){
140 Animal::descripcion();
141 cout<<" ,Numero De Patas: "<<num_patas<<" ,Alimento: "<<alimento<<" (Terrestre)"<<endl;
142 }
143 //set y get
144 void Terrestre::setNumPatas(int n){num_patas = n;}
145 void Terrestre::setAlimento(string a){alimento = a;}
146 int Terrestre::getNumPatas()const{return num_patas;}
147 string Terrestre::getAlimento()const{return alimento;}
148
149
150
151 Acuatico::Acuatico():Animal(){}
152 Acuatico::Acuatico(string n,int a):Animal(n,a){}
153 Acuatico::Acuatico(string n,int a,string t):Animal(n,a){tipo_agua = t;}
154
155 Acuatico::~Acuatico(){}
156 void Acuatico::nadar(){
157 cout<<"Acuatico Nadando..."<<endl;
158 }
159 void Acuatico::descripcion(){
160 Animal::descripcion();
161 cout<<" ,Tipo Agua: "<<tipo_agua<<" (Acuatico)"<<endl;
162 }
163 //set y get
164 void Acuatico::getTipoAgua(string t){tipo_agua=t;}
165 string Acuatico::getTipoAgua()const{return tipo_agua;}
166
167
168
169 Aereo::Aereo():Animal(){}
170 Aereo::Aereo(string n,int a):Animal(n,a){}
171 Aereo::Aereo(string n,int a,char g,float l):Animal(n,a){
172 genero = g;
173 long_alas = l;
174 }
175
176 Aereo::~Aereo(){}
177
178 void Aereo::volar(){
179 cout<<"Aereo Volando.."<<endl;
180 }
181 void Aereo::descripcion(){
182 Animal::descripcion();
183 cout<<" ,Genero: "<<genero<<" ,Longitud Alas: "<<long_alas<<"mts. (Aereo)"<<endl;
184 }
185 //set y get
186 void Aereo::setGenero(char g){genero=g;}
187 void Aereo::setLongAlas(float l){long_alas=l;}
188 char Aereo::getGenero()const{return genero;}
189 float Aereo::getLongAlas()const{return long_alas;}
190
191
192 ///archivo MAIN.cpp
193 ///archivo MAIN.cpp
194 #include "ANIMAL.cpp"
195
196 int main(int argc, char const *argv[]){
197
198 Animal *v[4];
199 ///llenamos un vector de animales por el Principio de Sustitucion ES UN (en vector polimorfico)
200 /// AnimaL ES UN Animal
201 /// AnimaL ES UN Terrestre
202 /// AnimaL ES UN Acuatico
203 /// AnimaL ES UN Aereo
204
205 v[0] =new Animal("Caballo",2020);
206 v[1] =new Terrestre("Perro",2020,4,"Croquetas");
207 v[2] =new Acuatico("Tiburon",2000,"Salada");
208 v[3] =new Aereo("Aguila",2015,'M',1.1);
209
210 for(Animal *a :v){
211 a->descripcion();
212 cout<<endl;
213 }
214
215
216 return 0;
217 }
218
219 //-------------------------------------------------------------------
220 ///pregunta 3
221 ///pregunta 3
222 int verifica(int dia,int mes,int anio){
223 if((dia>=1 && dia<=31 && mes>=1 && mes<=12 && anio>=1) && !(anio%4!=0 && dia>28 && mes==2))return 1;
224 else return 0;
225 }
226
227 //-------------------------------------------------------------------
228 ///pregunta 4
229 ///pregunta 4
230 a)
231 TipoDeAcceso Significado
232 private: Los miembros de la clase declarados como private solo pueden ser usados por las funciones miembro
y amigos (clases o funciones) de la clase.
233 protected: Los miembros de la clase declarados como protected pueden ser usados por las funciones miembro y
amigos (clases o funciones) de la clase. Además, las clases derivadas de la clase también pueden usarlos.
234 public: Los miembros de la clase declarados como public pueden ser usados por cualquier función.
235 b)
236 encapsulacion
237 herencia
238 polimorfismo
239 c)
240 <nombre_de_la_funcion>([<lista_de_argumentos>]);
241 [opcional]
242 ej.
243 residuo(12,5);
244 verifica(13,4,2023);