Opzione 3
This commit is contained in:
parent
1586311489
commit
de05db89a3
83
Program.cs
83
Program.cs
@ -6,7 +6,7 @@ class Program {
|
||||
Console.Clear();
|
||||
//dichiarazione e inizializzazione variabili
|
||||
int scelta;
|
||||
string[] arrayNomi = new string[dimensione], arrayCognomi = new string[dimensione];
|
||||
string[] arrayNomi = new string[dimensione], arrayCognomi = new string[dimensione], arrayNumeri;
|
||||
|
||||
//menu
|
||||
do {
|
||||
@ -37,7 +37,13 @@ class Program {
|
||||
break;
|
||||
case 3:
|
||||
Console.Clear();
|
||||
//StampaArray(InvertiArray(CreaArrayCasuale()));
|
||||
arrayNumeri = CreaVettore();
|
||||
Console.Clear();
|
||||
Console.WriteLine("Array originale:");
|
||||
StampaArray(arrayNumeri);
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("Array invertito: ");
|
||||
StampaArray(RibaltaVettore(arrayNumeri));
|
||||
Pausa();
|
||||
break;
|
||||
default:
|
||||
@ -80,22 +86,11 @@ class Program {
|
||||
}
|
||||
return ritorno;
|
||||
}
|
||||
|
||||
static void Pausa() {
|
||||
Console.WriteLine("Premere un tasto per continuare. . .");
|
||||
Console.ReadKey();
|
||||
Console.Clear();
|
||||
}
|
||||
static int[] InvertiArray(int[] p_array) {
|
||||
int[] ritorno = new int[dimensione];
|
||||
int j = dimensione - 1;
|
||||
|
||||
for (int i = 0; i < dimensione; i++) {
|
||||
ritorno[i] = p_array[j];//il primo elemento di ritorno è l'ultimo di p_array e così via, i e j variano in opposto
|
||||
j--;
|
||||
}
|
||||
return ritorno;
|
||||
}
|
||||
static void CreaVettoriParalleli(string[] p_arrayCognomi, string[] p_arrayNomi) {
|
||||
|
||||
for (int i = 0; i < dimensione; i++) { //Inserimento nomi e cognomi
|
||||
@ -112,7 +107,7 @@ class Program {
|
||||
p_arrayNomi[i] = Console.ReadLine();
|
||||
}
|
||||
}
|
||||
static void ControllaVettoriParalleli(string[] p_arrayCognomi, string[] p_arrayNomi){
|
||||
static void ControllaVettoriParalleli(string[] p_arrayCognomi, string[] p_arrayNomi) {
|
||||
string correzione;
|
||||
uint elemento;
|
||||
char scelta;
|
||||
@ -131,7 +126,7 @@ class Program {
|
||||
switch (scelta) {
|
||||
case 'S':
|
||||
break;
|
||||
|
||||
|
||||
case 'N':
|
||||
Console.Clear();
|
||||
|
||||
@ -148,7 +143,7 @@ class Program {
|
||||
|
||||
Console.Clear();
|
||||
|
||||
|
||||
|
||||
|
||||
do {
|
||||
switch (correzione) {
|
||||
@ -204,25 +199,25 @@ class Program {
|
||||
}
|
||||
static void CercaAlunni(string[] p_arrayCognomi, string[] p_arrayNomi) {
|
||||
Console.Clear();
|
||||
|
||||
|
||||
//dichiarazione e inizializzazione variabili
|
||||
string daCercare;
|
||||
int i = 0, indiceOccorrenze = 0;
|
||||
bool daCercareEsiste = false;
|
||||
|
||||
const int valoreNonValido = -1;
|
||||
int[] luogoOccorrenze = new int[dimensione];
|
||||
for (int j=0; j<dimensione; j++){
|
||||
int[] luogoOccorrenze = new int[dimensione + 1];
|
||||
for (int j = 0; j < dimensione + 1; j++) {
|
||||
luogoOccorrenze[j] = valoreNonValido;
|
||||
}
|
||||
|
||||
|
||||
do{
|
||||
|
||||
do {
|
||||
Console.Write("Per quale nome cercare? ");
|
||||
daCercare = Console.ReadLine();
|
||||
i = 0;
|
||||
for (; i<dimensione; i++){
|
||||
if (p_arrayNomi[i] == daCercare){ //se daCercare è un nome che esiste
|
||||
for (; i < dimensione; i++) {
|
||||
if (p_arrayNomi[i] == daCercare) { //se daCercare è un nome che esiste
|
||||
daCercareEsiste = true;
|
||||
luogoOccorrenze[indiceOccorrenze] = i;
|
||||
indiceOccorrenze++;
|
||||
@ -230,18 +225,54 @@ class Program {
|
||||
Console.WriteLine("Debug i: " + i);
|
||||
}
|
||||
|
||||
if(!daCercareEsiste){
|
||||
if (!daCercareEsiste) {
|
||||
Console.WriteLine("Il nome inserito non è stato trovato nella lista dei nomi, inserire un nome valido e riprovare");
|
||||
Pausa();
|
||||
}
|
||||
}
|
||||
while (!daCercareEsiste);
|
||||
|
||||
|
||||
Console.Clear();
|
||||
|
||||
Console.WriteLine("I cognomi che corrispondono al nome " + daCercare + " sono:");
|
||||
for (int j = 0; luogoOccorrenze[j]!=valoreNonValido; j++) {
|
||||
for (int j = 0; luogoOccorrenze[j] != valoreNonValido; j++) {
|
||||
Console.WriteLine(p_arrayCognomi[luogoOccorrenze[j]]);
|
||||
}
|
||||
}
|
||||
static string[] CreaVettore() {
|
||||
string[] ritorno = new string[dimensione];
|
||||
int i = 0, inputNumero;
|
||||
string input;
|
||||
const int minValue = 10, maxValue = 100;
|
||||
|
||||
do {
|
||||
Console.Clear();
|
||||
Console.WriteLine("Hai ancora " + (dimensione - i) + " numeri da poter inserire");
|
||||
Console.Write("Inserire un numero ([q] per uscire): ");
|
||||
input = Console.ReadLine(); //non posso ancora fare il catch dell'eccezione se viene inserito un qualcosa che non sia un numero o q
|
||||
if (input != "q") {
|
||||
inputNumero = Convert.ToInt32(input);
|
||||
if (inputNumero < minValue || inputNumero > maxValue) {
|
||||
Console.WriteLine("Il numero deve essere compreso tra " + minValue + " e " + maxValue);
|
||||
Pausa();
|
||||
}
|
||||
else {
|
||||
ritorno[i] = Convert.ToString(inputNumero);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
while (input != "q" && i < dimensione);
|
||||
return ritorno;
|
||||
}
|
||||
static string[] RibaltaVettore(string[] p_array) {
|
||||
string[] ritorno = new string[dimensione];
|
||||
int j = dimensione - 1;
|
||||
|
||||
for (int i = 0; i < dimensione; i++) {
|
||||
ritorno[i] = p_array[j];//il primo elemento di ritorno è l'ultimo di p_array e così via, i e j variano in opposto
|
||||
j--;
|
||||
}
|
||||
return ritorno;
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -13,7 +13,7 @@ using System.Reflection;
|
||||
[assembly: System.Reflection.AssemblyCompanyAttribute("ripasso4")]
|
||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+5e25bae12bffb762799385dca316b421094df672")]
|
||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+1586311489478f159982f3d338f62263cd3d7322")]
|
||||
[assembly: System.Reflection.AssemblyProductAttribute("ripasso4")]
|
||||
[assembly: System.Reflection.AssemblyTitleAttribute("ripasso4")]
|
||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||
|
||||
@ -1 +1 @@
|
||||
0acebe587ea036e7bc5b2ebd780d276040dd0061050ec63fb03b11fe5f4dfeed
|
||||
7e22376af2220273f7932470ad9af8b861f237d1607ec04f4558b1aa98801784
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user