# Session Six: Repetição FOR || Fund. Lógica >[color=orange]**Autor:** Letícia Rodrigues da Silva **Turma:** IndoD **Número:** 25 [toc] ## Exercício 1 ```csharp= using System; using System.Collections.Generic; public class Retangulo { public double Basee {get; set;} public double altura {get; set;} } public class Notas { public double Nota1 {get; set;} public double Nota2 {get; set;} public double Nota3 {get; set;} } public class TreinoFocadoA { 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 final) { List<int> sequ = new List<int>(); for(int i = inicio; i <= final; i++) { sequ.Add(i); } return sequ; } public List<int> GerarSequenciaPares(int inicio1, int fim2) { List<int> seque = new List<int>(); for(int i = inicio1; i <= fim2; i+=2) { seque.Add(i); } return seque; } public int SomarAte(int fim3) { int soma = 0; for(int i = 0; i <= fim3; i++) { soma +=i; } return soma; } public double CalcularMedia(List<double> notas) { double soma = 0; for(int i = 0; i < notas.Count; i++) { soma += notas[i]; } double media = soma / notas.Count; return media; } public List<double> CalculaMedias(List<Notas> notasAlunos) { List<double> media = new List<double>(); for(int i = 0; i < notasAlunos.Count; i++) { Notas n = notasAlunos[i]; double m = (n.Nota1 + n.Nota2 + n.Nota3) / 3; media.Add(m); } return media; } public List<double> CalcularQuadrados(List<double> numeros) { List<double> quadrados = new List<double>(); for(int i = 0; i < numeros.Count; i++) { double qq = numeros[i]; double n = Math.Pow(qq, 2); quadrados.Add(n); } return quadrados; } private double AreaRetangulo(Retangulo retangulo) { double calc = retangulo.Basee * retangulo.altura; return calc; } public List<double> AreaRetangulos(List<Retangulo> retangulos) { List<double> ret = new List<double>(); for(int i = 0; i < retangulos.Count; i++) { Retangulo r = retangulos[i]; double rets = AreaRetangulo(r); ret.Add(rets); } return ret; } } TreinoFocadoA t = new TreinoFocadoA(); int fim = 25; List<int> seq = t.GerarSequencia(fim); Console.WriteLine(string.Join(", ", seq)); int inicio = 3; int final = 12; List<int> sequ = t.GerarSequenciA(inicio, final); Console.WriteLine(string.Join(", ", sequ)); int inicio1 = 2; int fim2 = 15; List<int> seque = t.GerarSequenciaPares(inicio1, fim2); Console.WriteLine(string.Join(", ", seque)); int fim3 = 18; int soma = t.SomarAte(fim3); Console.WriteLine(soma); List<double> totalmedia = new List<double>(); totalmedia.Add(6); totalmedia.Add(7.5); totalmedia.Add(5); double n = t.CalcularMedia(totalmedia); Console.WriteLine(n); Notas n1 = new Notas(); n1.Nota1 = 8; n1.Nota2 = 4.5; n1.Nota3 = 7; Notas n2 = new Notas(); n2.Nota1 = 9.5; n2.Nota2 = 6; n2.Nota3 = 6.5; Notas n3 = new Notas(); n3.Nota1 = 10; n3.Nota2 = 7; n3.Nota3 = 5; List<Notas> li = new List<Notas>() {n1, n2, n3}; List<double> medias = t.CalculaMedias(li); Console.WriteLine(string.Join(" - ", medias)); List<double> q = new List<double>() {5, 6, 12}; List<double> quadrado = t.CalcularQuadrados(q); Console.WriteLine(string.Join(", ", quadrado)); Retangulo retangs = new Retangulo(); retangs.altura = 15; retangs.Basee = 5; List<Retangulo> retang = new List<Retangulo>() {retangs}; List<double> area = t.AreaRetangulos(retang); Console.WriteLine(string.Join(", ", area)); ``` ## Exercício 2 ```csharp= using System; using System.Collections.Generic; public class Pessoa { public string Nome {get; set;} public DateTime Nascimento {get; set;} public override string ToString() { return "(" + Nome + ", " + Nascimento.ToString("dd/mm/yyyy") + ")"; } } public class TreinoFocadoB { public List<DateTime> GerarSequenciaD(int qtd) { List<DateTime> data = new List<DateTime>(); DateTime inicial = DateTime.Now; for(int i = 0; i < qtd; i++) { inicial = inicial.AddDays(i); data.Add(inicial); } return data; } public List<DateTime> GerarSequenciaD1(int qtde, DateTime data) { List<DateTime> d = new List<DateTime>(); DateTime inicial = data; for(int i = 0; i < qtde; i++) { inicial = inicial.AddDays(i); d.Add(inicial); } return d; } public List<DateTime> GerarSequenciaDiasPares(int qtdd) { List<DateTime> pares = new List<DateTime>(); DateTime datapar = DateTime.Now.Date; for(int i = 0; i < qtdd; i++) { if(datapar.Day % 2 == 0) datapar = datapar.AddDays(2); pares.Add(datapar); } return pares; } private string Signo(DateTime nascimento) { string signo = string.Empty; DateTime a = nascimento; DateTime A = new DateTime(a.Year,03,21); DateTime AA = new DateTime(a.Year,04,20); DateTime T = new DateTime(a.Year,04,21); DateTime TT = new DateTime(a.Year,05,20); DateTime G = new DateTime(a.Year,05,21); DateTime GG = new DateTime(a.Year,06,20); DateTime C = new DateTime(a.Year,06,21); DateTime CC = new DateTime(a.Year,07,21); DateTime L = new DateTime(a.Year,07,22); DateTime LL = new DateTime(a.Year,08,22); DateTime V = new DateTime(a.Year,08,23); DateTime VV = new DateTime(a.Year,09,22); DateTime LI = new DateTime(a.Year,09,23); DateTime LII = new DateTime(a.Year,10,22); DateTime E = new DateTime(a.Year,10,23); DateTime EE = new DateTime(a.Year,11,21); DateTime S = new DateTime(a.Year,11,22); DateTime SS = new DateTime(a.Year,12,21); DateTime AQ = new DateTime(a.Year,01,21); DateTime AQQ = new DateTime(a.Year,02,19); DateTime P = new DateTime(a.Year,02,20); DateTime PE = new DateTime(a.Year,03,20); if (a >= A && a <= AA) { signo = "Seu signo é Áries"; } else if (a >= T && a <= TT) { signo = "Seu signo é Touro"; } else if (a >= G && a <= GG) { signo = "Seu signo é Gêmeos"; } else if (a >= C && a <= CC) { signo = "Seu signo é Câncer"; } else if (a >= L && a <= LL) { signo = "Seu signo é Leão"; } else if (a >= V && a <= VV) { signo = "Seu signo é Virgem"; } else if (a >= LI && a <= LII) { signo = "Seu signo é Libra"; } else if (a >= E && a <= EE) { signo = "Seu signo é Escorpião"; } else if (a >= S && a <= SS) { signo = "Seu signo é Sagitário"; } else if (a >= AQ && a <= AQQ) { signo = "Seu signo é Aquário"; } else if (a >= P && a <= PE) { signo = "Seu signo é Peixes"; } else { signo = "Seu signo é Capricórnio"; } return signo; } public List<string> Signos(List<DateTime> nascimentos) { List<string> s = new List<string>(); for(int i = 0; i < nascimentos.Count; i++) { DateTime sig = nascimentos[i]; string datasig = Signo(sig); } return s; } public List<Pessoa> FiltrarMaiores18(List<Pessoa> pessoas) { List<Pessoa> filtro = new List<Pessoa>(); for(int i = 0; i < pessoas.Count; i++) { Pessoa p = pessoas[i]; if(p.Nascimento <= DateTime.Now.AddYears(-18)) { filtro.Add(p); } } return filtro; } public bool TodosMaiores18(List<Pessoa> pessoass) { bool maiores = true; for(int i = 0; i < pessoass.Count; i++) { Pessoa pe = pessoass[i]; if(pe.Nascimento > DateTime.Now.AddYears(-18)) { maiores = false; } } return maiores; } } TreinoFocadoB treinob = new TreinoFocadoB(); List<DateTime> d1 = treinob.GerarSequenciaD(5); Console.WriteLine(string.Join(" - ", d1)); List<DateTime> d2 = treinob.GerarSequenciaD1(5, new DateTime(2021, 6, 12)); Console.WriteLine(string.Join(" - ", d2)); List<DateTime> p = treinob.GerarSequenciaDiasPares(4); Console.WriteLine(string.Join(" - ", p)); List<Pessoa> maior = new List<Pessoa>() { new Pessoa() {Nome = "Fulano", Nascimento = new DateTime(2000, 04, 01)}, new Pessoa() {Nome = "Letícia", Nascimento = new DateTime(2003, 08, 31)}, new Pessoa() {Nome = "Fulaninho", Nascimento = new DateTime(1999, 06, 24)} }; List<Pessoa> resultado = treinob.FiltrarMaiores18(maior); Console.WriteLine(string.Join(", ", resultado)); bool maior18 = treinob.TodosMaiores18(maior); Console.WriteLine(string.Join(", ", maior18)); ``` ## Exercício 3 ```csharp= using System; using System.Collections.Generic; public class Pessoa { public string Nome {get; set;} public DateTime Nascimento {get; set;} public string Cidade {get; set;} } public class TreinoFocadoC { public string SepararLetrar(string frase) { string letras = string.Empty; for(int i = 0; i < frase.Length; i++) { char separar = frase[i]; letras = letras + separar + "-"; } return letras; } public string Inverter(string frase) { string inverter = string.Empty; for(int i = 0; i < frase.Length; i++) { char ler = frase[i]; inverter = ler + inverter; } return inverter; } public bool TodasVogais(string frase) { bool vogais = true; for(int i = 0; i < frase.Length; i++) { if(frase.Contains("A") && frase.Contains("a") || frase.Contains("E") && frase.Contains("e") || frase.Contains("I") && frase.Contains("i") || frase.Contains("O") && frase.Contains("o") || frase.Contains("U") && frase.Contains("u")) { vogais = true; } } return vogais; } private string UltimoNome(string nomeCompleto) { string ultimo = string.Empty; for(int i = 0; i < nomeCompleto.Length; i++) { if(nomeCompleto.Contains(" ")) { int espaco = nomeCompleto.LastIndexOf(" "); string ult = nomeCompleto.Substring(espaco); string nome = ult.Trim(); nomeCompleto = nome; } } return ultimo; } public List<string> UltimosNomes(List<string> nomecompleto) { List<string> nomes = new List<string>(); for(int i = 0; i < nomecompleto.Count; i++) { string n = nomecompleto[i]; nomes.Add(n); } return nomes; } public bool ApenasCoresPrimarias(List<string> cores) { bool corprimaria = true; for(int i = 0; i < cores.Count; i++) { string cor = cores[i]; if(cor != "azul" && cor != "amarelo" && cor != "vermelho") { corprimaria = false; } } return corprimaria; } public bool SenhaForte(string senha) { bool senhaforte = true; for(int i = 0; i < senha.Length; i++) { bool caracter = senha.Contains("!") || senha.Contains("@") || senha.Contains("#") || senha.Contains("$") || senha.Contains("%") || senha.Contains("&") || senha.Contains("*"); bool digitos = senha.Length >= 8; bool senhaf = caracter == digitos; if(senhaf) { senhaforte = true; } } return senhaforte; } } TreinoFocadoC treinoC = new TreinoFocadoC(); string s = treinoC.SepararLetrar("lele linda S2"); Console.WriteLine(s); string inver = treinoC.Inverter("Leticia"); Console.WriteLine(inver); bool v = treinoC.TodasVogais("Oie"); Console.WriteLine(v); List<string> n = new List<string>() { "Letícia Rodrigues", "Henry Zarlenga", "Josefina Claudia" }; List<string> nomeC = treinoC.UltimosNomes(n); Console.WriteLine(string.Join(", ", nomeC)); List<string> todascores = new List<string>() { "roxo", "azul", "vermelho" }; bool coresprimarias = treinoC.ApenasCoresPrimarias(todascores); Console.WriteLine(coresprimarias); bool senhaF = treinoC.SenhaForte("lele@#12"); Console.WriteLine(senhaF); ```
{"metaMigratedAt":"2023-06-16T03:04:43.754Z","metaMigratedFrom":"Content","title":"Session Six: Repetição FOR || Fund. Lógica","breaks":true,"contributors":"[{\"id\":\"f2f98191-1ff5-4afd-8e66-66ff77c4c5b1\",\"add\":13305,\"del\":7}]"}
Expand menu