This repository has been archived by the owner on Jun 16, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
092c352
commit 190dda6
Showing
7 changed files
with
160 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Tipo booleano | ||
|
||
OPERATORE - NUMERO ARG - POSIZIONE | ||
! - unario - prefisso | ||
&& - binario - infisso | ||
|| - binario - infisso | ||
|
||
bool -> int | ||
true -> 1 | ||
false -> 0 | ||
|
||
int -> bool | ||
n!=0 -> true | ||
0 -> false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Operatori | ||
|
||
- additivi | ||
- moltiplicativi | ||
- ... | ||
- di confronto (relazione, uguaglianza) | ||
- logici | ||
- assegnamento | ||
- accodamento | ||
|
||
## Operatori logici | ||
|
||
x == true --> x | ||
x == false --> !x | ||
|
||
La seconda forma viene preferita per compattezza. | ||
|
||
OVERLOADING degli operatori = dare più significato di quello che hanno (eg. assegnare un int ad un bool) | ||
|
||
## Priorità | ||
Accodamento ha priorità minore rispetto agli altri, attento a valutare espressioni mentre fai in o out da stream. | ||
|
||
## Assegnamento | ||
a += 1 --> a = a + 1 | ||
... | ||
|
||
## Incremento e decremento | ||
- prefisso: effettua incremento/decremento, poi valuta l'espressione (usa la variabile). Ritorna _lvalue_ della variabile (indirizzo). Eg. (++a) = 4 è valido | ||
- postfisso: usa la variabile, poi effettua l'incremento/decremento della variabile. Ritorna _rvalue_ della variabile (ovvero il suo valore). Eg. (a++) = 4 non è valido | ||
|
||
## Espressioni | ||
= costrutto sintattico costituito da letterali, identificatori, operatori e parentesi tonde | ||
|
||
## Associatività | ||
= ordine con cui vengono valutati operatori con la stessa precedenza | ||
|
||
Associatività operatore di assegnamento -> dx (da destra a sinistra) | ||
|
||
TODO: aggiungi tabella priorità operatori | ||
|
||
TRACING = seguire passo passo le istruzioni | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# Programmazione strutturata | ||
|
||
La prima tecnica utilizzata per fare *branching* è il salto: | ||
- jump (linguaggio macchina) | ||
- goto (alto livello) | ||
|
||
Un salto all'indietro corrisponde ad un ciclo. | ||
|
||
*Spaghetti code* = logica a spaghetti = aggrovigliamento del codice | ||
|
||
## Programmazione strutturata | ||
Introdotta da Dijkstra | ||
TODO: completa (con i tre tipi) | ||
|
||
## Macchina di Turing | ||
Vantaggi: | ||
- programmi leggibili | ||
- facili da mantenere | ||
|
||
Perdiamo qualcosa? No | ||
Macchina di Turing: macchina dotata di testina che può leggere o scrivere (0 o 1) su un nastro che scorre avanti o indietro. Vedi Doodle. | ||
|
||
Tesi di Church-Turing: ogni codice può essere eseguito da una macchina di Turing (Test di Turing) | ||
|
||
Teorema di Jacopini-Boem: ogni algoritmo può essere tradotto in un programma se si ha a disposizione un linguaggio Turing-completo: | ||
- TODO: completa | ||
|
||
## Costrutti condizionali | ||
- scelta semplice o alternativa | ||
- scelta multipla | ||
|
||
### Scelta semplice | ||
Consente di scegliere tra due istruzioni alternative in base al verificarsi di una condizione. | ||
|
||
<istruzione-scelta> ::= | ||
if (<condizione>) | ||
<istruzione-1> | ||
[else | ||
<istruzione-2>] | ||
|
||
### Digressione sullo 0 | ||
Lo zero non è nè positivo nè negativo. | ||
|
||
n>0 è NON negativo | ||
|
||
### Indentazione | ||
=> utile per migliorare leggibilità, ma non essenziale. Servono le parentesi graffe (istruzione composta) per eseguire un blocco di istruzioni in un ramo dell'if/else | ||
|
||
TODO: add link esercizi | ||
|
||
## Sanificazione e controllo delle eccezioni | ||
Operazione illegale -> CPU lancia hardware exception -> OS associa errore -> terminazione forzata del programma (overflow, non inizializzazione) | ||
|
||
## Good programming choices | ||
- No *numeri magici* -> no numeri senza nome -> usa costanti con nome | ||
- Nomi significativi (self-explanatory) | ||
- Non replicare il codice. Se un bug è contenuto in una replica, probabilmente anche le altre repliche lo contengono. Codice riusabile. | ||
|
||
TODO: link a es velocità download + reimplementa a casa + multiplo.cc + ordinati.cc |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include <iostream> | ||
|
||
using namespace std; | ||
|
||
int main() { | ||
const int a = 1, b = 10; | ||
int controllo, i; | ||
|
||
cout << "Inserisci controllo: "; | ||
cin >> controllo; | ||
|
||
cout << "Inserisci i: "; | ||
cin >> i; | ||
|
||
if (controllo) | ||
if (a<=i && b>=i) | ||
cout << "i è incluso nell'intervallo"; | ||
else | ||
cout << "i non è incluso nell'intervallo"; | ||
else | ||
cout << "Nessun controllo"; | ||
cout << endl; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include <iostream> | ||
|
||
using namespace std; | ||
|
||
int main() { | ||
int a, b; | ||
cout << "Inserisci a: "; | ||
cin >> a; | ||
cout << "Inserisci b: "; | ||
cin >> b; | ||
if (b==0) { | ||
cout << "Divisore non valido" << endl; | ||
return 1; | ||
} | ||
else { | ||
cout << "Risultato: " << a/b << endl; | ||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#include <iostream> | ||
|
||
// TODO: esercizio inclusione senza && |