Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <malloc.h>
- #include <stdio.h>
- #define max 100
- struct studenti {
- int matricola;
- char cognome [max];
- char nome [max];
- };
- struct esame {
- int matricola;
- char esami [max];
- int voto;
- };
- void inizializza_A (struct studenti **A, int n);
- //void inizializza_B (struct esame **B, int n);
- void aggiungi_studente (struct studenti **A, int n);
- void aggiungi_esame (struct studenti **A, struct esame **B, int n);
- int main(int argc, char **argv)
- {
- int n;
- n=1;
- struct studenti *A[n];
- struct esame *B[n];
- int scelta_2, flag, scelta;
- flag=0;
- do{
- printf ("Scegli voce:\n");
- printf ("1) Aggiungi Studente \n2) Aggiungi Esame \n 3) Stampa studenti \n4) Esci dal programma\n\n\n");
- scanf("%d", &scelta);
- switch (scelta){
- case 1:
- aggiungi_studente(A, n);
- printf ("\nVuoi aggiungere un altro studente (0=si, 1=no)?\n");
- scanf("%d", &scelta_2);
- if (scelta_2==0){
- aggiungi_studente(A, n);
- }
- else if (scelta_2==1){
- printf ("1) Aggiungi Studente \n2) Aggiungi Esame \n 3) Stampa studenti \n4) Esci dal programma\n\n\n");
- scanf("%d", &scelta);
- }
- break;
- case 2:
- aggiungi_esame(A, B, n);
- printf ("\nVuoi aggiungere un altro esame (0=si, 1=no)?\n");
- scanf("%d", &scelta_2);
- if (scelta_2==0){
- flag++;
- aggiungi_esame(A, B, n);
- }
- else if (scelta_2==1){
- printf ("1) Aggiungi Studente \n2) Aggiungi Esame \n 3) Stampa studenti \n4) Esci dal programma\n\n\n");
- scanf("%d", &scelta);
- }
- printf("\n");
- break;
- case 3:
- //stampa_studente(A, mediapiualta);
- printf ("\nVuoi fare altro (0=si, 1=no)?\n");
- scanf("%d", &scelta_2);
- if (scelta_2==0){
- printf ("1) Aggiungi Studente \n2) Aggiungi Esame \n 3) Stampa studenti \n4) Esci dal programma\n\n\n");
- scanf("%d", &scelta);
- }
- else if (scelta_2==1){
- printf("\nARRIVEDERCI\n");
- return 0;
- }
- break;
- case 4:
- printf("\nARRIVEDERCI\n");
- return 0;
- default:
- printf("Errore\n");
- }
- }
- while (scelta !=4);
- printf("\n");
- return 0;
- }
- void inizializza_A (struct studenti **A, int n){
- int i;
- i=0;
- for (i=0; i<n; i++){
- A[i]=NULL;
- }
- }
- //void inizializza_B (struct esame **B, int n);
- void aggiungi_studente (struct studenti **A, int n){
- int i=0;
- for (i=0; i<n; i++){
- A[i]=(struct studenti *) malloc (sizeof(struct studenti));
- printf("Matricola:");
- scanf("%d", &A[i]->matricola);
- printf("\n");
- printf("Cognome:");
- scanf("%s", A[i]->cognome);
- printf("\nNome:");
- scanf("%s", A[i]->nome);
- printf("\n");
- }
- }
- void aggiungi_esame (struct studenti **A, struct esame **B, int n){
- int i=0;
- for (i=0; i<n; i++){
- B[i]=(struct esame *)malloc (sizeof(struct esame));
- printf("Numero Matricola\n");
- scanf("%d", &B[i]->matricola);
- if (B[i]->matricola==A[i]->matricola){
- printf("Inserisci nome esame\n");
- scanf("%s", B[i]->esami);
- printf("\nInserisci voto:\n");
- scanf("%d", &B[i]->voto);
- }
- else{
- printf("\nMatricola errata, reinserisci:");
- scanf("%d", &B[i]->matricola);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement