Controllo voce preesistente
This commit is contained in:
parent
adcd853d06
commit
371104953b
38
Program.cs
38
Program.cs
@ -6,6 +6,7 @@ class Program {
|
||||
Console.Clear();
|
||||
int scelta = 0;
|
||||
Voce[] rubrica = new Voce[100]; //tetto massimo di voci possibili nella rubrica
|
||||
int indice = 0;
|
||||
|
||||
do {
|
||||
Console.WriteLine("Inserire un'opzione:");
|
||||
@ -23,7 +24,7 @@ class Program {
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
CreaVoce(rubrica);
|
||||
CreaVoce(rubrica, indice++);
|
||||
Pausa();
|
||||
break;
|
||||
case 2:
|
||||
@ -55,10 +56,9 @@ class Program {
|
||||
Console.ReadKey();
|
||||
}
|
||||
|
||||
static void CreaVoce(Voce[] p_rubrica) {
|
||||
static void CreaVoce(Voce[] p_rubrica, int p_indice) {
|
||||
bool error;
|
||||
string scelta;
|
||||
int indiceVoce = TrovaProssimaPosizioneDisponibile(p_rubrica);
|
||||
string nome;
|
||||
string cognome;
|
||||
string telefono;
|
||||
@ -71,6 +71,7 @@ class Program {
|
||||
const string EMAIL = "^[\\w.-]+@([\\w-]+\\.)+[\\w-]{2,4}$";
|
||||
const string CONFERMA = "[SsYy]";
|
||||
const string NEGAZIONE = "[Nn]";
|
||||
string[] voce;
|
||||
|
||||
do {
|
||||
Console.Write("Inserire il nome della persona: ");
|
||||
@ -209,25 +210,19 @@ class Program {
|
||||
}
|
||||
while (error);
|
||||
|
||||
if (indiceVoce == -1) {
|
||||
if (p_indice == p_rubrica.Length) {
|
||||
Console.WriteLine("Errore: la rubrica è piena.");
|
||||
}
|
||||
else {
|
||||
p_rubrica[indiceVoce] = new Voce(nome, cognome, telefono, cellulare, email, indirizzo);
|
||||
voce = [nome, cognome, telefono, cellulare, email, indirizzo];
|
||||
if (!DoesVoceExist(p_rubrica, voce)) {
|
||||
p_rubrica[p_indice] = new Voce(nome, cognome, telefono, cellulare, email, indirizzo);
|
||||
Console.WriteLine("Voce creata con successo.");
|
||||
}
|
||||
}
|
||||
|
||||
static int TrovaProssimaPosizioneDisponibile(Voce[] p_rubrica) {
|
||||
bool exit = false;
|
||||
int i;
|
||||
for (i = 0; i < p_rubrica.Length && exit; i++) {
|
||||
if (p_rubrica[i] == null) {
|
||||
exit = true;
|
||||
else {
|
||||
Console.WriteLine("Errore: la voce esiste già.");
|
||||
}
|
||||
}
|
||||
|
||||
return !exit ? i : -1;
|
||||
}
|
||||
|
||||
static void MostraRubrica(Voce[] p_rubrica) {
|
||||
@ -241,4 +236,17 @@ class Program {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static bool DoesVoceExist(Voce[] p_rubrica, string[] p_voce) {
|
||||
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]) {
|
||||
esiste = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return esiste;
|
||||
}
|
||||
}
|
||||
|
||||
4
Voce.cs
4
Voce.cs
@ -25,4 +25,8 @@ class Voce {
|
||||
Console.WriteLine($"\tEmail: {this.email}");
|
||||
Console.WriteLine($"\tIndirizzo: {this.indirizzo}");
|
||||
}
|
||||
|
||||
public string[] GetVoceAsArray() {
|
||||
return [this.nome, this.cognome, this.telefono, this.cellulare, this.email, this.indirizzo];
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -13,10 +13,10 @@ 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+394c4e4012c619345c24a8351853ea1ad8a0dc6b")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+adcd853d065d0f5ee33305ce879ad3ab6c752998")]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute("vacanzeEstive_rubricaTelefonica")]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("vacanzeEstive_rubricaTelefonica")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
||||
// Generated by the MSBuild WriteCodeFragment class.
|
||||
// Generato dalla classe WriteCodeFragment di MSBuild.
|
||||
|
||||
|
||||
@ -1 +1 @@
|
||||
fb0d1ec8b0274d7315e8b09e330ec685e30dd469f5d8fc537973ed9c1d3cad12
|
||||
81cb16105158fc67677a8f34f6d4634cc420d130cc85cba0f787d235cb911b77
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user