Skip to content
This repository has been archived by the owner on Jun 16, 2023. It is now read-only.

Commit

Permalink
fine lezione 5
Browse files Browse the repository at this point in the history
  • Loading branch information
mc-cat-tty committed Oct 5, 2021
1 parent 847c447 commit a6b0eae
Show file tree
Hide file tree
Showing 14 changed files with 234 additions and 0 deletions.
12 changes: 12 additions & 0 deletions 5_dimensioni_dato.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Tipi di dato
## sizeof(<espressione>)
Ritorna la dimensione di un tipo di dato oppure di un espressione (variabile, espressione numerica, confronto)

TODO: vedi esercizio

## Overflow
=> se accettiamo valori più grossi di quelli consentiti

Quando il valore di un espressione è troppo grande per essere contenuto. No errori.


6 changes: 6 additions & 0 deletions 5_fasi_sviluppo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Fasi sviluppo
## Attori
Programmatore, compilatore, utente (utonto)

## Fasi

13 changes: 13 additions & 0 deletions 5_miniprova_prima_test.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Miniprova prima parte

## PARTE 1
1) a
2) c
3) d -> Il risultato di un assegnamento (b=8) è l'lvalue della variabile, ovvero l'indirizzo in memoria di b.

## PARTE 2
4) a, c

## PARTE 3


8 changes: 8 additions & 0 deletions 5_switch.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,11 @@ istruzione-scelta-multipla ::=
}

l'_espressione di selezione_ deve essere di tipo *numerabile*: int, char o enum.

## Pro e contro
Pro:
- aumenta leggibilità
- evita di scorrere una serie di if-else
Contro:
- costrutto ingombrante (sconsigliato per numero casi minore o uguale a 2)
- non utilizzabile con numeri reali e tipi di dato strutturati
Binary file modified esercitazioni/a.out
Binary file not shown.
55 changes: 55 additions & 0 deletions esercitazioni/calcolatrice.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include <iostream>

using namespace std;

int main() {
int a, b, sel;
cout <<
"1 --> +\n"
"2 --> -\n"
"3 --> *\n"
"4 --> /\n"
"5 --> resto divisione intera\n"
"\n";

cout << "Inserire a: ";
cin >> a;

cout << "Inserire b: ";
cin >> b;

cout << "Selezione: ";
cin >> sel;

switch (sel) {
case 1:
cout << a << " + " << b << " = " << a+b;
break;
case 2:
cout << a << " - " << b << " = " << a-b;
break;
case 3:
cout << a << " * " << b << " = " << a*b;
break;
case 4:
if (b == 0) {
cout << "Operazione non valida";
break;
}
cout << a << " / " << b << " = " << a/b;
break;
case 5:
if (b == 0) {
cout << "Operazione non valida";
break;
}
cout << a << " % " << b << " = " << a%b;
break;
default:
cout << "Opzione inesistente";
}
cout << endl;
// Miglioramenti: usa flag, ritorna exit code diverso da 0 in caso di errore

return 0;
}
11 changes: 11 additions & 0 deletions esercitazioni/deref.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <iostream>

using namespace std;

int main() {
int b = 0;
if (b=0)
cout << "true" << endl;
else
cout << "false" << endl;
}
8 changes: 8 additions & 0 deletions esercitazioni/overflow.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <iostream>

using namespace std;

int main() {
int i =
// TODO
}
9 changes: 9 additions & 0 deletions esercitazioni/overflow_checker.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <iostream>

using namespace std;

int main() {
int ;
// TODO: verifica overflow somma e sottrazione
return 0;
}
1 change: 1 addition & 0 deletions esercitazioni/overflow_checker_prod.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// TODO: verifica overflow in prodotto
10 changes: 10 additions & 0 deletions esercitazioni/sizeof_int.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <iostream>

using namespace std;

int main() {
cout << "Dimensione int su questa macchina: " << sizeof(int) << " bytes" << endl;
cout << "Dimensione 10+50 su questa macchina: " << sizeof(10+50) << " bytes" << endl;
cout << "Dimensione bool su questa macchina: " << sizeof(1<2) << " bytes" << endl;
return 0;
}
27 changes: 27 additions & 0 deletions esercitazioni/switch_case.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <iostream>

using namespace std;

int main() {
int a = 2, n;
cin >> n;
switch (n) {
case 1:
cout << "Ramo A";
break;
case 2:
cout << "Ramo B";
a = a*a;
break;
case 3:
cout << "Ramo C";
a = a*a*a;
// break;
default:
a = 1;
}

cout << endl << a << endl;

return 0;
}
36 changes: 36 additions & 0 deletions esercitazioni/switch_opzione.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include <iostream>

using namespace std;

int main() {
int n;

cout << "1\tOpzione A\n"
"2\tOpzione B\n"
"3\tOpzione C\n"
"4\tOpzione D\n"
"\n";

cout << "Scegli un opzione: ";
cin >> n;

switch (n) {
case 1:
cout << "Opzione A";
break;
case 2:
cout << "Opzione B";
break;
case 3:
cout << "Opzione C";
break;
case 4:
cout << "Opzione D";
break;
default:
cout << "Scelta non valida";
}
cout << endl;

return 0;
}
38 changes: 38 additions & 0 deletions esercitazioni/switch_opzione2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include <iostream>

using namespace std;

int main() {
int n;

cout << "1\tOpzione A\n"
"3\tOpzione B\n"
"4\tOpzione C\n"
"5\tOpzione C\n"
"6\tOpzione D\n"
"\n";

cout << "Scegli un opzione: ";
cin >> n;

switch (n) {
case 1:
cout << "Opzione A";
break;
case 3:
cout << "Opzione B";
break;
case 4:
case 5:
cout << "Opzione C";
break;
case 6:
cout << "Opzione D";
break;
default:
cout << "Scelta non valida";
}
cout << endl;

return 0;
}

0 comments on commit a6b0eae

Please sign in to comment.