TrabalhosGratuitos.com - Trabalhos, Monografias, Artigos, Exames, Resumos de livros, Dissertações
Pesquisar

Implementação de algorítmo imperativo(.net) tentando imitar um lógico(prolog)

Por:   •  3/3/2017  •  Trabalho acadêmico  •  4.988 Palavras (20 Páginas)  •  203 Visualizações

Página 1 de 20

using System;

using System.Collections.Generic;

using System.Linq;

using System.Windows.Forms;

namespace Estudos.Paradigmas.WFA

{

internal static class Program

{

private static List<Pessoa> listaPessoas = new List<Pessoa>();

private static List<Homem> listaHomens = new List<Homem>();

private static List<Mulher> listaMulheres = new List<Mulher>();

private static Dictionary<Homem, List<Mulher>> mapHetero = new Dictionary<Homem, List<Mulher>>();

private static Dictionary<Pessoa, List<Pessoa>> mapHomoHomem = new Dictionary<Pessoa, List<Pessoa>>();

private static Dictionary<Pessoa, List<Pessoa>> mapHomoMulher = new Dictionary<Pessoa, List<Pessoa>>();

[STAThread]

private static void Main()

{

//Dictionary<Homem, Mulher> mapHeteroH = new Dictionary<Homem, Mulher>();

//Dictionary<Mulher, Homem> mapHeteroM = new Dictionary<Mulher, Homem>();

Pessoa joao = new Homem { Nome = "joao", Idade = 20, Sexo = "Masculino" };

Pessoa felipe = new Homem { Nome = "felipe", Idade = 32, Sexo = "Masculino" };

Pessoa pedro = new Homem { Nome = "pedro", Idade = 18, Sexo = "Masculino" };

Pessoa fredy = new Homem { Nome = "fredy", Idade = 38, Sexo = "Masculino" };

Pessoa maria = new Mulher { Nome = "maria", Idade = 19, Sexo = "Feminino" };

Pessoa luciana = new Mulher { Nome = "luciana", Idade = 27, Sexo = "Feminino" };

Pessoa kelly = new Mulher { Nome = "kelly", Idade = 57, Sexo = "Feminino" };

Pessoa fernanda = new Mulher { Nome = "fernanda", Idade = 25, Sexo = "Feminino" };

listaPessoas.Add(joao); listaPessoas.Add(felipe); listaPessoas.Add(pedro); listaPessoas.Add(fredy);

listaPessoas.Add(maria); listaPessoas.Add(luciana); listaPessoas.Add(kelly); listaPessoas.Add(fernanda);

AddPes(listaPessoas);

mapHetero.Add((Homem)joao, listaMulheres);

mapHetero.Add((Homem)felipe, listaMulheres);

mapHetero.Add((Homem)pedro, listaMulheres);

mapHetero.Add((Homem)fredy, listaMulheres);

mapHomoHomem.Add(joao, listaHomens.Cast<Pessoa>().ToList()); mapHomoHomem.Add(felipe, listaHomens.Cast<Pessoa>().ToList());

mapHomoHomem.Add(pedro, listaHomens.Cast<Pessoa>().ToList()); mapHomoHomem.Add(fredy, listaHomens.Cast<Pessoa>().ToList());

mapHomoMulher.Add(maria, listaMulheres.Cast<Pessoa>().ToList()); mapHomoMulher.Add(luciana, listaMulheres.Cast<Pessoa>().ToList());

mapHomoMulher.Add(kelly, listaMulheres.Cast<Pessoa>().ToList()); mapHomoMulher.Add(fernanda, listaMulheres.Cast<Pessoa>().ToList());

var result = Casal("Homo", joao, maria);

MessageBox.Show(result == true ? "true" : "false");

var textoHeteroIdade = Combinacoes("Hetero", 20);

MessageBox.Show(textoHeteroIdade);

var textoHomoIdade = Combinacoes("Homo", 20);

MessageBox.Show(textoHomoIdade);

var textoHomo = Combinacoes("Homo");

MessageBox.Show(textoHomo);

var textoHetero = Combinacoes("Hetero");

MessageBox.Show(textoHetero);

var comb = Combinacoes("Homo", maria);

MessageBox.Show(comb);

}

private static void AddPes(List<Pessoa> lista)

{

foreach (var pessoa in lista)

{

if (pessoa.GetType() == typeof(Homem))

{

listaHomens.Add((Homem)pessoa);

}

if (pessoa.GetType() == typeof(Mulher))

{

listaMulheres.Add((Mulher)pessoa);

}

}

}

private static bool Casal(string type, Pessoa pes1, Pessoa pes2)

{

if (pes1.Equals(pes2))

{

return false;

...

Baixar como (para membros premium)  txt (10.7 Kb)   pdf (51.8 Kb)   docx (15.1 Kb)  
Continuar por mais 19 páginas »
Disponível apenas no TrabalhosGratuitos.com