NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

class Program
{
private const int qtdeContatos = 10;
private static string[] email = new string[qtdeContatos];
private static string[] nome = new string[qtdeContatos];
private static string[] telefone = new string[qtdeContatos];
private static string[] sexo = new string[qtdeContatos];
private static DateTime[] dtnasc = new DateTime[qtdeContatos];
private static bool[] familia = new bool[qtdeContatos];

static void Main(string[] args)
{
int opcaoMenu = 1;

do
{
try
{
Console.Write("n0. Finalizarn");
Console.Write("1. Cadastrar contaton");
Console.Write("2. Consultar contaton");
Console.Write("3. Excluir contaton");
Console.Write("4. Listar contatosn");
Console.Write("Sua opção: ");
opcaoMenu = int.Parse(Console.ReadLine());

switch (opcaoMenu)
{
case 1: cadastrar(); break;
case 2: consultar(); break;
case 3: excluir(); break;
case 4: listar(); break;
case 0: Console.Write("nMuito Obrigado!"); break;
default: Console.Write("nValor errado, digite um valor correspondente!n"); break;
}
}
catch (Exception e)
{
Console.WriteLine($"n{e}n");
Console.WriteLine("Erro - Digite apenas caracteres numéricos de 0 a 4. n");
}
} while(opcaoMenu != 0);
Console.ReadKey();
}
private static DateTime converteData(string dataNascimento)
{
DateTime dt;
try
{
return DateTime.Parse(dataNascimento);
}
catch(FormatException)
{
return dt = new DateTime();
}
}

private static void cadastrar()
{
try
{
int codigo;
string auxBool;
DateTime dtnascAux;
do
{
Console.Write("nInforme o código do contato: ");
codigo = int.Parse(Console.ReadLine());

if(codigo < 1 || codigo > 10)
{
Console.Write("nErro - utilize apenas valores de 1 a 10");
}
} while (codigo < 1 || codigo > 10);
codigo--;

Console.Write("nInforme o e-mail do contato: ");
email[codigo] = Console.ReadLine();
Console.Write("nInforme o nome do contato: ");
nome[codigo] = Console.ReadLine();
Console.Write("nInform o telefone do contato: ");
telefone[codigo] = Console.ReadLine();
do
{
Console.Write("nInforme o sexo do contato: ");
sexo[codigo] = Console.ReadLine();

if ((sexo[codigo] != "M" && sexo[codigo] != "m") && (sexo[codigo] != "F" && sexo[codigo] != "f"))
{
Console.Write("nErro - Entre apenas com M ou F");
}

} while ((sexo[codigo] != "M" && sexo[codigo] != "m") && (sexo[codigo] != "F" && sexo[codigo] != "f"));

do
{
dtnasc[codigo] = new DateTime();
dtnascAux = dtnasc[codigo];
Console.Write("nInforme a data de nascimento do contato: ");
dtnasc[codigo] = converteData(Console.ReadLine());
if (dtnasc[codigo] == dtnascAux)
{
Console.WriteLine("Informe uma data com a formatação correta <dd/mm/aaaa>");
}
} while (dtnasc[codigo] == dtnascAux);
do
{
Console.Write("nContato familiar (S/N): ");
auxBool = Console.ReadLine();

if((auxBool != "S" && auxBool != "s") && (auxBool != "N" && auxBool != "n"))
{
Console.Write("nErro - Entre apenas com S ou N");
}
} while ((auxBool != "S" && auxBool != "s") && (auxBool != "N" && auxBool != "n"));
if (auxBool == "S" || auxBool == "s")
{
familia[codigo] = true;
}
else if (auxBool == "N" || auxBool == "n")
{
familia[codigo] = false;
}

Console.Write("nContato cadastrado com sucesso");
}
catch(Exception e)
{
Console.Write($"n{e}n");
}
}

private static void consultar()
{
int retorno = 0;
string valor;
valor = criterioPesquisa();

if(valor == "c" || valor == "C")
{
mostrarDados(pesquisarPorCodigo());
}

else if (valor == "e" || valor == "E")
{
retorno = pesquisarPorEmail();
if (retorno >= 0 && retorno <= 9)
{
mostrarDados(retorno);
}
else
{
Console.Write("Erro - Nenhum email semelhante encontrado");
}

}
}

private static int pesquisarPorCodigo()
{
int numeroContato = 0;
try
{
do
{
Console.Write("Informe o código do contato: ");
numeroContato = int.Parse(Console.ReadLine()) - 1;
if (numeroContato < 0 || numeroContato > 9)
Console.Write("nErro - O número de contato deve consistir entre 1 e 10n");
} while (numeroContato < 0 || numeroContato > 9);
}
catch(Exception e)
{
Console.Write($"n{e}n");
}
return numeroContato;
}

private static string criterioPesquisa()
{
string opcao;
do
{
Console.Write("n--> Pesquisar por (C)ódigo ou (e)-mail ?n");
opcao = Console.ReadLine();
if ((opcao != "c" && opcao != "C") && (opcao != "e" && opcao != "E"))
{
Console.Write("nDigite apenas "c" ou "e"");
}
} while ((opcao != "c" && opcao != "C") && (opcao != "e" && opcao != "E"));
return opcao;

}
private static int pesquisarPorEmail()
{
string emailContato;
Console.Write("Informe o e-mail do contato: ");
emailContato = Console.ReadLine();

for (int ct = 0; ct < qtdeContatos; ct++)
{
if (emailContato == email[ct])
{
return ct;
}
}
return -1;
}

private static void excluirDados(int numeroContato)
{
email[numeroContato] = "";
nome[numeroContato] = "";
telefone[numeroContato] = "";
sexo[numeroContato] = "";
dtnasc[numeroContato] = new DateTime();
familia[numeroContato] = false;

Console.Write("Contato foi excluído");
}

private static void excluir()
{
string valor;
int retorno = 0;
valor = criterioPesquisa();

if (valor == "c" || valor == "C")
{
excluirDados(pesquisarPorCodigo());
}

else if (valor == "e" || valor == "E")
{
retorno = pesquisarPorEmail();
if (retorno >= 0 && retorno <= 9)
{
excluirDados(retorno);
}
else
{
Console.Write("Erro - Nenhum email semelhante encontrado");
}

}

}
private static void listar()
{
for (int numeroContato = 0; numeroContato < qtdeContatos; numeroContato++ )
{
Console.Write("nCódigo : " + (numeroContato + 1) + "n");
Console.Write("nE-mail : " + email[numeroContato] + "n");
Console.Write("nNome : " + nome[numeroContato] + "n");
Console.Write("nTelefone : " + telefone[numeroContato] + "n");
Console.Write("nSexo : " + sexo[numeroContato] + "n");
Console.Write("nDt de Nasc : " + string.Format("{0:dd/MM/yyyy}", dtnasc[numeroContato]) + "n");
if (familia[numeroContato] == true)
{
Console.Write("nFamilia: Sn");
}
else
{
Console.Write("nFamilia: Nn");
}
Console.Write("------------------------------");
}
}

private static void mostrarDados(int numeroContato)
{
Console.Write("nCódigo : " + (numeroContato + 1) + "n");
Console.Write("nE-mail : " + email[numeroContato] + "n");
Console.Write("nNome : " + nome[numeroContato] + "n");
Console.Write("nTelefone : " + telefone[numeroContato] + "n");
Console.Write("nSexo : " + sexo[numeroContato] + "n");
Console.Write("nDt de Nasc : " + string.Format("{0:dd/MM/yyyy}", dtnasc[numeroContato]) + "n");
if (familia[numeroContato])
{
Console.Write("nFamilia: Sn");
}
else if(!familia[numeroContato])
{
Console.Write("nFamilia: Nn");
}

}



}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.