Advertisement
Guest User

Untitled

a guest
Apr 25th, 2015
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.06 KB | None | 0 0
  1.  
  2. #include <stdlib.h>
  3. #include <malloc.h>
  4. #include <stdio.h>
  5. #define max 100
  6.  
  7. struct studenti {
  8.     int matricola;
  9.     char cognome [max];
  10.     char nome [max];
  11. };
  12.  
  13. struct esame {
  14.     int matricola;
  15.     char esami [max];
  16.     int voto;
  17. };
  18.  
  19. void inizializza_A (struct studenti **A, int n);
  20. //void inizializza_B (struct esame **B, int n);
  21. void aggiungi_studente (struct studenti **A, int n);
  22. void aggiungi_esame (struct studenti **A, struct esame **B, int n);
  23.  
  24. int main(int argc, char **argv)
  25. {
  26.     int n;
  27.     n=1;
  28.     struct studenti *A[n];
  29.     struct esame *B[n];
  30.     int scelta_2, flag, scelta;
  31.     flag=0;
  32.     do{
  33.         printf ("Scegli voce:\n");
  34.         printf ("1) Aggiungi Studente \n2) Aggiungi Esame \n 3) Stampa studenti \n4) Esci dal programma\n\n\n");
  35.         scanf("%d", &scelta);
  36.         switch (scelta){
  37.             case 1:
  38.             aggiungi_studente(A, n);
  39.             printf ("\nVuoi aggiungere un altro studente (0=si, 1=no)?\n");
  40.             scanf("%d", &scelta_2);
  41.             if (scelta_2==0){
  42.                 aggiungi_studente(A, n);
  43.             }
  44.             else if (scelta_2==1){
  45.                 printf ("1) Aggiungi Studente \n2) Aggiungi Esame \n 3) Stampa studenti \n4) Esci dal programma\n\n\n");
  46.                 scanf("%d", &scelta);
  47.             }
  48.             break;
  49.             case 2:
  50.             aggiungi_esame(A, B, n);
  51.             printf ("\nVuoi aggiungere un altro esame (0=si, 1=no)?\n");
  52.             scanf("%d", &scelta_2);
  53.             if (scelta_2==0){
  54.                 flag++;
  55.                 aggiungi_esame(A, B, n);
  56.             }
  57.             else if (scelta_2==1){
  58.                 printf ("1) Aggiungi Studente \n2) Aggiungi Esame \n 3) Stampa studenti \n4) Esci dal programma\n\n\n");
  59.                 scanf("%d", &scelta);
  60.             }
  61.             printf("\n");
  62.             break;
  63.             case 3:
  64.             //stampa_studente(A, mediapiualta);
  65.             printf ("\nVuoi fare altro (0=si, 1=no)?\n");
  66.             scanf("%d", &scelta_2);
  67.             if (scelta_2==0){
  68.                 printf ("1) Aggiungi Studente \n2) Aggiungi Esame \n 3) Stampa studenti \n4) Esci dal programma\n\n\n");
  69.                 scanf("%d", &scelta);
  70.             }
  71.             else if (scelta_2==1){
  72.                 printf("\nARRIVEDERCI\n");
  73.                 return 0;
  74.             }
  75.             break;
  76.             case 4:
  77.             printf("\nARRIVEDERCI\n");
  78.             return 0;
  79.             default:
  80.             printf("Errore\n");
  81.             }
  82.         }
  83.     while (scelta !=4);
  84.     printf("\n");
  85.     return 0;
  86. }
  87.  
  88. void inizializza_A (struct studenti **A, int n){
  89.     int i;
  90.     i=0;
  91.     for (i=0; i<n; i++){
  92.         A[i]=NULL;
  93.     }
  94. }
  95. //void inizializza_B (struct esame **B, int n);
  96. void aggiungi_studente (struct studenti **A, int n){
  97.     int i=0;
  98.     for (i=0; i<n; i++){
  99.         A[i]=(struct studenti *) malloc (sizeof(struct studenti));
  100.         printf("Matricola:");
  101.         scanf("%d", &A[i]->matricola);
  102.         printf("\n");
  103.         printf("Cognome:");
  104.         scanf("%s", A[i]->cognome);
  105.         printf("\nNome:");
  106.         scanf("%s", A[i]->nome);
  107.         printf("\n");
  108.     }
  109. }
  110. void aggiungi_esame (struct studenti **A, struct esame **B, int n){
  111.     int i=0;
  112.     for (i=0; i<n; i++){
  113.         B[i]=(struct esame *)malloc (sizeof(struct esame));
  114.         printf("Numero Matricola\n");
  115.         scanf("%d", &B[i]->matricola);
  116.         if (B[i]->matricola==A[i]->matricola){
  117.             printf("Inserisci nome esame\n");
  118.             scanf("%s", B[i]->esami);
  119.             printf("\nInserisci voto:\n");
  120.             scanf("%d", &B[i]->voto);
  121.         }
  122.         else{
  123.             printf("\nMatricola errata, reinserisci:");
  124.             scanf("%d", &B[i]->matricola);
  125.         }
  126.     }
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement