From 70912ecbdaffb778a4f3c4990fad30e58cdf81ec Mon Sep 17 00:00:00 2001 From: Vichingo455 Date: Fri, 10 Jan 2025 12:41:37 +0000 Subject: [PATCH] Upload files to "verifica_2" --- verifica_2/esercizio1.cpp | 59 +++++++++++++++++++++++++++++++++++++++ verifica_2/esercizio2.cpp | 46 ++++++++++++++++++++++++++++++ verifica_2/esercizio3.cpp | 26 +++++++++++++++++ 3 files changed, 131 insertions(+) create mode 100644 verifica_2/esercizio1.cpp create mode 100644 verifica_2/esercizio2.cpp create mode 100644 verifica_2/esercizio3.cpp diff --git a/verifica_2/esercizio1.cpp b/verifica_2/esercizio1.cpp new file mode 100644 index 0000000..c214b0e --- /dev/null +++ b/verifica_2/esercizio1.cpp @@ -0,0 +1,59 @@ +/* +AUTORE: Manuel Vichi + +*/ +#include +using namespace std; +bool esco(int Sara, int Lara, int Luca) { + return (Sara || Lara) && !Luca; +} +void stampaTabella() { + for (int Sara = 0; Sara <= 8; Sara++) { + cout << "Sara: "; + if (Sara == 1) + cout << "1"; + else + cout << "0"; + cout << " | "; + + for (int Lara = 0; Lara <= 1; Lara++) { + cout << "Lara: "; + if (Lara == 1) + cout << "1"; + else + cout << "0"; + cout << " | "; + + for (int Luca = 0; Luca <= 1; Luca++) { + bool risultato; + if (Sara == 1 && Lara == 1) { + risultato = Sara || Lara; + } else if (Sara == 1 && Lara == 0) { + risultato = Sara; + } else if (Sara == 0 && Luca == 1) { + risultato = false; + } else if (Lara == 1 && Luca == 0) { + risultato = Sara || Lara; + } else if (Lara == 0 && Luca == 1) { + risultato = false; + } else { + risultato = esco(Sara, Lara, Luca); + } + + cout << "Risultato: "; + if (risultato == true) + cout << "1"; + else + cout << "0"; + + cout << " | "; + cout << endl; + } + } + } +} + +int main() { + stampaTabella(); + return 0; +} diff --git a/verifica_2/esercizio2.cpp b/verifica_2/esercizio2.cpp new file mode 100644 index 0000000..1218be2 --- /dev/null +++ b/verifica_2/esercizio2.cpp @@ -0,0 +1,46 @@ +/* +AUTORE: Manuel Vichi + +*/ +#include +using namespace std; + +void insertionSort(int arr[], int n) { + for (int i = 1; i < n; i++) { + int key = arr[i]; + int j = i - 1; + + while (j >= 0 && arr[j] > key) { + arr[j + 1] = arr[j]; + j--; + } + arr[j + 1] = key; + } +} +int eliminaDuplicati(int arr[], int n) { + int finalSize = n; + for (int i = n; i > n/2; i--) { + for (int j = 0; j < n; j++) { + if (arr[i] == arr[j]) { + arr[j] = arr[i]; + finalSize--; + } + } + } + return finalSize; +} +void printArray(int arr[], int n) { + for (int i = 0; i < n; i++) { + cout << arr[i] << " "; + } + cout << endl; +} + +int main() { + int v1[] = {1, 2, 2, 3, 4, 3, 5, 6, 6, 7}; + int n = sizeof(v1) / sizeof(v1[0]); + printArray(v1,n); + insertionSort(v1, n); + + return 0; +} \ No newline at end of file diff --git a/verifica_2/esercizio3.cpp b/verifica_2/esercizio3.cpp new file mode 100644 index 0000000..c2d3470 --- /dev/null +++ b/verifica_2/esercizio3.cpp @@ -0,0 +1,26 @@ +#include +using namespace std; +void generaMatrice(int matrice[][10], int righe, int colonne) + +int main() { + srand(time(0)); // Inizializza il generatore di numeri casuali + + int matrice[5][10]; // Matrice 5x10 + int righe = 5, colonne = 10; + + // Genera e stampa la matrice casuale + generaMatrice(matrice, righe, colonne); + cout << "Matrice generata:" << endl; + stampaMatrice(matrice, righe, colonne); + + // Modifica le colonne 2 e 4 impostando tre elementi consecutivi successivi + modificaColonne(matrice, righe); + cout << "\nMatrice modificata (colonne 2 e 4 con valori successivi):" << endl; + stampaMatrice(matrice, righe, colonne); + + // Analizza e stampa le colonne con tre elementi consecutivi successivi + cout << endl; + stampaColonneConsecutive(matrice, righe, colonne); + + return 0; +}