# AUTOR: João Gabriel Camargo Ramos
# TURMA: Informática C
## Session Seven: Repetição FOREACH | Fund. Lógicos
TreinoFocadoA
TreinoFocadoB
TreinoFocadoC
## TreinoFocadoA
```csharp=
using System;
using System.Collections.Generic;
public class Retangulo
{
public double Base { 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> SomarImpares (List<int> numeros)
{
List<int> resposta = new List<int>();
int u = 0;
foreach(int item in numeros)
{
if (item % 2 != 0)
{
u += item;
}
}
resposta.Add(u);
return resposta;
}
public List<int> CalcularCubo (List<int> numeros)
{
List<int> resposta = new List<int>();
foreach(int item in numeros)
{
double d = Math.Pow(item,3);
int a = Convert.ToInt32(d);
resposta.Add(a);
}
return resposta;
}
public List<double> CalcularRaiz (List<double> numeros)
{
List<double> raiz = new List<double>();
foreach(double item in numeros)
{
double d = Math.Sqrt(item);
raiz.Add(d);
}
return raiz;
}
public int MaiorNumero (List<int> numeros)
{
int d = 0;
foreach(int item in numeros)
{
if(item > d)
{
d = item;
}
}
return d;
}
public double Media (List<double> notas)
{
double d = 0;
foreach(double item in notas)
{
d += item;
}
d = d/notas.Count;
return d;
}
public List<double> CalcularMedias (List<Notas> notas)
{
List<double> resposta = new List<double>();
foreach(Notas item in notas)
{
double d = (item.Nota1 + item.Nota2 + item.Nota3)/3;
resposta.Add(d);
}
return resposta;
}
private double AreaRetangulo (Retangulo retangulo)
{
return retangulo.Altura * retangulo.Base;
}
public List<double> AreasRetangulos (List<Retangulo> retangulos)
{
List<double> area = new List<double>();
foreach(Retangulo item in retangulos)
{
double a = AreaRetangulo(item);
area.Add(a);
}
return area;
}
}
List<Retangulo> a = new List<Retangulo>()
{
new Retangulo(){ Base = 4, Altura = 5 },
new Retangulo(){ Base = 7, Altura = 3 },
new Retangulo(){ Base = 8, Altura = 7 },
new Retangulo(){ Base = 2, Altura = 4 }
};
List<Notas> b = new List<Notas>()
{
new Notas(){ Nota1 = 8, Nota2 = 9, Nota3 = 10 },
new Notas(){ Nota1 = 10, Nota2 = 9, Nota3 = 10 },
new Notas(){ Nota1 = 8, Nota2 = 8, Nota3 = 8 },
new Notas(){ Nota1 = 1, Nota2 = 9, Nota3 = 10 },
new Notas(){ Nota1 = 5, Nota2 = 9, Nota3 = 5 },
new Notas(){ Nota1 = 4, Nota2 = 6, Nota3 = 9 }
};
List<int> dobli = new List<int>()
{
1,2,3,4,5,6,7,8,9,10
};
List<double> inti = new List<double>()
{
4,9,16,25,36,49,64
};
TreinoFocadoA c = new TreinoFocadoA();
List<int> x1 = c.SomarImpares(dobli);
List<int> x2 = c.CalcularCubo(dobli);
List<double> x3 = c.CalcularRaiz(inti);
int x4 = c.MaiorNumero(dobli);
double x5 = c.Media(inti);
List<double> x6 = c.CalcularMedias(b);
List<double> x7 = c.AreasRetangulos(a);
Console.WriteLine(string.Join(" - ", x1));
Console.WriteLine(string.Join(" - ", x2));
Console.WriteLine(string.Join(" - ", x3));
Console.WriteLine(x4);
Console.WriteLine(x5);
Console.WriteLine(string.Join(" - ", x6));
Console.WriteLine(string.Join(" - ", x7));
## TreinoFocadoB
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> UltimoDia (List<DateTime> datas)
{
List<DateTime> a = new List<DateTime>();
foreach(DateTime item in datas)
{
DateTime final = item.AddMonths(1);
DateTime d = final.AddDays(- item.Day);
a.Add(d);
}
return a;
}
public DateTime MaiorData (List<DateTime> datas)
{
DateTime d = DateTime.MinValue;
foreach(DateTime item in datas)
{
if(item > d)
{
d = item;
}
}
return d;
}
public List<Pessoa> FiltrarMaiores18 (List<Pessoa> pessoas)
{
List<Pessoa> resposta = new List<Pessoa>();
foreach(Pessoa item in pessoas)
{
if(item.Nascimento >= DateTime.Now.AddYears(-18))
{
resposta.Add(item);
}
}
return resposta;
}
public bool TodosMaiores18 (List<Pessoa> pessoas)
{
bool d = true;
foreach(Pessoa item in pessoas)
{
if(item.Nascimento < DateTime.Now.AddYears(-18))
{
d = false;
}
}
return d;
}
}
List<DateTime> Lista1 = new List<DateTime> () {
new DateTime(2021, 04, 14), new DateTime(2021, 05, 15)
};
List<Pessoa> pessoas = new List<Pessoa> () {
new Pessoa () {Nome = "Claytin", Nascimento = new DateTime(2021, 05, 05)},
new Pessoa () {Nome = "Bruno", Nascimento = new DateTime(2021, 01, 01)},
new Pessoa () {Nome = "Lucas", Nascimento = new DateTime(2021, 04 ,02)},
};
List<DateTime> Datas = new List<DateTime> () {
new DateTime(2021, 12, 12),
new DateTime(2015, 09, 09),
};
TreinoFocadoB treinoB = new TreinoFocadoB();
List<DateTime> Funcao1TreinoB = treinoB.UltimoDia(Lista1);
List<Pessoa> Funcao3TreinoB = treinoB.FiltrarMaiores18(pessoas);
bool Funcao4TreinoB = treinoB.TodosMaiores18(pessoas);
DateTime Funcao2TreinoB = treinoB.MaiorData(Datas);
Console.WriteLine("Função 1 treino B = " + String.Join(", ", Funcao1TreinoB));
Console.WriteLine("Função 2 treino B = " + Funcao2TreinoB);
Console.WriteLine("Função 3 treino B = " + String.Join(", ", Funcao3TreinoB));
Console.WriteLine("Função 4 treino B = " + String.Join(", ", Funcao4TreinoB));
TreinoFocadoC
using System;
using System.Collections.Generic;
public class Pessoaa
{
public string Nome { get; set; }
public DateTime Nascimento { get; set; }
public string Cidade { get; set; }
public override string ToString()
{
return $" ({Nome} - {Nascimento.ToString("dd/MM/yyyy")})";
}
}
public class TreinoFocadoC
{
public string SepararLetras (string frase)
{
string separado = string.Empty;
foreach(char item in frase)
{
separado += item + "-";
}
return separado;
}
public List<int> CodigoASCII (string frase)
{
List<int> a = new List<int>();
foreach (char item in frase)
{
int b = Convert.ToInt32(item);
a.Add(b);
}
return a;
}
public bool TodasVogais (string frase)
{
bool d = true;
frase.ToLower();
foreach(char item in frase)
{
if(item != 'a' && item != 'e' && item != 'i' && item != 'o' && item != 'u')
{
d = false;
break;
}
}
return d;
}
public string Alternar (Pessoaa pessoa)
{
char caracter = ' ';
string x = string.Empty;
foreach(char item in pessoa.Nome)
{
if (caracter == ' ')
x += item.ToString().ToUpper();
else
x += item.ToString().ToLower();
caracter = item;
}
return x;
}
public string Inverter (string frase)
{
string x = string.Empty;
foreach(char item in frase)
{
x = item + x;
}
return x;
}
public bool Palindromo (string frase)
{
bool d = false;
string g = Inverter(frase);
if(frase == g)
{
d = true;
}
return d;
}
}
## TreinoFocadoC treinoC = new TreinoFocadoC ();
Pessoaa Pessoa1 = new Pessoaa ();
Pessoa1.Nome = "Mariana Souza Linda";
Pessoa1.Nascimento = new DateTime(1990, 05 ,05);
Pessoa1.Cidade = "São Paulo";
List<int> ASCII = new List<int> () {
};
string Funcao1TreinoC = treinoC.SepararLetras("Olá, tudo bem");
Console.WriteLine("Função 1 Treino C = " + Funcao1TreinoC);
List<int> Funcao2TreinoC = treinoC.CodigoASCII("oi");
Console.WriteLine("Função 2 Treino C = " + String.Join(", ", Funcao2TreinoC));
bool Funcao3TreinoC = treinoC.TodasVogais("AA");
Console.WriteLine("Função 3 Treino C = " + Funcao3TreinoC);
string Funcao4TreinoC = treinoC.Alternar(Pessoa1);
Console.WriteLine("Função 4 Treino C = " + Funcao4TreinoC);
string Funcao5TreinoC = treinoC.Inverter("Olá, tudo bem?");
Console.WriteLine("Função 5 Treino C = " + Funcao5TreinoC);
bool Funcao6TreinoC = treinoC.Palindromo("Osso");
Console.WriteLine("Função 6 Treino C = " + Funcao6TreinoC);
{"metaMigratedAt":"2023-06-16T04:29:56.512Z","metaMigratedFrom":"Content","title":"AUTOR: João Gabriel Camargo Ramos","breaks":true,"contributors":"[{\"id\":\"b186730d-b9e4-4a77-8f97-f67305b05247\",\"add\":9378,\"del\":0}]"}