Last active
November 21, 2017 10:09
-
-
Save aziis98/491b45d8883a169b6b7128234ca96d97 to your computer and use it in GitHub Desktop.
Esercizi della piattaforma di autovalutazione del 21 Novembre 2017
This file contains hidden or 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
| #include <stdio.h> | |
| typedef enum { crocchette, scatolette, tonno } Cibo; | |
| typedef struct { | |
| int id; | |
| int age; | |
| float weight; | |
| Cibo food_type; | |
| } Gatto; | |
| Gatto read_gatto() { | |
| Gatto gatto; | |
| scanf("%d", &gatto.id); | |
| scanf("%d", &gatto.age); | |
| scanf("%f", &gatto.weight); | |
| scanf("%d", &gatto.food_type); | |
| return gatto; | |
| } | |
| void print_gatto(Gatto gatto) { | |
| printf("%d ", gatto.id); | |
| switch (gatto.food_type) { | |
| case crocchette: | |
| printf("crocchette\n"); | |
| break; | |
| case tonno: | |
| printf("tonno\n"); | |
| break; | |
| case scatolette: | |
| printf("scatolette\n"); | |
| break; | |
| default: | |
| printf("???\n"); | |
| } | |
| } | |
| int main() { | |
| Gatto arr[4]; | |
| float media_peso = 0.0; | |
| for (int i = 0; i < 4; i++) { | |
| arr[i] = read_gatto(); | |
| media_peso += arr[i].weight; | |
| } | |
| media_peso /= 4.0; | |
| for (int i = 0; i < 4; i++) { | |
| if (arr[i].age < 4&& media_peso < arr[i].weight) { | |
| print_gatto(arr[i]); | |
| } | |
| } | |
| return 0; | |
| } | |
This file contains hidden or 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
| #include <stdio.h> | |
| struct persona { | |
| char nome[10]; | |
| struct persona * mamma; | |
| struct persona * babbo; | |
| }; | |
| typedef struct persona Persona; | |
| Persona read_persona() { | |
| Persona persona; | |
| persona.mamma = NULL; | |
| persona.babbo = NULL; | |
| for (int i = 0; i < 10; i++) { | |
| persona.nome[i] = getchar(); | |
| } | |
| return persona; | |
| } | |
| void print_nome(char nome[10]) { | |
| for (int i = 0; i < 10; i++) { | |
| putchar(nome[i]); | |
| } | |
| } | |
| void print_persona(Persona persona) { | |
| print_nome(persona.nome); | |
| printf("\n"); | |
| if (persona.mamma == NULL) { | |
| printf("Sconosciuto"); | |
| } | |
| else { | |
| print_nome(persona.mamma->nome); | |
| } | |
| if (persona.babbo == NULL) { | |
| printf("Sconosciuto"); | |
| } | |
| else { | |
| print_nome(persona.babbo->nome); | |
| } | |
| printf("\n"); | |
| } | |
| int main() { | |
| Persona figlio = read_persona(); | |
| Persona madre = read_persona(); | |
| Persona padre = read_persona(); | |
| figlio.mamma = &madre; | |
| figlio.babbo = &padre; | |
| print_persona(figlio); | |
| print_persona(madre); | |
| print_persona(padre); | |
| } |
This file contains hidden or 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
| #include <stdio.h> | |
| typedef struct { | |
| int id; | |
| int mese; | |
| int anno; | |
| int stipendio; | |
| } Dipendente; | |
| Dipendente read_dipendente() { | |
| Dipendente dipendente; | |
| scanf("%d", &dipendente.id); | |
| scanf("%d", &dipendente.mese); | |
| scanf("%d", &dipendente.anno); | |
| scanf("%d", &dipendente.stipendio); | |
| return dipendente; | |
| }; | |
| void aumenta_stipendi(Dipendente dipendenti[], int size, int percentuale) { | |
| for (int i = 0; i < size; i++) { | |
| if (dipendenti[i].anno < 2000 || (dipendenti[i].anno == 2000 && dipendenti[i].mese < 5)) { | |
| dipendenti[i].stipendio += dipendenti[i].stipendio * percentuale / 100; | |
| } | |
| } | |
| } | |
| int main() { | |
| int perc; | |
| Dipendente dipendenti[2]; | |
| for (int i = 0; i < 2; i++) { | |
| dipendenti[i] = read_dipendente(); | |
| } | |
| scanf("%d", &perc); | |
| aumenta_stipendi(dipendenti, 2, perc); | |
| for (int i = 0; i < 2; i++) { | |
| if (dipendenti[i].stipendio > 1200) { | |
| printf("%d %d\n", dipendenti[i].id, dipendenti[i].stipendio); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment