Aggiunta funzione di controllo
This commit is contained in:
parent
48c2ab537d
commit
149b3fbbcf
50
Program.cs
50
Program.cs
@ -7,7 +7,7 @@ class Program {
|
|||||||
const int DIMENSIONE_RUBRICA = 100;
|
const int DIMENSIONE_RUBRICA = 100;
|
||||||
int scelta = 0;
|
int scelta = 0;
|
||||||
string nome = "";
|
string nome = "";
|
||||||
string numeroditelefono, tipologia;
|
string numeroditelefono;
|
||||||
bool check = false;
|
bool check = false;
|
||||||
bool check2 = false;
|
bool check2 = false;
|
||||||
bool check3 = false;
|
bool check3 = false;
|
||||||
@ -18,7 +18,7 @@ class Program {
|
|||||||
string[] nomi = new string[DIMENSIONE_RUBRICA];
|
string[] nomi = new string[DIMENSIONE_RUBRICA];
|
||||||
string[] numeriditelefono = new string[DIMENSIONE_RUBRICA];
|
string[] numeriditelefono = new string[DIMENSIONE_RUBRICA];
|
||||||
Voce singolavoce = null;
|
Voce singolavoce = null;
|
||||||
Voce[] vocidellarubrica = new Voce[DIMENSIONE_RUBRICA];
|
Voce[] voci = new Voce[DIMENSIONE_RUBRICA];
|
||||||
Rubrica rubrica = null;
|
Rubrica rubrica = null;
|
||||||
do {
|
do {
|
||||||
Console.WriteLine("1)Aggiungi nuova voce in rubrica");
|
Console.WriteLine("1)Aggiungi nuova voce in rubrica");
|
||||||
@ -38,13 +38,14 @@ class Program {
|
|||||||
Console.WriteLine("Inserisci il nome della voce che andrà nella rubrica telefonica");
|
Console.WriteLine("Inserisci il nome della voce che andrà nella rubrica telefonica");
|
||||||
nome = Console.ReadLine().ToLower();
|
nome = Console.ReadLine().ToLower();
|
||||||
nomi[contatore] = nome;
|
nomi[contatore] = nome;
|
||||||
tipologia = "nome";
|
|
||||||
check2 = VerificaCorrettezza(nome, true);
|
|
||||||
check3 = VerificaDoppione(nome, nomi, contatore);
|
check3 = VerificaDoppione(nome, nomi, contatore);
|
||||||
|
if (contatore == 0) {
|
||||||
|
|
||||||
|
}
|
||||||
if (nome.Length > 40) {
|
if (nome.Length > 40) {
|
||||||
Console.WriteLine("il nome non può essere lungo più di 40 caratteri");
|
Console.WriteLine("il nome non può essere lungo più di 40 caratteri");
|
||||||
}
|
}
|
||||||
if (check2 == true) {
|
if (VerificaCorrettezza(nome, true)) {
|
||||||
Console.WriteLine("il nome non può contenere dei numeri");
|
Console.WriteLine("il nome non può contenere dei numeri");
|
||||||
}
|
}
|
||||||
if (check3 == true) {
|
if (check3 == true) {
|
||||||
@ -58,7 +59,6 @@ class Program {
|
|||||||
numeroditelefono = Console.ReadLine();
|
numeroditelefono = Console.ReadLine();
|
||||||
numeroditelefono = numeroditelefono.ToLower();
|
numeroditelefono = numeroditelefono.ToLower();
|
||||||
numeriditelefono[contatore] = numeroditelefono;
|
numeriditelefono[contatore] = numeroditelefono;
|
||||||
tipologia = "numero di telefono";
|
|
||||||
check2 = VerificaCorrettezza(numeroditelefono, false);
|
check2 = VerificaCorrettezza(numeroditelefono, false);
|
||||||
check3 = VerificaDoppione(numeroditelefono, numeriditelefono, contatore);
|
check3 = VerificaDoppione(numeroditelefono, numeriditelefono, contatore);
|
||||||
if (numeroditelefono.Length > 20) {
|
if (numeroditelefono.Length > 20) {
|
||||||
@ -73,8 +73,8 @@ class Program {
|
|||||||
}
|
}
|
||||||
while (numeroditelefono.Length > 20 || check2 == true || check3 == true);
|
while (numeroditelefono.Length > 20 || check2 == true || check3 == true);
|
||||||
singolavoce = new Voce(nome, numeroditelefono);
|
singolavoce = new Voce(nome, numeroditelefono);
|
||||||
vocidellarubrica[contatore] = singolavoce;
|
voci[contatore] = singolavoce;
|
||||||
rubrica = new Rubrica(vocidellarubrica);
|
rubrica = new Rubrica(voci);
|
||||||
contatore++;
|
contatore++;
|
||||||
check = true;
|
check = true;
|
||||||
}
|
}
|
||||||
@ -89,7 +89,6 @@ class Program {
|
|||||||
Console.WriteLine("Inserisci il nome esatto che stai cercando");
|
Console.WriteLine("Inserisci il nome esatto che stai cercando");
|
||||||
nomeesatto = Console.ReadLine();
|
nomeesatto = Console.ReadLine();
|
||||||
nomeesatto = nomeesatto.ToLower();
|
nomeesatto = nomeesatto.ToLower();
|
||||||
tipologia = "nome";
|
|
||||||
check2 = VerificaCorrettezza(nome, true);
|
check2 = VerificaCorrettezza(nome, true);
|
||||||
if (nomeesatto.Length > 40) {
|
if (nomeesatto.Length > 40) {
|
||||||
Console.WriteLine("il nome non può essere lungo più di 40 caratteri");
|
Console.WriteLine("il nome non può essere lungo più di 40 caratteri");
|
||||||
@ -113,7 +112,6 @@ class Program {
|
|||||||
Console.WriteLine("Inserisci il nome approsimato che stai cercando");
|
Console.WriteLine("Inserisci il nome approsimato che stai cercando");
|
||||||
nomeapprossimato = Console.ReadLine();
|
nomeapprossimato = Console.ReadLine();
|
||||||
nomeapprossimato = nomeapprossimato.ToLower();
|
nomeapprossimato = nomeapprossimato.ToLower();
|
||||||
tipologia = "nome";
|
|
||||||
check2 = VerificaCorrettezza(nome, true);
|
check2 = VerificaCorrettezza(nome, true);
|
||||||
if (nomeapprossimato.Length > 40) {
|
if (nomeapprossimato.Length > 40) {
|
||||||
Console.WriteLine("il nome non può essere lungo più di 40 caratteri");
|
Console.WriteLine("il nome non può essere lungo più di 40 caratteri");
|
||||||
@ -147,16 +145,15 @@ class Program {
|
|||||||
static bool VerificaDoppione(string p_stringa, string[] p_stringhe, int p_contatore) {
|
static bool VerificaDoppione(string p_stringa, string[] p_stringhe, int p_contatore) {
|
||||||
bool check = false;
|
bool check = false;
|
||||||
if (p_contatore != 0) {
|
if (p_contatore != 0) {
|
||||||
for (int i = 0; i < p_contatore; i++) {
|
for (int i = 0; i < p_contatore && !(p_stringhe[i] == p_stringa); i++) ;
|
||||||
if (p_stringhe[i] == p_stringa) {
|
|
||||||
check = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return check;
|
return check;
|
||||||
}
|
}
|
||||||
static bool VerificaCorrettezza(string p_stringa, bool p_tipologia) {
|
static bool VerificaCorrettezza(string p_stringa, bool p_tipologia) {
|
||||||
|
/*
|
||||||
|
tipologia=true -> Controllo validità nome
|
||||||
|
tipologia=false -> Controllo validità numero di telefono
|
||||||
|
*/
|
||||||
bool check;
|
bool check;
|
||||||
const string NOME = "[1-9]+";
|
const string NOME = "[1-9]+";
|
||||||
const string TELEFONO = "^(?:\\(?\\+?\\d{1,3}\\)?|\\(?00\\d{1,3}\\)?)?[\\s-]?\\d{3}[\\s-]\\d{3}[\\s-]\\d{4}$";
|
const string TELEFONO = "^(?:\\(?\\+?\\d{1,3}\\)?|\\(?00\\d{1,3}\\)?)?[\\s-]?\\d{3}[\\s-]\\d{3}[\\s-]\\d{4}$";
|
||||||
@ -169,4 +166,25 @@ class Program {
|
|||||||
}
|
}
|
||||||
return check;
|
return check;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool Controllo(string p_stringa, bool p_tipologia, int p_contatore) {
|
||||||
|
bool ritorno = true;
|
||||||
|
if (p_stringa.Length > (p_tipologia ? 40 : 20)) {
|
||||||
|
Console.WriteLine($"Il {(p_tipologia ? "nome" : "numero di telefono")} non può essere lungo più di {(p_tipologia ? "40" : "20")} caratteri");
|
||||||
|
ritorno = false;
|
||||||
|
}
|
||||||
|
if (VerificaCorrettezza(p_stringa, p_tipologia)) {
|
||||||
|
Console.WriteLine(p_tipologia ? "Il nome non può contenere numeri" : "Numero di telefono non valido");
|
||||||
|
ritorno = false;
|
||||||
|
}
|
||||||
|
if (p_contatore != 0) {
|
||||||
|
if (check3 == true) {
|
||||||
|
Console.WriteLine("Questo nome esiste già nelle rubrica");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return ritorno;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
15
Voce.cs
15
Voce.cs
@ -4,25 +4,20 @@ class Voce {
|
|||||||
string nome;
|
string nome;
|
||||||
string numeroditelefono;
|
string numeroditelefono;
|
||||||
|
|
||||||
public Voce(string p_nome, string p_numeroditelefono)
|
public Voce(string p_nome, string p_numeroditelefono) {
|
||||||
{
|
|
||||||
this.nome = p_nome;
|
this.nome = p_nome;
|
||||||
this.numeroditelefono = p_numeroditelefono;
|
this.numeroditelefono = p_numeroditelefono;
|
||||||
}
|
}
|
||||||
public void SetNome(string p_nome)
|
public void SetNome(string p_nome) {
|
||||||
{
|
|
||||||
this.nome = p_nome;
|
this.nome = p_nome;
|
||||||
}
|
}
|
||||||
public void SetNumeroditelefono(string p_numeroditelefono)
|
public void SetNumeroditelefono(string p_numeroditelefono) {
|
||||||
{
|
|
||||||
this.numeroditelefono = p_numeroditelefono;
|
this.numeroditelefono = p_numeroditelefono;
|
||||||
}
|
}
|
||||||
public string GetNome()
|
public string GetNome() {
|
||||||
{
|
|
||||||
return this.nome;
|
return this.nome;
|
||||||
}
|
}
|
||||||
public string Getnumeroditelefono()
|
public string Getnumeroditelefono() {
|
||||||
{
|
|
||||||
return this.numeroditelefono;
|
return this.numeroditelefono;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user