Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.00 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.  
  71.  consulta_soci(Soci socis[]){
  72.      int numero;
  73.  
  74.      printf("Escriu el numero de soci: " );
  75.      scanf("%d",&numero);
  76.      system("clear");
  77.       printf("------------Dades del Soci--------------\n" );
  78.      printf("Numero de soci: %d\n",socis[numero].id_soci);
  79.      printf("Nom: ");
  80.      puts(socis[numero].nom);
  81.      printf("Edat: %d",socis[numero].edat );
  82.      printf("\n---------------------------------------\n" );
  83.      printf("\n");
  84.      printf("\n");
  85.  
  86.  }
  87. int main() {
  88.     Soci socis[MAX];
  89.     inicialitzar_club(socis);
  90.  
  91.     int opcio;
  92.  
  93.     do {
  94.         printf("MENU CLUB\n");
  95.         printf("---------\n");
  96.         printf("1. Alta soci\n");
  97.         printf("2. Consulta un soci\n");
  98.         printf("3. Mostra tots els socis\n");
  99.         printf("4. Esborra soci\n");
  100.         printf("5. Ordenar per numero de soci\n");
  101.         printf("6. Ordenar per inicial del nom\n");
  102.         printf("7. Ordenar per edat\n");
  103.         printf("8. Eliminar tots els socis\n");
  104.         printf("9. Sortir\n\n");
  105.         printf("Introdueix la teva opcio: ");
  106.         scanf("%d", &opcio);
  107.  
  108.         switch(opcio) {
  109.             case 1: alta_soci(socis);
  110.                 break;
  111.             case 2: consulta_soci(socis);
  112.                 break;
  113.             case 3: //mostrar_socis(socis);
  114.                 break;
  115.             case 4: //esborrar_soci(socis);
  116.                 break;
  117.             case 5: //ordenar_numero(socis);
  118.                 break;
  119.             case 6: //ordenar_inicial(socis);
  120.                 break;
  121.             case 7: //ordenar_edat(socis);
  122.                 break;
  123.             case 8: //eliminar_tots(socis);
  124.                 break;
  125.         }
  126.     } while(opcio>0 && opcio<9);
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement