Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
7.5 kB
8
Indexable
Never
#include <stdio.h>
#include <string.h>
#include "ex11.h"

//Do not write the types given in the exercise.

// Implement here the procedure "showAnimalsByOwnerName"
void showAnimalsByOwnerName(Animal animalesRecibidos[MAX_CHARS], int n_animals, char owner_name[MAX_CHARS]) {

    int j = 0;
    int hayAnimal = 0;

    for (j = 0; j < n_animals; j++) {

        //strcmp(que, que) -> = 0 si coinciden | != 0 si no coinciden
        if (!strcmp(owner_name, animalesRecibidos[j].owner.full_name)) {

            printf("\nName of animal: %s\n",animalesRecibidos[j].full_name);
            printf("Type of animal: %s\n", animalesRecibidos[j].type.name);
            printf("Animal breed: %s\n", animalesRecibidos[j].type.breed);
            printf("Owner name: %s\n", animalesRecibidos[j].owner.full_name);

            if (animalesRecibidos[j].owner.special_discount == 1) {
                printf("Special discount\n");
            } else {
                printf("No special discount\n");
            }

            if (animalesRecibidos[j].vaccinated == 1) {
                printf("Animal vaccinated\n");
            } else {
                printf("Animal not vaccinated\n");
            }

            hayAnimal++;

        }
    }

    // hayAnimal == 0  <--->  !hayAnimal
    if (!hayAnimal) {
        printf("\nNOT FOUND.\n");
    }

}



// Implement here the procedure "showAnimalsByTypeAndStatus"

void showAnimalsByTypeAndStatus(Animal all_animals[MAX_CHARS], int n_animals, char type[MAX_CHARS], char vaccinated) {

    int j = 0;

    for (j = 0; j < n_animals; j++) {

        if (strcmp(type, all_animals[j].type.name) == 0) {
            //mostrar solo gatos o perros

            if (vaccinated == 'Y' && all_animals[j].vaccinated == 1) {
                //muestro vacunados

                printf("\nName of animal: %s\n",all_animals[j].full_name);
                printf("Type of animal: %s\n", all_animals[j].type.name);
                printf("Animal breed: %s\n", all_animals[j].type.breed);
                printf("Owner name: %s\n", all_animals[j].owner.full_name);

                if (all_animals[j].owner.special_discount == 1) {
                    printf("Special discount\n");
                } else {
                    printf("No special discount\n");
                }

                printf("Animal vaccinated\n");

            } else {
                if(vaccinated == 'N' && all_animals[j].vaccinated == 0) {
                    //muestro no vacunados

                    printf("\nName of animal: %s\n",all_animals[j].full_name);
                    printf("Type of animal: %s\n", all_animals[j].type.name);
                    printf("Animal breed: %s\n", all_animals[j].type.breed);
                    printf("Owner name: %s\n", all_animals[j].owner.full_name);

                    if (all_animals[j].owner.special_discount == 1) {
                        printf("Special discount\n");
                    } else {
                        printf("No special discount\n");
                    }

                    printf("Animal not vaccinated\n");

                } else {
                    if (vaccinated == 'A') {
                        //muestro todos

                        printf("\nName of animal: %s\n",all_animals[j].full_name);
                        printf("Type of animal: %s\n", all_animals[j].type.name);
                        printf("Animal breed: %s\n", all_animals[j].type.breed);
                        printf("Owner name: %s\n", all_animals[j].owner.full_name);

                        if (all_animals[j].owner.special_discount == 1) {
                            printf("Special discount\n");
                        } else {
                            printf("No special discount\n");
                        }

                        if (all_animals[j].vaccinated == 1) {
                            printf("Animal vaccinated\n");
                        } else {
                            printf("Animal not vaccinated\n");
                        }
                    }
                }
            }

        } else {
            if (strcmp(type, "All") == 0) {
                //mostrar todos

                if (vaccinated == 'Y' && all_animals[j].vaccinated == 1) {
                    //muestro vacunados

                    printf("\nName of animal: %s\n",all_animals[j].full_name);
                    printf("Type of animal: %s\n", all_animals[j].type.name);
                    printf("Animal breed: %s\n", all_animals[j].type.breed);
                    printf("Owner name: %s\n", all_animals[j].owner.full_name);

                    if (all_animals[j].owner.special_discount == 1) {
                        printf("Special discount\n");
                    } else {
                        printf("No special discount\n");
                    }

                    printf("Animal vaccinated\n");


                } else {
                    if(vaccinated == 'N' && all_animals[j].vaccinated == 0) {
                        //muestro no vacunados

                        printf("\nName of animal: %s\n",all_animals[j].full_name);
                        printf("Type of animal: %s\n", all_animals[j].type.name);
                        printf("Animal breed: %s\n", all_animals[j].type.breed);
                        printf("Owner name: %s\n", all_animals[j].owner.full_name);

                        if (all_animals[j].owner.special_discount == 1) {
                            printf("Special discount\n");
                        } else {
                            printf("No special discount\n");
                        }

                        printf("Animal not vaccinated\n");


                    } else {
                        if(vaccinated == 'A') {
                            //muestro todos

                            printf("\nName of animal: %s\n",all_animals[j].full_name);
                            printf("Type of animal: %s\n", all_animals[j].type.name);
                            printf("Animal breed: %s\n", all_animals[j].type.breed);
                            printf("Owner name: %s\n", all_animals[j].owner.full_name);

                            if (all_animals[j].owner.special_discount == 1) {
                                printf("Special discount\n");
                            } else {
                                printf("No special discount\n");
                            }

                            if (all_animals[j].vaccinated == 1) {
                                printf("Animal vaccinated\n");
                            } else {
                                printf("Animal not vaccinated\n");
                            }

                        }
                    }
                }
            }
        }
    }
}

int main() {
   Animal all_animals[MAX_CHARS];
   int n_animals = 0;
   char owner_name[MAX_CHARS], type[MAX_CHARS], vaccinated,aux;

   n_animals = loadAnimalsInfo (all_animals);

   printf ("Enter owner name: ");
   fgets (owner_name, 100, stdin);
   owner_name[strlen(owner_name) - 1] = '\0';
   showAnimalsByOwnerName(all_animals, n_animals, owner_name);

   printf ("\nWant to show dogs (Dog) cats (Cat) or both (All)? : ");
   scanf ("%s", type);
   scanf("%c", &aux);
   printf ("\nShow vaccinated (Y), not vaccinated (N) or all (A)? : ");
   scanf ("%c", &vaccinated);
   showAnimalsByTypeAndStatus(all_animals, n_animals, type, vaccinated);

   return 0;
}