# List e For | Fund. Lógica **Author:** Matheus Rafael Morato Rocha **Turma:** InfoC **Número:** 40 [TOC] ## Nível 1 ```csharp= using System; using System.Collections.Generic; public class Notas { public double Nota1 { get; set; } public double Nota2 { get; set; } public double Nota3 { get; set; } } public class Retangulo { public double Base; public double Altura; } public class TreinoFocado1 { public List<int> GerarSequencia(int fim) { List<int> seq = new List<int>(); for (int i = 0; i <= fim; i++) { seq.Add(i); } return seq; } public List<int> GerarSequencia(int inicio,int fim) { List<int> seq = new List<int>(); for (int i = inicio; i <= fim; i++) { seq.Add(i); } return seq; } public List<int> GerarSequenciaPares(int inicio,int fim) { List<int> seq = new List<int>(); for (int i = inicio; i <= fim; i++) { if (i % 2 == 0) { seq.Add(i); } } return seq; } public int SomarAte (int fim) { int somar = 0; for (int i = 0; i <= fim; i++) { somar += i; } return somar; } public double CalcularMedia(List<double> notas) { double soma = 0; for (int i = 0; i < notas.Count; i++) { double n = notas[i]; soma = soma + n; } double media = soma / notas.Count; return media; } public List<double> CalcularMedias(List<Notas> notas) { List<double> medias = new List<double>(); for (int i = 0; i < notas.Count; i++) { Notas Aluno = notas[i]; double media = (Aluno.Nota1 + Aluno.Nota2 + Aluno.Nota3) / 3; medias.Add(media); } return medias; } public List<double> CalcularQuadrados (List<double> numeros) { List<double> Quadrado = new List<double>(); for (int i = 0; i < numeros.Count; i++) { double numero = numeros[i]; double quadrados = Math.Pow(numero, 2); Quadrado.Add(quadrados); } return Quadrado; } private double AreaRetangulo(Retangulo retangulo) { double area = retangulo.Base * retangulo.Altura; return area; } public List<double> AreaRetangulos(List<Retangulo> retangulos) { List<double> retangulo = new List<double>(); for (int i = 0; i < retangulos.Count; i++) { Retangulo ret = retangulos[i]; double area = AreaRetangulo(ret); retangulo.Add(area); } return retangulo; } } List<Retangulo> retangulos = new List<Retangulo>() { new Retangulo() { Base = 5, Altura = 4 }, new Retangulo() { Base = 8, Altura = 4 }, new Retangulo() { Base = 10, Altura = 2 } }; List<double> notas = new List<double> () {10, 8, 6}; List<double> Quadrado = new List<double> () {2,3,4}; Notas nota1 = new Notas(); nota1.Nota1 = 10; nota1.Nota2 = 8; nota1.Nota3 = 6; Notas nota2 = new Notas(); nota2.Nota1 = 8; nota2.Nota2 = 6; nota2.Nota3 = 4; Notas nota3 = new Notas(); nota3.Nota1 = 8; nota3.Nota2 = 10; nota3.Nota3 = 6; List<Notas> Notasss = new List<Notas>() { nota1, nota2, nota3 }; TreinoFocado1 x = new TreinoFocado1(); List<int> seq = x.GerarSequencia(10); List<int> seq2 = x.GerarSequencia(5,10); List<int> seq3 = x.GerarSequenciaPares(5,15); int somar = x.SomarAte(10); double notas1 = x.CalcularMedia(notas); List<double> notas2 = x.CalcularMedias(Notasss); List<double> CalcularQuadrado = x.CalcularQuadrados(Quadrado); List<double> area2 = x.AreaRetangulos(retangulos); string a = string.Join(", ", seq); string b = string.Join(", ", seq2); string c = string.Join(", ", seq3); string NotasFinal = string.Join(", ", notas2); string QuadradoTotal = string.Join(", ", CalcularQuadrado); string retangulo = string.Join(", ", area2); Console.WriteLine(a); Console.WriteLine(b); Console.WriteLine(c); Console.WriteLine(somar); Console.WriteLine(NotasFinal); Console.WriteLine(notas1); Console.WriteLine(QuadradoTotal); Console.WriteLine(retangulo); // 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 // 5, 6, 7, 8, 9, 10 // 6, 8, 10, 12, 14 // 8, 6, 8 // 8 // 4, 9, 16 // 20, 32, 20 ``` ## Nível 2 ```csharp= using System; using System.Collections.Generic; public class Pessoa { public string Nome { get; set; } public DateTime Nascimento { get; set; } } public class TreinoFocado2 { public List<DateTime> GerarSequencia(int qtd) { DateTime Dia = DateTime.Now; List<DateTime> prox = new List<DateTime>(); for (int data= 0; data <= qtd; data++) { DateTime dt = Dia.AddDays(data); prox.Add(dt); } return prox; } public List<DateTime> GerarSequencia(DateTime data, int qtd) { List<DateTime> prox = new List<DateTime>(); for (int datas= 0; datas <= qtd; datas++) { DateTime dt = data.AddDays(datas); prox.Add(dt); } return prox; } public List<DateTime> GerarSequenciaPares(int qtd) { DateTime Dia = DateTime.Now; List<DateTime> prox = new List<DateTime>(); for (int data= 0; data <= qtd; data++) { if (data % 2 == 1) { DateTime dt = Dia.AddDays(data); prox.Add(dt); } } return prox; } private string Signo (DateTime nascimento) { string Signo = ""; if (nascimento.Day >=21 && nascimento.Month == 1 || nascimento.Day <= 18 && nascimento.Month == 2) { Signo = "Aquário"; } else if (nascimento.Day >= 19 && nascimento.Month == 2 || nascimento.Day <= 20 && nascimento.Month == 3) { Signo = "Peixes"; } else if (nascimento.Day >=21 && nascimento.Month == 3 || nascimento.Day <= 20 && nascimento.Month == 4) { Signo = "Áries"; } else if (nascimento.Day >=21 && nascimento.Month == 4 || nascimento.Day <= 20 && nascimento.Month == 5) { Signo = "Touro"; } else if (nascimento.Day >=21 && nascimento.Month == 5 || nascimento.Day <= 20 && nascimento.Month == 6) { Signo = "Gêmeos"; } else if (nascimento.Day >=21 && nascimento.Month == 6 || nascimento.Day <= 22 && nascimento.Month == 7) { Signo = "Câncer"; } else if (nascimento.Day >=23 && nascimento.Month == 7 || nascimento.Day <= 22 && nascimento.Month == 8) { Signo = "Leão"; } else if (nascimento.Day >=23 && nascimento.Month == 8 || nascimento.Day <= 22 && nascimento.Month == 9) { Signo = "Virgem"; } else if (nascimento.Day >=23 && nascimento.Month == 9 || nascimento.Day <= 22 && nascimento.Month == 10) { Signo = "Libra"; } else if (nascimento.Day >=23 && nascimento.Month == 10 || nascimento.Day <= 21 && nascimento.Month == 11) { Signo = "Escorpião"; } else if (nascimento.Day >=22 && nascimento.Month == 11 || nascimento.Day <= 21 && nascimento.Month == 12) { Signo = "Sagitário"; } else if (nascimento.Day >=22 && nascimento.Month == 12 || nascimento.Day <= 20 && nascimento.Month == 1) { Signo = "Capricórnio"; } else { Signo = "Se chegou aqui, seu signo é Alienígina"; } return Signo; } public List<string> Signos(List<DateTime> nascimento) { List<string> z = new List<string> (); for (int i = 0; i < nascimento.Count; i++) { DateTime a = nascimento[i]; string x = Signo(a); z.Add(x); } return z; } public List<Pessoa> FiltrarMaiores18(List<Pessoa> pessoas) { List<Pessoa> a = new List<Pessoa>(); for (int i = 0; i <= pessoas.Count - 1; i++) { if (pessoas[i].Nascimento.AddYears(18) <= DateTime.Now) a.Add(pessoas[i]); else continue; } return a; } public bool TodosMaiores18(List<Pessoa> pessoas) { bool a = true; for (int i = 0; i <= pessoas.Count -1; i++) { if (pessoas[i].Nascimento.AddYears(18) <= DateTime.Now) { a = true; } else { a = false; break; } } return a; } } DateTime NascimentoMeu = new DateTime(2004 , 09, 10); DateTime NascimentoMiguel = new DateTime(2019 , 10, 16); DateTime DataNova1 = new DateTime(2020 , 10, 16); List<DateTime> DataNova = new List<DateTime> () {NascimentoMeu,NascimentoMiguel}; List<Pessoa> Maior = new List<Pessoa>() { new Pessoa() { Nome = "Matheus", Nascimento = new DateTime(2004 , 09, 10)}, new Pessoa() { Nome = "Vasco", Nascimento = new DateTime(1898 , 08, 21) }, new Pessoa() { Nome = "Ronaldinho", Nascimento = new DateTime(1980 , 03, 21) } }; TreinoFocado2 a = new TreinoFocado2(); List<DateTime> z = a.GerarSequencia(3); string x = string.Join(" - ", z); Console.WriteLine(x); List<DateTime> z2 = a.GerarSequencia(DataNova1,4); string x2 = string.Join(" - ", z2); Console.WriteLine(x2); List<DateTime> z3 = a.GerarSequenciaPares(2); string x3 = string.Join(" - ", z3); Console.WriteLine(x3); List<string> z5 = a.Signos(DataNova); string x4 = string.Join(", ", z5); Console.WriteLine(x4); List<Pessoa> z6 = a.FiltrarMaiores18(Maior); string x5 = string.Join(" - ", z6); Console.WriteLine(x5); bool z7 = a.TodosMaiores18(Maior); string x6 = string.Join(" - ", z7); Console.WriteLine(x6); // 20/06/2021 18:57:42 - 21/06/2021 18:57:42 - 22/06/2021 18:57:42 - 23/06/2021 18:57:42 // 16/10/2020 00:00:00 - 17/10/2020 00:00:00 - 18/10/2020 00:00:00 - 19/10/2020 00:00:00 - 20/10/2020 00:00:00 // 21/06/2021 18:57:42 // Virgem, Libra // Submission#0+Pessoa - Submission#0+Pessoa // False ``` ## Nível 3 ```csharp= public class Pessoa { public string Nome { get; set; } public DateTime Nascimento { get; set; } public string Cidade { get; set; } } public class TreinoFocado3 { public string SepararLetras(string frase) { string separado = ""; for (int i = 0; i < frase.Length; i++) { char letra = frase[i]; separado += letra + "-"; } return separado; } public string InverterLetras(string frase) { string inverter = ""; for (int i = frase.Length -1; i >= 0; i--) { inverter += frase[i]; } return inverter; } public bool TodasVogais(string frase) { frase = frase.ToLower(); bool a = false; if (frase.Contains("a") || frase.Contains("e") || frase.Contains("i") || frase.Contains("o") || frase.Contains("u")) { for (int i = 0; i < frase.Length; i++) { if (frase[i] == 'a' || frase[i] == 'e' || frase[i] == 'i' || frase[i] == 'o' || frase[i] == 'u') { a = true; } else { a = false; } } } return a; } private string UltimoNome(string Nome) { int a = Nome.LastIndexOf(" "); string UltimoNome = Nome.Substring(a); string FinalName = UltimoNome.Trim(); return FinalName; } public List<string> UltimosNomes(List<string> Nome) { List<string> Lista = new List<string> (); for (int i = 0; i < Nome.Count; i++) { Lista.Add(UltimoNome(Nome[i])); } return Lista; } public bool ApenasCoresPrimarias(List<string> cores) { bool a = false; List<string> Lista = new List<string> (); for (int i = 0; i < cores.Count; i++) { if (cores[i] == "Azul" || cores[i] == "Vermelho" || cores[i] == "Amarelo") { a = true; } else { a = false; } } return a; } public bool SenhaForte(string senha) { bool teste = false; bool numero = false; bool caracter = false; bool digitos = false; int quantidade = 0; int quantidade2 = 0; if (senha.Length >= 8) digitos = true; else digitos = false; for (int i = 0; i < senha.Length; i++) { if (senha[i] == '0'|| senha[i] == '1' || senha[i] == '2' || senha[i] == '3' || senha[i] == '4' || senha[i] == '5' || senha[i] == '6' || senha[i] == '7' || senha[i] == '8' || senha[i] == '9') { quantidade++; numero = true; } else if (senha[i] != '0'|| senha[i] != '1' || senha[i] != '2' || senha[i] != '3' || senha[i] != '4' || senha[i] != '5' || senha[i] != '6' || senha[i] != '7' || senha[i] != '8' || senha[i] != '9') { numero = false; } } if (quantidade >= 2) numero = true; else numero = false; for (int i = 0; i < senha.Length; i++) { if (senha[i] == '!'|| senha[i] == '@' || senha[i] == '#' || senha[i] == '$' || senha[i] == '%' || senha[i] == '¨' || senha[i] == '&' || senha[i] == '*' || senha[i] == '(' || senha[i] == ')') { quantidade2++; } else { continue; } } if (quantidade2 >= 2) caracter = true; else caracter = false; if (digitos && caracter && numero) teste = true; else teste = false; return teste; } } Pessoa b = new Pessoa(); b.Nome = "Matheus"; b.Nascimento = new DateTime(2004 , 09, 10); b.Cidade = "São Paulo"; string frase = "Vasco Minha Vida Minha Historia"; string Vogais = "Vasco Minha Vida Minha Historia"; string Nome = "Matheus Rafael"; string Nome2 = "Vasco Da Gama"; string Nome3 = "Ronaldinho Gaucho"; string Cor1 = "Azul"; string Cor2 = "Amarelo"; string Cor3 = "Vermelho"; string senha = "s&nha@87"; List<string> Cores = new List<string> () { Cor1, Cor2, Cor3 }; List<string> Nomes = new List<string> () { Nome, Nome2, Nome3 }; TreinoFocado3 a = new TreinoFocado3(); string SepararLetras = a.SepararLetras(frase); string InverterLetras = a.InverterLetras(frase); bool TodasVogais = a.TodasVogais(Vogais); List<string> UltimosNomes = a.UltimosNomes(Nomes); bool ApenasCoresPrimarias = a.ApenasCoresPrimarias(Cores); bool SenhaForte = a.SenhaForte(senha); string UltimosNomes2 = string.Join(", ", UltimosNomes); Console.WriteLine(SepararLetras); Console.WriteLine(InverterLetras); Console.WriteLine(TodasVogais); Console.WriteLine(UltimosNomes2); Console.WriteLine(ApenasCoresPrimarias); Console.WriteLine(SenhaForte); // V-a-s-c-o- -M-i-n-h-a- -V-i-d-a- -M-i-n-h-a- -H-i-s-t-o-r-i-a- // airotsiH ahniM adiV ahniM ocsaV // True // Rafael, Gama, Gaucho // True // True ```
{"metaMigratedAt":"2023-06-16T02:53:05.818Z","metaMigratedFrom":"Content","title":"List e For | Fund. Lógica","breaks":true,"contributors":"[{\"id\":\"0ba297e4-eafa-413a-9b17-c3ef1702e693\",\"add\":15521,\"del\":0}]"}
Expand menu