-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
118 lines (86 loc) · 3.49 KB
/
Program.cs
File metadata and controls
118 lines (86 loc) · 3.49 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program
{
static void Main(string[] args)
{
//Ejecicio 1
int[] integerArray1 = { 1, 20, 3, 44, 5, 60, 7, 88, 9, 100 };
Console.WriteLine($"Posicion 5: [{integerArray1[5]}]\n");
///Salida: Posicion 5: [60]
//Ejercicio 2
Random aleatorio = new Random();
int[] array = new int[5];
for (int i = 0; i < array.Length; i++)
{
array[i] = 0;
Console.WriteLine($"Arreglo[{i}] = {array[i]}");
}
Console.WriteLine();
for (int i = 0; i < array.Length; i++)
{
array[i] = aleatorio.Next(0, 1000);
Console.WriteLine($"Arreglo[{i}] = {array[i]}");
}
Console.WriteLine();
//Ejercicio 3
ArrayObject Arreglo_Objetos = new ArrayObject();
ArrayObject Arreglo_Objetos2 = new ArrayObject();
ArrayObject Arreglo_Objetos3 = new ArrayObject();
String[] miArreglo = new String[] { Arreglo_Objetos.Color, Arreglo_Objetos2.Animal, Arreglo_Objetos3.Maquina };
ArrayObject[] Arreglo_Objetos4 = new ArrayObject[] { new ArrayObject(), new ArrayObject(), new ArrayObject() };
for (int i = 0; i < miArreglo.Length; i++)
{
Console.WriteLine($"Objetos del arreglo: {miArreglo[i]}");
}
Console.WriteLine($"\nObjeto 1: {Arreglo_Objetos4[2].Color}" +
$"\nObjeto 2: {Arreglo_Objetos4[0].Animal}" +
$"\nObjeto 3: {Arreglo_Objetos4[1].Maquina}");
//Ejercicio 4
Animal[] ObjetoAnimal = new Animal[] { new Animal("Perro", "woof woof"), new Animal("Gato", "miau miau") };
for (int i = 0; i < ObjetoAnimal.Length; i++)
{
Console.WriteLine($"\n El {ObjetoAnimal[i].Nombreanimal} dice '{ ObjetoAnimal[i].Accion}' ");
}
//Ejercicio 5
Mamifero[] ObjetoMamifero = new Mamifero[] { new Mamifero("Pasto", "muu", "Vaca"), new Mamifero("Carne", "grrr", "Tigre")};
for (int i = 0; i < ObjetoMamifero.Length; i++)
{
Console.WriteLine($"\n Mamifero: La/El {ObjetoMamifero[i].Nombreanimal} dice '{ ObjetoMamifero[i].Accion}' y come {ObjetoMamifero[i].Comida}");
}
Console.ReadLine();
}
}
public class ArrayObject
{
private String color = "Rojo";
private String animal = "Perro";
private String maquina = "Auto";
public string Color { get => color; set => color = value; }
public string Animal { get => animal; set => animal = value; }
public string Maquina { get => maquina; set => maquina = value; }
}
public class Animal
{
private string nombreanimal;
private string accion;
public Animal(string nombreanimal, string accion)
{
this.nombreanimal = nombreanimal;
this.accion = accion;
}
public string Nombreanimal { get => nombreanimal; set => nombreanimal = value; }
public string Accion { get => accion; set => accion = value; }
}
public class Mamifero : Animal
{
private string comida;
public Mamifero(string comida, string accion, string nombreanimal): base(nombreanimal, accion)
{
this.comida = comida;
}
public string Comida { get => comida; set => comida = value; }
}