# Session six - REPETIÇÃO FOR | Fund.Logica | 2° bimestre
**Nome** Kevin Ribeiro de Andrade
**Número** 27
**Turma** Informática A
## Exercício 1
Crie a(s) classe(s) representando a abstração de função e/ou dados ao lado. Abaixo
a especificação das situações a serem resolvidas:
▪ Realize a lógica para implementar uma função que gere uma sequência de valores
iniciando do zero até um valor final recebido por parâmetro.
Ex. (5) => {0,1,2,3,4,5}, (3) => {0,1,2,3}, (0) => { }
▪ Realize a lógica para implementar uma função que gere uma sequência de valores a
partir de um número inicial e final.
Ex. (2,4) => {2,3,4}, (1, 2) => {1,2}, (0,0) => { 0 }
▪ Realize a lógica para implementar uma função que gere uma sequência de valores
pares a partir de um número inicial e final.
Ex. (2,7) => {2,4,6}, (1, 2) => { 2 }, (0,0) => { 0 }
▪ Realize a lógica para implementar uma função que some os números naturais de 0
até um número final informado.
Ex. (5) => 15, (3) => 6
▪ Realize a lógica para implementar uma função que calcule a média a partir de uma
lista de notas.
Ex. ({5,5,5}) => 5, ({6,8}) => 7, ({4,6,8, 10}) => 7
▪ Realize a lógica para implementar uma função que calcule a média para cada aluno a
partir de uma lista de Notas.
▪ Realize a lógica para implementar uma função que calcule a potência ao quadrado
para cada número em uma lista.
Ex. ({2,3,4}) => {4,9,16}
▪ Realize a lógica para implementar uma função que calcule a área do retângulo.
▪ Realize a lógica para implementar uma função que calcule a área do retângulo pra
cada Retângulo da lista.
```csharp=
using System;
using System.Collections.Generic;
public class Retangulo
{
public double Altura {get; set;}
public double Basee {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> Contagem (int fim)
{
List<int> Seq = new List<int>();
for(int x = 0; x <= fim; x++)
{
Seq.Add(x);
}
return Seq;
}
public List<int> GerarSequencia(int Inicio, int Fim)
{
List<int> Seq = new List<int>();
for(int x = 0; Inicio <= Fim; x++)
{
Seq.Add(x);
}
return Seq;
}
public List<long> GerandoSequenciaPar (long Inicio, long Fim)
{
List<long> SeqPar = new List<long>();
for (int x = 0; Inicio <= Fim; x++)
{
if (x % 2 == 0)
SeqPar.Add(x);
}
return SeqPar;
}
public int SomarAte(int Fim)
{
int NumberNatu = 0;
for (int x = 0; x <= Fim; x++)
{
NumberNatu += x;
}
return NumberNatu;
}
public double CalcularMedia (List<double> Notas)
{
double SomaNotas = 0;
for (int nt = 0; nt < Notas.Count; nt++)
{
SomaNotas += Notas[nt];
}
return SomaNotas / Notas.Count;
}
public List<double> CalcularMedia (List<Notas> Nota)
{
List<double> Nt = new List<double>();
double nota = 0;
for (int nt = 0; nt < Nota.Count; nt++)
{
Notas nts = Nota[nt];
Nt.Add((nts.Nota1 + nts.Nota2 + nts.Nota3) / 3);
}
//Nt.Add(nota);
return Nt;
}
public List<double> CalcularQuadrado (List<double> Numeros)
{
List<double> Potencia = new List<double>();
for (int cont = 0; cont < 10000000000000; cont++)
{
Potencia.Add(Math.Pow(cont,2));
}
return Potencia;
}
private double AreaRetangulo (Retangulo ret)
{
return ret.Altura * ret.Basee;
}
public List<double> CalcRetangulos (List<Retangulo> ret)
{
List<double> NumberRetangulos = new List<double>();
for (int Cont = 0; Cont < ret.Count; Cont++)
{
Retangulo Ret = ret[Cont];
//double calcRet = AreaRetangulo(ret[1]);
NumberRetangulos.Add(AreaRetangulo(Ret));
}
return NumberRetangulos;
}
}
TreinoFocadoA TFA = new TreinoFocadoA();
List<int> Seq = TFA.Contagem(10);
List<int> seq = TFA.GerarSequencia(1,10);
int fim = 10;
int inicio = 0;
List<long> SeqPar = TFA.GerandoSequenciaPar(inicio,fim);
Console.WriteLine(string.Join("-",Seq));
Console.WriteLine(string.Join("-", seq));
Console.WriteLine(string.Join("-", SeqPar));
fim = 100;
Console.WriteLine(TFA.SomarAte(fim));
List<double> Nt = new List<double>();
Nt.Add(7);
Nt.Add(9);
Nt.Add(8);
Nt.Add(8);
Console.WriteLine(TFA.CalcularMedia(Nt));
Notas nota = new Notas();
nota.Nota1 = 1;
nota.Nota2 = 1;
nota.Nota3 = 0;
List<Notas> nt = new List<Notas>();
nt.Add(nota);
List<double> Media = TFA.CalcularMedia(nt);
Console.WriteLine(string.Join("-", Media));
List<double> Numero = new List<double>();
Numero.Add(3);
List<double> Potencia = TFA.CalcularQuadrado(Numero);
Console.WriteLine(string.Join("-", Potencia));
Retangulo ret = new Retangulo();
ret.Altura = 2;
ret.Basee = 2;
//Console.WriteLine(TFA.AreaRetangulo(ret));
List<Retangulo> Retang = new List<Retangulo>();
List<double> CalculandoRetangulo = TFA.CalcRetangulos(Retang);
Console.WriteLine(string.Join("-", CalculandoRetangulo));
```
## Exercício 2
Crie a(s) classe(s) representando a abstração de função e/ou dados ao lado. Abaixo a
especificação das situações a serem resolvidas:
▪ Realize a lógica para implementar uma função que gere uma sequência de datas de um
tamanho informado por parâmetro, iniciando da data atual.
Ex. (2) => { [14/06/2021], [15/06/2021] }
▪ Realize a lógica para implementar uma função que gere uma sequência de datas de um
tamanho informado por parâmetro, iniciando de uma data também informada.
Ex. (2, [14/06/2021]) => { [14/06/2021], [15/06/2021] }
▪ Realize a lógica para implementar uma função que gere uma sequência de datas com
dias pares de um tamanho informado por parâmetro, iniciando de uma data também
informada.
Ex. (2, [14/06/2021]) => { [14/06/2021], [16/06/2021] }
▪ Realize a lógica para implementar uma função que identifique o signo de uma paessoa
baseado em uma data
Ex. ([22/10/1989]) => "Libra", ([23/10/1989]) => "Escorpião“
▪ Realize a lógica para implementar uma função que identifique os signos para cada data
de uma lista.
Ex. ({[22/10/1989], [23/10/1989]}) => { "Libra", "Escorpião“ }
▪ Realize a lógica para implementar uma função que retorne uma lista com as pessoas
maiores de 18 anos a partir de uma lista de pessoas.
▪ Realize a lógica para implementar uma função que retorne se todos de uma lista de
pessoas são maiores de 18 anos.
```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.ToShortDateString()}";
}
}
public class TreinoFocadoB
{
public List<DateTime> GerandoSequencia (int qtd)
{
List<DateTime> QtdDatas = new List<DateTime>();
for (int cont = 0; cont <= qtd; cont++)
{
QtdDatas.Add(DateTime.Today.AddDays(cont));
}
return QtdDatas;
}
public List<DateTime> GerandoSequencia (int qtd, DateTime data)
{
List<DateTime> SeqData = new List<DateTime>();
for( int cont = 0; cont <= qtd; cont++)
{
SeqData.Add(data.AddDays(cont));
}
return SeqData;
}
public List<DateTime> SequenciaPar(int qtd)
{
List<DateTime> SeqDatas = new List<DateTime>();
for(int cont = 0; cont <= qtd; cont++)
{
if (DateTime.Today.AddDays(cont).Day % 2 == 0)
SeqDatas.Add(DateTime.Today.AddDays(cont));
}
return SeqDatas;
}
private string Signo (DateTime Nasc)
{
string signo = string.Empty;
if (Nasc.Day >= 21 && Nasc.Month == 03 || Nasc.Day <= 20 && Nasc.Month == 04)
signo = "Áries";
else if (Nasc.Day >= 21 && Nasc.Month == 04 || Nasc.Day <= 20 && Nasc.Month == 05)
signo = "Touro";
else if (Nasc.Day >= 21 && Nasc.Month == 05 || Nasc.Day <= 20 && Nasc.Month == 06)
signo = "Gêmeos";
else if (Nasc.Day >= 21 && Nasc.Month == 06 || Nasc.Day <= 22 && Nasc.Month == 07)
signo = "Câncer";
else if (Nasc.Day >= 23 && Nasc.Month == 07 || Nasc.Day <= 22 && Nasc.Month == 08)
signo = "Leão";
else if(Nasc.Day >= 23 && Nasc.Month == 08 || Nasc.Day <= 22 && Nasc.Month == 09)
signo = "Virgem";
else if(Nasc.Day >= 23 && Nasc.Month == 09 || Nasc.Day <= 22 && Nasc.Month == 10)
signo = "Libra";
else if (Nasc.Day >= 23 && Nasc.Month == 10 || Nasc.Day <= 21 && Nasc.Month == 11)
signo = "Escorpião";
else if (Nasc.Day >= 22 && Nasc.Month == 11 || Nasc.Day <= 21 && Nasc.Month == 12)
signo = "Sagitário";
else if (Nasc.Day >= 22 && Nasc.Month == 12 || Nasc.Day <= 20 && Nasc.Month == 01)
signo = "Capricórnio";
else if (Nasc.Day >= 21 && Nasc.Month == 01 || Nasc.Day <= 18 && Nasc.Month == 02)
signo = "Aquário";
else
signo = "Peixes";
return signo;
}
public List<string> QualSigno (List<DateTime> Nasc)
{
List<string>signo = new List<string>();
for (int cont = 0; cont < Nasc.Count; cont++)
{
signo.Add(Signo(Nasc[cont]));
}
return signo;
}
public List<Pessoa> FiltrarMaiores (List<Pessoa> P)
{
List<Pessoa> Pessu = new List<Pessoa>();
for (int cont = 0; cont < P.Count; cont++)
{
Pessoa pessu = P[cont];
TimeSpan dif = DateTime.Today - pessu.Nascimento;
if ((dif.TotalDays / 365) >= 18)
Pessu.Add(pessu);
}
return Pessu;
}
public bool Maiores18(List<Pessoa> P)
{
bool Maior18 = true;
for (int cont = 0; cont < P.Count; cont++)
{
Pessoa pessu = P[cont];
if ((DateTime.Today - pessu.Nascimento).TotalDays / 365 <= 18)
Maior18 = false;
}
return Maior18;
}
}
TreinoFocadoB TFB = new TreinoFocadoB();
int[] fim = new int[10];
fim[1] = 2;
List<DateTime> Datas = TFB.GerandoSequencia(fim[1]);
Console.WriteLine(string.Join("|", Datas));
fim[2] = 2;
List<DateTime> Datas2 = TFB.GerandoSequencia(fim[2], DateTime.Today);
Console.WriteLine(string.Join("|", Datas2));
fim[3] = 4;
List<DateTime> DatasPar = TFB.SequenciaPar(fim[3]);
Console.WriteLine(string.Join("|", DatasPar));
fim[4] = 5;
string[] ValoresPraFuncoes = new string[10];
List<DateTime> DataNasc = new List<DateTime>();
DataNasc.Add(DateTime.Today);
List<string> signo = TFB.QualSigno(DataNasc);
Console.WriteLine(string.Join("|", signo));
List<Pessoa> p = new List<Pessoa>() {
new Pessoa() {Nome = "Kus", Nascimento = new DateTime (1890, 03, 14)},
new Pessoa() {Nome = "Kalax", Nascimento = new DateTime(2000, 05, 18)},
new Pessoa() {Nome = "kdks", Nascimento = new DateTime (1989, 06, 27)}
};
List<Pessoa> Pessu = TFB.FiltrarMaiores(p);
Console.WriteLine(string.Join("|", Pessu));
bool DeMaior = TFB.Maiores18(p);
Console.WriteLine(DeMaior);
//Console.WriteLine(TFB.Signo(new DateTime (2008, 12, 25)));
```
## Exercício 3
Crie a(s) classe(s) representando a abstração de função e/ou dados ao lado. Abaixo a
especificação das situações a serem resolvidas:
▪ Realize a lógica para implementar uma função que separe cada caractere de uma frase
por um hífen. Ex. ("Olá, tudo bem?") => "O-l-á- t-u-d-o- -b-e-m-?-“
▪ Realize a lógica para implementar uma função que inverte os caracteres de uma frase.
Ex. ("Olá, tudo bem?") => "?meb odut ,álO“
▪ Realize a lógica para implementar uma função que verifica se todos caracteres de uma
frase são vogais
Ex. ("Olá") => false, ("Eaee") => true
▪ Realize a lógica para implementar uma função que retorne o último nome a partir de um
nome completo. Ex. ("Bruno de Oliveira") => "Oliveira“
▪ Realize a lógica para implementar uma função que retorne os últimos nomes a partir de
uma lista de nomes completos.
Ex. (["Bruno de Oliveira", "João Silva"]) => ["Oliveira", "Silva"]
▪ Realize a lógica para implementar uma função que verifique se todas as cores em uma
lista são primárias. Ex. (["Azul", "Amarelo", "Vermelho"]) => true
▪ Realize a lógica para implementar uma função que verifique se uma senha é forte. Para
ser forte, ela precisa ter pelo menos 2 caracteres especiais, 2 números e 8 digitos.
Ex. ("senha@123") => false, ("s&nha@87") => true, ("aaaa@@00") => true
```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 FraseComTracinho (string frase)
{
string resul = string.Empty;
for (int cont = 0; cont < frase.Length; cont++)
{
char corte = frase[cont];
resul += corte + "-";
}
return resul;
}
public string InvertendoFrase (string frase)
{
string resul = string.Empty;
for (int cont = 0; cont < frase.Length; cont++)
{
char corte = frase[cont];
resul = corte + resul;
}
return resul;
}
public string TodasVogais (string frase)
{
string resul = string.Empty;
bool FullVogal = false;
for (int cont = 0; cont < frase.Length; cont++)
{
char corte = frase[cont];
if (corte == 'a' || corte == 'A' || corte == 'e' || corte == 'E' || corte == 'i' || corte == 'I' || corte == 'o' || corte == 'O' || corte == 'u' || corte == 'U')
FullVogal = true;
else
{
FullVogal = false;
break;
}
}
return FullVogal.ToString();
}
private string UltimoNome (string Nome)
{
return Nome.Substring(Nome.LastIndexOf(" ") + 1);
}
public List<string> LastNames (List<string> Nome)
{
List<string> Nm = new List<string>();
for (int cont = 0; cont < Nome.Count; cont++)
{
Nm.Add(UltimoNome(Nome[cont]));
}
return Nm;
}
public bool CoresPrimarias (List<string> Cores)
{
bool CoresPrimaria = false;
for (int cont = 0; cont < Cores.Count; cont++)
{
if ( Cores[cont] == "Azul" || Cores[cont] == "Amarelo" || Cores[cont] == "Vermelho")
CoresPrimaria = true;
else
{
CoresPrimaria = false;
break;
}
}
return CoresPrimaria;
}
public bool SenhaForte (string senha)
{
bool SenhaFullPower = false;
//for (int cont = 0; cont < senha.Length; cont++)
//char corte = senha[cont];
int number = 0;
int CaracEspecial = 0;
string Numeros = "0123456789";
string CarcEspecial = "&_@#/\\*()?!:";
for (int cont = 0; cont < senha.Length; cont++)
{
for (int x = 0; x < Numeros.Length; x++)
{
if (senha[cont] == Numeros[x])
number += 1;
}
for (int y = 0; y < CarcEspecial.Length; y++)
{
if(senha[cont] == CarcEspecial[y])
CaracEspecial += 1;
}
}
if(senha.Length == 8 && number == 2 && CaracEspecial == 2)
SenhaFullPower = true;
return SenhaFullPower;
}
}
TreinoFocadoC TFC = new TreinoFocadoC();
string[] ValoresPraFuncoes = new string[10];
ValoresPraFuncoes[0] = "Oi tudo bem?";
string Frase = TFC.FraseComTracinho(ValoresPraFuncoes[0]);
Console.WriteLine(Frase);
//string FraseInversa= TFC.InvertendoFrase(ValoresPraFuncoes[0]);
//Console.WriteLine(FraseInversa)/Console.WriteLine(FraseInversa);
ValoresPraFuncoes[1] = "Ota";
string Vogais = TFC.TodasVogais(ValoresPraFuncoes[1]);
Console.WriteLine(Vogais);
List<string> Nomes = new List<string>() {
{"oliver queen"},
{"Carl kis"}
};
List<string> LastName = TFC.LastNames(Nomes);
Console.WriteLine(string.Join("|", LastName));
List<string> Cores = new List<string>() {
{"Azul"},
{"Amarelo"},
{"Preto"}
};
bool CorPrimaria = TFC.CoresPrimarias(Cores);
Console.WriteLine(CorPrimaria);
```