Advertisement
fedexist

Registro

Feb 8th, 2013
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.54 KB | None | 0 0
  1. //main.c
  2. #include <stdio.h>
  3. #include "logic.h"
  4. #define MAX 20
  5.  
  6. int main()
  7. {
  8.     paziente registro[MAX]={0};
  9.     int temp;
  10.     int cursore=0;//primo elemento libero dell'array
  11.     data date_temp;
  12.     while(1)
  13.     {
  14.         printf("1.Inserire nuovi dati\n"); 
  15.         printf("2.Ricerca per data di ricovero\n");
  16.         scanf("%d", &temp);
  17.         switch(temp)
  18.         {
  19.  
  20.             case 1: insert(registro, &cursore);
  21.                 break;
  22.             case 2: printf("Inserire la data di ricovero (GG/MM/AAAA)\n");
  23.                 scanf("%d/%d/%d", &date_temp.giorno, &date_temp.mese, &date_temp.anno);
  24.                 temp=search(date_temp,registro, &cursore);
  25.                 if (temp!=-1)
  26.                     printf("Nome: %c\nData di nascita: %d/%d/%d\nGenere: %c\nDisturbo: %c",registro[temp].nome, registro[temp].nascita.giorno, registro[temp].nascita.mese, registro[temp].nascita.anno, registro[temp].genere, registro[temp].malattia);
  27.                 else printf("Non รจ stata trovata nessuna corrispondenza\n");
  28.                 break;
  29.             default: return 0; 
  30.                 break;
  31.  
  32.         }
  33.     }
  34.  
  35.     return 0;
  36. }
  37. //end_main.c
  38. //logic.c
  39. #include <stdio.h>
  40. #include "logic.h"
  41.  
  42.  
  43. void insert(paziente *registro, int* cursore)
  44. {
  45.     printf("Inserire il nome del paziente:\n");
  46.     scanf(" %c", &registro[*cursore].nome);
  47.     printf("Inserire la data di nascita GG/MM/AAAA:\n");
  48.     scanf(" %d/%d/%d", &registro[*cursore].nascita.giorno,&registro[*cursore].nascita.mese,&registro[*cursore].nascita.anno);
  49.     printf("Inserire il genere (M/F):\n");
  50.     scanf(" %c", &registro[*cursore].genere);
  51.     printf("Inserire la data di ricovero:\n");
  52.     scanf(" %d/%d/%d", &registro[*cursore].ricovero.giorno,&registro[*cursore].ricovero.mese,&registro[*cursore].ricovero.anno);
  53.     printf("Inserire il disturbo del paziente:\n");
  54.     scanf(" %c", &registro[*cursore].malattia);
  55.     *cursore++;
  56.     printf("Inserimento completato.\n");
  57. }
  58.  
  59. int search(data date_temp, paziente *registro, int *cursore)
  60. {
  61.     paziente res;
  62.     int i=0;
  63.     int found=1;
  64.     while((i<*cursore) && (found!=0))
  65.     {
  66.         if ((registro[i].ricovero.giorno==date_temp.giorno) && (registro[i].ricovero.mese==date_temp.mese) && (registro[i].ricovero.anno==date_temp.anno))
  67.         {
  68.             found=0;
  69.             break;
  70.         }
  71.         i++;
  72.     }
  73.     if (found==0) return i;
  74.     else return -1;
  75.  
  76. }
  77. //end_logic.c
  78. //logic.h
  79. #ifndef LOGIC_H
  80. #define LOGIC_H
  81.  
  82.  
  83. typedef struct tipo_data
  84. {
  85.     unsigned int giorno;
  86.     unsigned int mese;
  87.     unsigned int anno;
  88. } data;
  89.  
  90. typedef struct informazioni
  91. {
  92.     char nome;
  93.     data nascita;
  94.     char genere;
  95.     data ricovero;
  96.     char malattia;
  97.  
  98. } paziente;
  99.  
  100. void insert(paziente *registro, int* cursore);
  101. int search(data date_temp, paziente *registro, int *cursore);
  102.  
  103. #endif
  104. //end_logic.h
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement