-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
118 lines (94 loc) · 3.04 KB
/
Program.cs
File metadata and controls
118 lines (94 loc) · 3.04 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 bytebank.Modelos.Conta;
using bytebank_ATENDIMENTO.bytebank.Util;
using ByteBankArray;
#region Exemplos Arrays em C#
//TestaArrayInt();
//TestaBuscarPalavra();
void TestaArrayInt()
{
int[] idades = new int[5];
idades[0] = 30;
idades[1] = 40;
idades[2] = 17;
idades[3] = 21;
idades[4] = 18;
Console.WriteLine($"Tamanho do Array {idades.Length}");
int acumulador = 0;
for (int i = 0; i < idades.Length; i++)
{
int idade = idades[i];
Console.WriteLine($"índice [{i}] = {idade}");
acumulador += idade;
}
int media = acumulador / idades.Length;
Console.WriteLine($"Média de idades = {media}");
}
void TestaBuscarPalavra()
{
string[] arrayDePalavras = new string[5];
for (int i = 0; i < arrayDePalavras.Length; i++)
{
Console.Write($"Digite {i + 1}ª Palavra: ");
arrayDePalavras[i] = Console.ReadLine();
}
Console.Write("Digite palavara a ser encontrada: ");
var busca = Console.ReadLine();
foreach (string palavra in arrayDePalavras)
{
if (palavra.Equals(busca))
{
Console.WriteLine($"Palavra encontrada = {busca}.");
break;
}
}
}
//[5,9][1,8][7,1][10][6,9]
//Array amostra = Array.CreateInstance(typeof(double), 5);
Array amostra = new double[5];
amostra.SetValue(5.9, 0);
amostra.SetValue(1.8, 1);
amostra.SetValue(7.1, 2);
amostra.SetValue(10, 3);
amostra.SetValue(6.9, 4);
///TestaMediana(amostra);
void TestaMediana(Array array)
{
if ((array == null) || (array.Length == 0))
{
Console.WriteLine("Array para cálculo da mediana está vazio ou nulo.");
}
//Mediana
double[] numerosOrdenados = (double[])array.Clone();
Array.Sort(numerosOrdenados);
//[1,8][5,9][6,9][7,1][10]
int tamanho = numerosOrdenados.Length;
int meio = tamanho / 2;
double mediana = (tamanho % 2 != 0) ? numerosOrdenados[meio] : (numerosOrdenados[meio] +
numerosOrdenados[meio - 1]) / 2;
Console.WriteLine($"Com base na amostra a mediana = {mediana}.");
}
void TestaArrayDeContasCorrentes()
{
ListaDeContasCorrentes listaDeContas = new ListaDeContasCorrentes();
listaDeContas.Adicionar(new ContaCorrente(874));
listaDeContas.Adicionar(new ContaCorrente(874));
listaDeContas.Adicionar(new ContaCorrente(874));
listaDeContas.Adicionar(new ContaCorrente(874));
listaDeContas.Adicionar(new ContaCorrente(874));
listaDeContas.Adicionar(new ContaCorrente(874));
var contaDoAndre = new ContaCorrente(963);
listaDeContas.Adicionar(contaDoAndre);
//listaDeContas.ExibeLista();
//Console.WriteLine("============");
//listaDeContas.Remover(contaDoAndre);
//listaDeContas.ExibeLista();
for (int i = 0; i < listaDeContas.Tamanho; i++)
{
ContaCorrente conta = listaDeContas[i];
Console.WriteLine($"Indice [{i}] = {conta.Conta}/{conta.Numero_agencia}");
}
}
//TestaArrayDeContasCorrentes();
#endregion
Console.WriteLine("Boas Vindas ao ByteBank, Atendimento.");
new ByteBank_Atendimento().AtendimentoCliente();