Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Crea un programa per realitzar la gestió dels socis
- * d'un club. L'estructura del soci té id_soci, nom i
- * edat.
- El programa tindrà les següents funcions:
- • Alta soci
- • Consulta un soci
- • Consulta massiva (Mostra tots els socis)
- • Esborra soci
- • Ordenar per número
- • Ordenar per inicial del nom
- • Ordenar per edat
- • Eliminar tots els socis
- • Sortir
- Soci serà un vector de 40 posicions.
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define MAX 40
- typedef struct {
- int id_soci;
- char nom[50];
- int edat;
- } Soci;
- void inicialitzar_club(Soci socis[]) {
- int i;
- for(i=0; i<MAX; i++) {
- socis[i].id_soci = 0;
- }
- }
- int id_buit(Soci socis[]) {
- int i;
- for(i=0; i<MAX; i++) {
- if(socis[i].id_soci == 0) {
- return i;
- }
- }
- return -1;
- }
- void alta_soci(Soci socis[]) {
- int nou_id = id_buit(socis);
- if(nou_id != -1) {
- socis[nou_id].id_soci = nou_id;
- setbuf(stdin, NULL);
- printf("Introdueix el nom del soci: ");
- gets(socis[nou_id].nom);
- setbuf(stdin, NULL);
- printf("Introdueix l'edat del soci: ");
- scanf("%d", &socis[nou_id].edat);
- } else {
- printf("El club esta ple :( \n");
- }
- }
- int main() {
- Soci socis[MAX];
- inicialitzar_club(socis);
- int opcio;
- do {
- printf("MENU CLUB\n");
- printf("---------\n");
- printf("1. Alta soci\n");
- printf("2. Consulta un soci\n");
- printf("3. Mostra tots els socis\n");
- printf("4. Esborra soci\n");
- printf("5. Ordenar per numero de soci\n");
- printf("6. Ordenar per inicial del nom\n");
- printf("7. Ordenar per edat\n");
- printf("8. Eliminar tots els socis\n");
- printf("9. Sortir\n\n");
- printf("Introdueix la teva opcio: ");
- scanf("%d", &opcio);
- switch(opcio) {
- case 1: alta_soci(socis);
- break;
- case 2: //consulta_soci(socis);
- break;
- case 3: //mostrar_socis(socis);
- break;
- case 4: //esborrar_soci(socis);
- break;
- case 5: //ordenar_numero(socis);
- break;
- case 6: //ordenar_inicial(socis);
- break;
- case 7: //ordenar_edat(socis);
- break;
- case 8: //eliminar_tots(socis);
- break;
- }
- } while(opcio>0 && opcio<9);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement