Opzioni 1 e 4
This commit is contained in:
parent
394c4e4012
commit
adcd853d06
196
Program.cs
196
Program.cs
@ -1,9 +1,11 @@
|
||||
namespace vacanzeEstive_rubricaTelefonica;
|
||||
using System.Text.RegularExpressions;
|
||||
namespace vacanzeEstive_rubricaTelefonica;
|
||||
|
||||
class Program {
|
||||
static void Main(string[] args) {
|
||||
Console.Clear();
|
||||
int scelta = 0;
|
||||
Voce[] rubrica = new Voce[100]; //tetto massimo di voci possibili nella rubrica
|
||||
|
||||
do {
|
||||
Console.WriteLine("Inserire un'opzione:");
|
||||
@ -21,6 +23,7 @@ class Program {
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
CreaVoce(rubrica);
|
||||
Pausa();
|
||||
break;
|
||||
case 2:
|
||||
@ -29,6 +32,10 @@ class Program {
|
||||
case 3:
|
||||
Pausa();
|
||||
break;
|
||||
case 4:
|
||||
MostraRubrica(rubrica);
|
||||
Pausa();
|
||||
break;
|
||||
default:
|
||||
Console.WriteLine("Opzione non valida.");
|
||||
Pausa();
|
||||
@ -47,4 +54,191 @@ class Program {
|
||||
Console.WriteLine("Premere un tasto per continuare. . .");
|
||||
Console.ReadKey();
|
||||
}
|
||||
|
||||
static void CreaVoce(Voce[] p_rubrica) {
|
||||
bool error;
|
||||
string scelta;
|
||||
int indiceVoce = TrovaProssimaPosizioneDisponibile(p_rubrica);
|
||||
string nome;
|
||||
string cognome;
|
||||
string telefono;
|
||||
string cellulare = null;
|
||||
string email = null;
|
||||
string indirizzo = null;
|
||||
const int LUNGHEZZA_NOME = 40;
|
||||
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]";
|
||||
|
||||
do {
|
||||
Console.Write("Inserire il nome della persona: ");
|
||||
nome = Console.ReadLine();
|
||||
|
||||
if (nome.Length > LUNGHEZZA_NOME) {
|
||||
Console.WriteLine($"Errore: il nome non può superare i {LUNGHEZZA_NOME} caratteri.");
|
||||
Pausa();
|
||||
}
|
||||
}
|
||||
while (nome.Length > LUNGHEZZA_NOME);
|
||||
|
||||
do {
|
||||
Console.Write("Inserire il cognome della persona: ");
|
||||
cognome = Console.ReadLine();
|
||||
|
||||
if (cognome.Length > LUNGHEZZA_NOME) {
|
||||
Console.WriteLine($"Errore: il cognome non può superare i {LUNGHEZZA_NOME} caratteri.");
|
||||
Pausa();
|
||||
}
|
||||
}
|
||||
while (cognome.Length > LUNGHEZZA_NOME);
|
||||
|
||||
do {
|
||||
error = false;
|
||||
Console.Write("Inserire il numero di telefono della persona: ");
|
||||
telefono = Console.ReadLine();
|
||||
|
||||
if (telefono.Length > LUNGHEZZA_TELEFONO) {
|
||||
error = true;
|
||||
Console.WriteLine($"Errore: il numero di telefono non può superare i {LUNGHEZZA_TELEFONO} caratteri.");
|
||||
Pausa();
|
||||
}
|
||||
if (!Regex.IsMatch(telefono, TELEFONO)) {
|
||||
error = true;
|
||||
Console.WriteLine("Errore: il numero di telefono inserito non è valido.");
|
||||
Pausa();
|
||||
}
|
||||
}
|
||||
while (error);
|
||||
|
||||
do {
|
||||
error = false;
|
||||
Console.Write("Inserire il numero cellulare? [S/N] ");
|
||||
scelta = Console.ReadLine();
|
||||
|
||||
if (Regex.IsMatch(scelta, CONFERMA)) {
|
||||
do {
|
||||
error = false;
|
||||
Console.Write("Inserire il numero cellulare della persona: ");
|
||||
cellulare = Console.ReadLine();
|
||||
|
||||
if (cellulare.Length > LUNGHEZZA_TELEFONO) {
|
||||
error = true;
|
||||
Console.WriteLine($"Errore: il numero cellulare non può superare i {LUNGHEZZA_TELEFONO} caratteri.");
|
||||
Pausa();
|
||||
}
|
||||
if (!Regex.IsMatch(cellulare, TELEFONO)) {
|
||||
error = true;
|
||||
Console.WriteLine("Errore: il numero cellulare inserito non è valido.");
|
||||
Pausa();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
while (error);
|
||||
}
|
||||
else if (Regex.IsMatch(scelta, NEGAZIONE)) {
|
||||
cellulare = "";
|
||||
}
|
||||
else {
|
||||
error = true;
|
||||
Console.WriteLine("Opzione non valida.");
|
||||
Pausa();
|
||||
}
|
||||
}
|
||||
while (error);
|
||||
|
||||
do {
|
||||
error = false;
|
||||
Console.Write("Inserire l'email? [S/N] ");
|
||||
scelta = Console.ReadLine();
|
||||
|
||||
if (Regex.IsMatch(scelta, CONFERMA)) {
|
||||
do {
|
||||
error = false;
|
||||
Console.Write("Inserire l'email della persona: ");
|
||||
email = Console.ReadLine();
|
||||
|
||||
if (!Regex.IsMatch(email, EMAIL)) {
|
||||
error = true;
|
||||
Console.WriteLine("Errore: l'email inserita non è valida.");
|
||||
Pausa();
|
||||
}
|
||||
}
|
||||
while (error);
|
||||
}
|
||||
else if (Regex.IsMatch(scelta, NEGAZIONE)) {
|
||||
email = "";
|
||||
}
|
||||
else {
|
||||
error = true;
|
||||
Console.WriteLine("Opzione non valida.");
|
||||
Pausa();
|
||||
}
|
||||
}
|
||||
while (error);
|
||||
|
||||
do {
|
||||
error = false;
|
||||
Console.Write("Inserire l'indirizzo? [S/N] ");
|
||||
scelta = Console.ReadLine();
|
||||
|
||||
if (Regex.IsMatch(scelta, CONFERMA)) {
|
||||
do {
|
||||
error = false;
|
||||
Console.Write("Inserire l'indirizzo della persona: ");
|
||||
indirizzo = Console.ReadLine();
|
||||
if (string.IsNullOrEmpty(indirizzo)) {
|
||||
error = true;
|
||||
Console.WriteLine("Errore: inserire un indirizzo non vuoto.");
|
||||
Pausa();
|
||||
}
|
||||
}
|
||||
while (error);
|
||||
}
|
||||
else if (Regex.IsMatch(scelta, NEGAZIONE)) {
|
||||
indirizzo = "";
|
||||
}
|
||||
|
||||
else {
|
||||
error = true;
|
||||
Console.WriteLine("Opzione non valida.");
|
||||
Pausa();
|
||||
}
|
||||
}
|
||||
while (error);
|
||||
|
||||
if (indiceVoce == -1) {
|
||||
Console.WriteLine("Errore: la rubrica è piena.");
|
||||
}
|
||||
else {
|
||||
p_rubrica[indiceVoce] = 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;
|
||||
}
|
||||
}
|
||||
|
||||
return !exit ? i : -1;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
23
Voce.cs
23
Voce.cs
@ -1,5 +1,28 @@
|
||||
namespace vacanzeEstive_rubricaTelefonica;
|
||||
|
||||
class Voce {
|
||||
string nome;
|
||||
string cognome;
|
||||
string telefono;
|
||||
string cellulare;
|
||||
string email;
|
||||
string indirizzo;
|
||||
|
||||
public Voce(string p_nome, string p_cognome, string p_telefono, string p_cellulare, string p_email, string p_indirizzo) {
|
||||
this.nome = p_nome;
|
||||
this.cognome = p_cognome;
|
||||
this.telefono = p_telefono;
|
||||
this.cellulare = p_cellulare;
|
||||
this.email = p_email;
|
||||
this.indirizzo = p_indirizzo;
|
||||
}
|
||||
|
||||
public void MostraVoce() {
|
||||
Console.WriteLine($"\tNome: {this.nome}");
|
||||
Console.WriteLine($"\tCognome: {this.cognome}");
|
||||
Console.WriteLine($"\tTelefono: {this.telefono}");
|
||||
Console.WriteLine($"\tCellulare: {this.cellulare}");
|
||||
Console.WriteLine($"\tEmail: {this.email}");
|
||||
Console.WriteLine($"\tIndirizzo: {this.indirizzo}");
|
||||
}
|
||||
}
|
||||
BIN
bin/Debug/net9.0/vacanzeEstive_rubricaTelefonica
Executable file
BIN
bin/Debug/net9.0/vacanzeEstive_rubricaTelefonica
Executable file
Binary file not shown.
23
bin/Debug/net9.0/vacanzeEstive_rubricaTelefonica.deps.json
Normal file
23
bin/Debug/net9.0/vacanzeEstive_rubricaTelefonica.deps.json
Normal file
@ -0,0 +1,23 @@
|
||||
{
|
||||
"runtimeTarget": {
|
||||
"name": ".NETCoreApp,Version=v9.0",
|
||||
"signature": ""
|
||||
},
|
||||
"compilationOptions": {},
|
||||
"targets": {
|
||||
".NETCoreApp,Version=v9.0": {
|
||||
"vacanzeEstive_rubricaTelefonica/1.0.0": {
|
||||
"runtime": {
|
||||
"vacanzeEstive_rubricaTelefonica.dll": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"libraries": {
|
||||
"vacanzeEstive_rubricaTelefonica/1.0.0": {
|
||||
"type": "project",
|
||||
"serviceable": false,
|
||||
"sha512": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
bin/Debug/net9.0/vacanzeEstive_rubricaTelefonica.dll
Normal file
BIN
bin/Debug/net9.0/vacanzeEstive_rubricaTelefonica.dll
Normal file
Binary file not shown.
BIN
bin/Debug/net9.0/vacanzeEstive_rubricaTelefonica.pdb
Normal file
BIN
bin/Debug/net9.0/vacanzeEstive_rubricaTelefonica.pdb
Normal file
Binary file not shown.
@ -0,0 +1,12 @@
|
||||
{
|
||||
"runtimeOptions": {
|
||||
"tfm": "net9.0",
|
||||
"framework": {
|
||||
"name": "Microsoft.NETCore.App",
|
||||
"version": "9.0.0"
|
||||
},
|
||||
"configProperties": {
|
||||
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
obj/Debug/net9.0/apphost
Executable file
BIN
obj/Debug/net9.0/apphost
Executable file
Binary file not shown.
BIN
obj/Debug/net9.0/ref/vacanzeEstive_rubricaTelefonica.dll
Normal file
BIN
obj/Debug/net9.0/ref/vacanzeEstive_rubricaTelefonica.dll
Normal file
Binary file not shown.
BIN
obj/Debug/net9.0/refint/vacanzeEstive_rubricaTelefonica.dll
Normal file
BIN
obj/Debug/net9.0/refint/vacanzeEstive_rubricaTelefonica.dll
Normal file
Binary file not shown.
@ -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+2b8a74dc3d7e2b5d4ec8c84246e6d5258a05a207")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+394c4e4012c619345c24a8351853ea1ad8a0dc6b")]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute("vacanzeEstive_rubricaTelefonica")]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("vacanzeEstive_rubricaTelefonica")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
||||
@ -1 +1 @@
|
||||
1cf205894741f0f344720b04f287e466e62e0c71f7ba235f2c86401c9a1d40c3
|
||||
fb0d1ec8b0274d7315e8b09e330ec685e30dd469f5d8fc537973ed9c1d3cad12
|
||||
|
||||
@ -0,0 +1 @@
|
||||
af9cbbb2db2ed0ec0383684e12942aaf1c3338d3b532433546c495d7b4a602b1
|
||||
@ -0,0 +1,14 @@
|
||||
/home/Verde/git/vacanzeEstive_rubricaTelefonica/bin/Debug/net9.0/vacanzeEstive_rubricaTelefonica
|
||||
/home/Verde/git/vacanzeEstive_rubricaTelefonica/bin/Debug/net9.0/vacanzeEstive_rubricaTelefonica.deps.json
|
||||
/home/Verde/git/vacanzeEstive_rubricaTelefonica/bin/Debug/net9.0/vacanzeEstive_rubricaTelefonica.runtimeconfig.json
|
||||
/home/Verde/git/vacanzeEstive_rubricaTelefonica/bin/Debug/net9.0/vacanzeEstive_rubricaTelefonica.dll
|
||||
/home/Verde/git/vacanzeEstive_rubricaTelefonica/bin/Debug/net9.0/vacanzeEstive_rubricaTelefonica.pdb
|
||||
/home/Verde/git/vacanzeEstive_rubricaTelefonica/obj/Debug/net9.0/vacanzeEstive_rubricaTelefonica.GeneratedMSBuildEditorConfig.editorconfig
|
||||
/home/Verde/git/vacanzeEstive_rubricaTelefonica/obj/Debug/net9.0/vacanzeEstive_rubricaTelefonica.AssemblyInfoInputs.cache
|
||||
/home/Verde/git/vacanzeEstive_rubricaTelefonica/obj/Debug/net9.0/vacanzeEstive_rubricaTelefonica.AssemblyInfo.cs
|
||||
/home/Verde/git/vacanzeEstive_rubricaTelefonica/obj/Debug/net9.0/vacanzeEstive_rubricaTelefonica.csproj.CoreCompileInputs.cache
|
||||
/home/Verde/git/vacanzeEstive_rubricaTelefonica/obj/Debug/net9.0/vacanzeEstive_rubricaTelefonica.dll
|
||||
/home/Verde/git/vacanzeEstive_rubricaTelefonica/obj/Debug/net9.0/refint/vacanzeEstive_rubricaTelefonica.dll
|
||||
/home/Verde/git/vacanzeEstive_rubricaTelefonica/obj/Debug/net9.0/vacanzeEstive_rubricaTelefonica.pdb
|
||||
/home/Verde/git/vacanzeEstive_rubricaTelefonica/obj/Debug/net9.0/vacanzeEstive_rubricaTelefonica.genruntimeconfig.cache
|
||||
/home/Verde/git/vacanzeEstive_rubricaTelefonica/obj/Debug/net9.0/ref/vacanzeEstive_rubricaTelefonica.dll
|
||||
BIN
obj/Debug/net9.0/vacanzeEstive_rubricaTelefonica.dll
Normal file
BIN
obj/Debug/net9.0/vacanzeEstive_rubricaTelefonica.dll
Normal file
Binary file not shown.
@ -0,0 +1 @@
|
||||
1e0f26abcfceab9ac156ad7d9496024505c2298d85e6d53d15ff3c29c6b701c2
|
||||
BIN
obj/Debug/net9.0/vacanzeEstive_rubricaTelefonica.pdb
Normal file
BIN
obj/Debug/net9.0/vacanzeEstive_rubricaTelefonica.pdb
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user