Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.62 KB | None | 0 0
  1. /* Crea un programa per realitzar la gestió dels socis
  2.  * d'un club. L'estructura del soci té id_soci, nom i
  3.  * edat.
  4. El programa tindrà les següents funcions:
  5.     • Alta soci
  6.     • Consulta un soci
  7.     • Consulta massiva (Mostra tots els socis)
  8.     • Esborra soci
  9.     • Ordenar per número
  10.     • Ordenar per inicial del nom
  11.     • Ordenar per edat
  12.     • Eliminar tots els socis
  13.     • Sortir
  14. Soci serà un vector de 40 posicions.
  15.  */
  16.  
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <string.h>
  20.  
  21. #define MAX 40
  22.  
  23. typedef struct {
  24.     int id_soci;
  25.     char nom[50];
  26.     int edat;
  27. } Soci;
  28.  
  29. void inicialitzar_club(Soci socis[]) {
  30.     int i;
  31.    
  32.     for(i=0; i<MAX; i++) {
  33.         socis[i].id_soci = 0;
  34.     }
  35. }
  36.  
  37.  
  38. int id_buit(Soci socis[]) {
  39.     int i;
  40.    
  41.     for(i=0; i<MAX; i++) {
  42.         if(socis[i].id_soci == 0) {
  43.             return i;
  44.         }
  45.     }
  46.    
  47.     return -1;
  48. }
  49.  
  50. void alta_soci(Soci socis[]) {
  51.     int nou_id = id_buit(socis);
  52.    
  53.     if(nou_id != -1) {
  54.         socis[nou_id].id_soci = nou_id;
  55.  
  56.         setbuf(stdin, NULL);
  57.         printf("Introdueix el nom del soci: ");
  58.         gets(socis[nou_id].nom);
  59.        
  60.         setbuf(stdin, NULL);
  61.         printf("Introdueix l'edat del soci: ");
  62.         scanf("%d", &socis[nou_id].edat);
  63.        
  64.     } else {
  65.         printf("El club esta ple :( \n");
  66.     }
  67.    
  68. }
  69.  
  70. int main() {
  71.     Soci socis[MAX];
  72.     inicialitzar_club(socis);
  73.  
  74.     int opcio;
  75.    
  76.     do {
  77.         printf("MENU CLUB\n");
  78.         printf("---------\n");
  79.         printf("1. Alta soci\n");
  80.         printf("2. Consulta un soci\n");
  81.         printf("3. Mostra tots els socis\n");
  82.         printf("4. Esborra soci\n");
  83.         printf("5. Ordenar per numero de soci\n");
  84.         printf("6. Ordenar per inicial del nom\n");
  85.         printf("7. Ordenar per edat\n");
  86.         printf("8. Eliminar tots els socis\n");
  87.         printf("9. Sortir\n\n");
  88.         printf("Introdueix la teva opcio: ");
  89.         scanf("%d", &opcio);
  90.        
  91.         switch(opcio) {
  92.             case 1: alta_soci(socis);
  93.                 break;
  94.             case 2: //consulta_soci(socis);
  95.                 break;
  96.             case 3: //mostrar_socis(socis);
  97.                 break;
  98.             case 4: //esborrar_soci(socis);
  99.                 break;
  100.             case 5: //ordenar_numero(socis);
  101.                 break;
  102.             case 6: //ordenar_inicial(socis);
  103.                 break;
  104.             case 7: //ordenar_edat(socis);
  105.                 break;
  106.             case 8: //eliminar_tots(socis);
  107.                 break;
  108.         }
  109.     } while(opcio>0 && opcio<9);
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement