gmansano

Atividade 2 - Exercício 1 [Agenda.cs]

Aug 26th, 2020
1,349
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.67 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Atividade
  4. {
  5.     public class Agenda
  6.     {
  7.         string[] nome = new string[10];
  8.         int[] idade = new int[10];
  9.         float[] altura = new float[10];
  10.  
  11.         public Agenda()
  12.         {
  13.  
  14.         }
  15.  
  16.         public void armazenarPessoa(string nome, int idade, int index, float altura)
  17.         {
  18.             for (; index < this.nome.Length; index++)
  19.             {
  20.                 this.nome[index] = nome;
  21.                 this.idade[index] = idade;
  22.                 this.altura[index] = altura;
  23.             }
  24.         }
  25.         public void removerPessoa(string nome)
  26.         {
  27.             Console.Clear();
  28.             bool flag = false;
  29.             for (int index = 0; index < this.nome.Length; index++)
  30.             {
  31.                 if (this.nome[index].Contains(nome))
  32.                 {
  33.                     flag = true;
  34.                     this.nome[index] = null;
  35.                     this.idade[index] = 0;
  36.                     this.altura[index] = 0;
  37.                 }
  38.             }
  39.             if (flag == true)
  40.             {
  41.                 System.Console.WriteLine("A pessoa {0} foi deletada do sistema com sucesso.", nome);
  42.             }
  43.             else
  44.             {
  45.                 System.Console.WriteLine("Não foi possível deletar a pessoa {0}, ela não existe ou seu nome foi digitado incorretamente.", nome);
  46.             }
  47.         }
  48.         public int buscaPessoa(string nome)
  49.         {
  50.             int i = 0;
  51.             for (int index = 0; index < this.nome.Length; index++)
  52.             {
  53.                 if (this.nome[index].Contains(nome))
  54.                 {
  55.                     i = index;
  56.                 }
  57.             }
  58.             return i;
  59.         }
  60.         public void imprimeAgenda()
  61.         {
  62.             for (int index = 0; index < nome.Length; index++)
  63.             {
  64.                 System.Console.WriteLine("| Nome: {0} | Idade: {1} anos | Altura: {2} m |", this.nome[index], this.idade[index], this.altura[index]);
  65.             }
  66.         }
  67.         public void imprimePessoa(int index)
  68.         {
  69.             bool flag = false;
  70.             for (int i = 0; i < this.nome.Length; i++)
  71.             {
  72.                 if (i == index)
  73.                 {
  74.                     flag = true;
  75.                     System.Console.WriteLine("| Nome: {0} | Idade: {1} anos | Altura: {2} m |", this.nome[i], this.idade[i], this.altura[i]);
  76.                     break;
  77.                 }
  78.             }
  79.             if (flag == false)
  80.             {
  81.                 Console.WriteLine("O índice {0} é inválido na instância atual.", index);
  82.             }
  83.         }
  84.         ~Agenda()
  85.         {
  86.  
  87.         }
  88.     }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment