diff --git a/Program.cs b/Program.cs index 24f054f..c8c52fd 100644 --- a/Program.cs +++ b/Program.cs @@ -28,13 +28,30 @@ class Program { Pausa(); break; case 2: + if (rubrica[0] == null) { + Console.WriteLine("Errore: rubrica vuota."); + } + else { + RicercaEsatta(rubrica); + } Pausa(); break; case 3: + if (rubrica[0] == null) { + Console.WriteLine("Errore: rubrica vuota."); + } + else { + Ricerca(rubrica); + } Pausa(); break; case 4: - MostraRubrica(rubrica); + if (rubrica[0] == null) { + Console.WriteLine("Errore: rubrica vuota."); + } + else { + MostraRubrica(rubrica); + } Pausa(); break; default: @@ -69,8 +86,8 @@ class Program { const int LUNGHEZZA_TELEFONO = 20; const string TELEFONO = "^(?:\\(?\\+?\\d{1,3}\\)?|\\(?00\\d{1,3}\\)?)?[\\s-]?\\d{3}[\\s-]\\d{3}[\\s-]\\d{4}$"; const string EMAIL = "^[\\w.-]+@([\\w-]+\\.)+[\\w-]{2,4}$"; - const string CONFERMA = "[SsYy]"; - const string NEGAZIONE = "[Nn]"; + const string CONFERMA = "[SsYy]{1}"; + const string NEGAZIONE = "[Nn]{1}"; string[] voce; do { @@ -226,14 +243,9 @@ class Program { } static void MostraRubrica(Voce[] p_rubrica) { - if (p_rubrica[0] == null) { - Console.WriteLine("Errore: rubrica vuota."); - } - else { - for (int i = 0; i < p_rubrica.Length && p_rubrica[i] != null; i++) { - Console.WriteLine($"Voce n. {i + 1}:"); - p_rubrica[i].MostraVoce(); - } + for (int i = 0; i < p_rubrica.Length && p_rubrica[i] != null; i++) { + Console.WriteLine($"Voce n. {i + 1}:"); + p_rubrica[i].MostraVoce(); } } @@ -241,7 +253,7 @@ class Program { bool esiste = false; for (int i = 0; i < p_rubrica.Length && p_rubrica[i] != null && !esiste; i++) { for (int j = 2; j < p_voce.Length && !esiste; j++) { - if (p_voce[j] == p_rubrica[i].GetVoceAsArray()[j]) { + if (p_voce[j] == p_rubrica[i].GetVoceAsArray()[j] && p_voce[j] != "") { esiste = true; } } @@ -249,4 +261,44 @@ class Program { return esiste; } + + static void RicercaEsatta(Voce[] p_rubrica) { + string ricerca; + do { + Console.Write("Inserire il nome da cercare: "); + ricerca = Console.ReadLine(); + if (string.IsNullOrEmpty(ricerca)) { + Console.WriteLine("Errore: nome vuoto."); + Pausa(); + } + } + while (string.IsNullOrEmpty(ricerca)); + + for (int i = 0; i < p_rubrica.Length && p_rubrica[i] != null; i++) { + if (p_rubrica[i].GetNome() == ricerca) { + Console.WriteLine("Corrispondenza trovata:"); + p_rubrica[i].MostraVoce(); + } + } + } + + static void Ricerca(Voce[] p_rubrica) { + string ricerca; + do { + Console.Write("Inserire il termine da cercare: "); + ricerca = Console.ReadLine(); + if (string.IsNullOrEmpty(ricerca)) { + Console.WriteLine("Errore: nome vuoto."); + Pausa(); + } + } + while (string.IsNullOrEmpty(ricerca)); + + for (int i = 0; i < p_rubrica.Length && p_rubrica[i] != null; i++) { + if (p_rubrica[i].GetNome().Contains(ricerca)) { + Console.WriteLine("Corrispondenza trovata:"); + p_rubrica[i].MostraVoce(); + } + } + } } diff --git a/Voce.cs b/Voce.cs index 5ef7439..19f5c5b 100644 --- a/Voce.cs +++ b/Voce.cs @@ -29,4 +29,8 @@ class Voce { public string[] GetVoceAsArray() { return [this.nome, this.cognome, this.telefono, this.cellulare, this.email, this.indirizzo]; } + + public string GetNome() { + return this.nome; + } } \ No newline at end of file diff --git a/bin/Debug/net9.0/vacanzeEstive_rubricaTelefonica.dll b/bin/Debug/net9.0/vacanzeEstive_rubricaTelefonica.dll index a643575..509b6fe 100644 Binary files a/bin/Debug/net9.0/vacanzeEstive_rubricaTelefonica.dll and b/bin/Debug/net9.0/vacanzeEstive_rubricaTelefonica.dll differ diff --git a/bin/Debug/net9.0/vacanzeEstive_rubricaTelefonica.pdb b/bin/Debug/net9.0/vacanzeEstive_rubricaTelefonica.pdb index 0cd42f6..dbf5272 100644 Binary files a/bin/Debug/net9.0/vacanzeEstive_rubricaTelefonica.pdb and b/bin/Debug/net9.0/vacanzeEstive_rubricaTelefonica.pdb differ diff --git a/obj/Debug/net9.0/ref/vacanzeEstive_rubricaTelefonica.dll b/obj/Debug/net9.0/ref/vacanzeEstive_rubricaTelefonica.dll index fdad86e..6544783 100644 Binary files a/obj/Debug/net9.0/ref/vacanzeEstive_rubricaTelefonica.dll and b/obj/Debug/net9.0/ref/vacanzeEstive_rubricaTelefonica.dll differ diff --git a/obj/Debug/net9.0/refint/vacanzeEstive_rubricaTelefonica.dll b/obj/Debug/net9.0/refint/vacanzeEstive_rubricaTelefonica.dll index fdad86e..6544783 100644 Binary files a/obj/Debug/net9.0/refint/vacanzeEstive_rubricaTelefonica.dll and b/obj/Debug/net9.0/refint/vacanzeEstive_rubricaTelefonica.dll differ diff --git a/obj/Debug/net9.0/vacanzeEstive_rubricaTelefonica.AssemblyInfo.cs b/obj/Debug/net9.0/vacanzeEstive_rubricaTelefonica.AssemblyInfo.cs index 7d9b09b..2e001f7 100644 --- a/obj/Debug/net9.0/vacanzeEstive_rubricaTelefonica.AssemblyInfo.cs +++ b/obj/Debug/net9.0/vacanzeEstive_rubricaTelefonica.AssemblyInfo.cs @@ -13,7 +13,7 @@ using System.Reflection; [assembly: System.Reflection.AssemblyCompanyAttribute("vacanzeEstive_rubricaTelefonica")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] -[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+adcd853d065d0f5ee33305ce879ad3ab6c752998")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+371104953b7b7c89cc3ce105bb42a1abd2a722cf")] [assembly: System.Reflection.AssemblyProductAttribute("vacanzeEstive_rubricaTelefonica")] [assembly: System.Reflection.AssemblyTitleAttribute("vacanzeEstive_rubricaTelefonica")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] diff --git a/obj/Debug/net9.0/vacanzeEstive_rubricaTelefonica.AssemblyInfoInputs.cache b/obj/Debug/net9.0/vacanzeEstive_rubricaTelefonica.AssemblyInfoInputs.cache index 7acb339..0169bae 100644 --- a/obj/Debug/net9.0/vacanzeEstive_rubricaTelefonica.AssemblyInfoInputs.cache +++ b/obj/Debug/net9.0/vacanzeEstive_rubricaTelefonica.AssemblyInfoInputs.cache @@ -1 +1 @@ -81cb16105158fc67677a8f34f6d4634cc420d130cc85cba0f787d235cb911b77 +a78438f378acb1585c80b4cdf5f2a5fa8a6c9e2fb3f6656cf473d5dafa412453 diff --git a/obj/Debug/net9.0/vacanzeEstive_rubricaTelefonica.dll b/obj/Debug/net9.0/vacanzeEstive_rubricaTelefonica.dll index a643575..509b6fe 100644 Binary files a/obj/Debug/net9.0/vacanzeEstive_rubricaTelefonica.dll and b/obj/Debug/net9.0/vacanzeEstive_rubricaTelefonica.dll differ diff --git a/obj/Debug/net9.0/vacanzeEstive_rubricaTelefonica.pdb b/obj/Debug/net9.0/vacanzeEstive_rubricaTelefonica.pdb index 0cd42f6..dbf5272 100644 Binary files a/obj/Debug/net9.0/vacanzeEstive_rubricaTelefonica.pdb and b/obj/Debug/net9.0/vacanzeEstive_rubricaTelefonica.pdb differ