Untitled

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

#define MAX_CHARS 100
#define MAX_REGISTERS 25

typedef struct {   
   char full_name[MAX_CHARS];
   int special_discount;
} Owner;

typedef struct {   
   char tipoAnimal[MAX_CHARS];
   char breed[MAX_CHARS];
} AnimalType;

typedef struct {   
   char full_name[MAX_CHARS];
   Owner owner;
   AnimalType type;
   int vaccinated;  // 0-not vaccinated  1-vaccinated
} Animal;

typedef int entero;

 

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

 

// Implement here the procedure "showAnimalsByOwnerName"

void showAnimalsByOwnerName(Animal animales[MAX_CHARS], int numeroAnimales, char ownerName[MAX_CHARS]) {

    int i = 0;
    int count = 0;

    for(i = 0; i < numeroAnimales; i++) {

        if(strcmp(animales[i].owner.full_name, ownerName) == 0) {
            printf("Name of animal: %s\n", animales[i].full_name);
            printf("Type of animal: %s\n", animales[i].type.tipoAnimal);
            printf("Animal breed: %s\n", animales[i].type.breed);
            printf("Owner name: %s\n", animales[i].owner.full_name);
            if(animales[i].owner.special_discount) {
                printf("Special discount\n");
            }else {
                printf("No special discount\n");
            }
            if(animales[i].vaccinated) {
                printf("Animal vaccinated\n");
            }else {
                printf("Animal not vaccinated\n");
            }
            count++;
        }

    }

    if(count == 0) {
        printf("NOT FOUND.\n");
    }


}

 

// Implement here the procedure "showAnimalsByTypeAndStatus"

void showAnimalsByTypeAndStatus(Animal animales[MAX_CHARS], int numeroAnimales, char type[MAX_CHARS], char vaccinated) {

    int i = 0;
    char opt = type[0];


    switch (opt)
    {
    case 'A':

        for(i = 0; i < numeroAnimales; i++) {

            printf("\n");

            if(vaccinated == 'Y' && animales[i].vaccinated) {

                printf("Name of animal: %s\n", animales[i].full_name);
                printf("Type of animal: %s\n", animales[i].type.tipoAnimal);
                printf("Animal breed: %s\n", animales[i].type.breed);
                printf("Owner name: %s\n", animales[i].owner.full_name);
                if(animales[i].owner.special_discount) {
                    printf("Special discount\n");
                } else {
                    printf("No special discount\n");
                }
                printf("Animal vaccinated\n");

            } else if( vaccinated == 'N' && !animales[i].vaccinated) {

                printf("Name of animal: %s\n", animales[i].full_name);
                printf("Type of animal: %s\n", animales[i].type.tipoAnimal);
                printf("Animal breed: %s\n", animales[i].type.breed);
                printf("Owner name: %s\n", animales[i].owner.full_name);
                if(animales[i].owner.special_discount) {
                    printf("Special discount\n");
                } else {
                    printf("No special discount\n");
                }
                printf("Animal not vaccinated\n");

            } else if(vaccinated == 'A') {

                printf("Name of animal: %s\n", animales[i].full_name);
                printf("Type of animal: %s\n", animales[i].type.tipoAnimal);
                printf("Animal breed: %s\n", animales[i].type.breed);
                printf("Owner name: %s\n", animales[i].owner.full_name);
                if(animales[i].owner.special_discount) {
                    printf("Special discount\n");
                } else {
                    printf("No special discount\n");
                }
                if(animales[i].vaccinated) {
                    printf("Animal vaccinated\n");
                } else {
                    printf("Animal not vaccinated\n");
                }


            }


        }

        break;

    case 'D':


        for (i = 0; i<numeroAnimales; i++) {

            printf("\n");

            if ((vaccinated == 'Y' && animales[i].vaccinated) && !strcmp(animales[i].type.tipoAnimal, "Dog")) {

                printf("Name of animal: %s\n", animales[i].full_name);
                printf("Type of animal: %s\n", animales[i].type.tipoAnimal);
                printf("Animal breed: %s\n", animales[i].type.breed);
                printf("Owner name: %s\n", animales[i].owner.full_name);
                if(animales[i].owner.special_discount) {
                    printf("Special discount\n");
                } else {
                    printf("No special discount\n");
                }
                printf("Animal vaccinated\n");

            } else if (( vaccinated == 'N' && !animales[i].vaccinated) && !strcmp(animales[i].type.tipoAnimal, "Dog")) {

                printf("Name of animal: %s\n", animales[i].full_name);
                printf("Type of animal: %s\n", animales[i].type.tipoAnimal);
                printf("Animal breed: %s\n", animales[i].type.breed);
                printf("Owner name: %s\n", animales[i].owner.full_name);
                if(animales[i].owner.special_discount) {
                    printf("Special discount\n");
                } else {
                    printf("No special discount\n");
                }
                printf("Animal not vaccinated\n");

            } else if(vaccinated == 'A' && !strcmp(animales[i].type.tipoAnimal, "Dog")) {

                printf("Name of animal: %s\n", animales[i].full_name);
                printf("Type of animal: %s\n", animales[i].type.tipoAnimal);
                printf("Animal breed: %s\n", animales[i].type.breed);
                printf("Owner name: %s\n", animales[i].owner.full_name);
                if(animales[i].owner.special_discount) {
                    printf("Special discount\n");
                } else {
                    printf("No special discount\n");
                }
                if(animales[i].vaccinated) {
                    printf("Animal vaccinated\n");
                } else {
                    printf("Animal not vaccinated\n");
                }


            }


        }


        break;

    case 'C':

        for (i = 0; i<numeroAnimales; i++) {

            printf("\n");

            if ((vaccinated == 'Y' && animales[i].vaccinated) && !strcmp(animales[i].type.tipoAnimal, "Cat")) {

                printf("Name of animal: %s\n", animales[i].full_name);
                printf("Type of animal: %s\n", animales[i].type.tipoAnimal);
                printf("Animal breed: %s\n", animales[i].type.breed);
                printf("Owner name: %s\n", animales[i].owner.full_name);
                if(animales[i].owner.special_discount) {
                    printf("Special discount\n");
                } else {
                    printf("No special discount\n");
                }
                printf("Animal vaccinated\n");

            } else if (( vaccinated == 'N' && !animales[i].vaccinated) && !strcmp(animales[i].type.tipoAnimal, "Cat")) {

                printf("Name of animal: %s\n", animales[i].full_name);
                printf("Type of animal: %s\n", animales[i].type.tipoAnimal);
                printf("Animal breed: %s\n", animales[i].type.breed);
                printf("Owner name: %s\n", animales[i].owner.full_name);
                if(animales[i].owner.special_discount) {
                    printf("Special discount\n");
                } else {
                    printf("No special discount\n");
                }
                printf("Animal not vaccinated\n");

            } else if(vaccinated == 'A' && !strcmp(animales[i].type.tipoAnimal, "Cat")) {

                printf("Name of animal: %s\n", animales[i].full_name);
                printf("Type of animal: %s\n", animales[i].type.tipoAnimal);
                printf("Animal breed: %s\n", animales[i].type.breed);
                printf("Owner name: %s\n", animales[i].owner.full_name);
                if(animales[i].owner.special_discount) {
                    printf("Special discount\n");
                } else {
                    printf("No special discount\n");
                }
                if(animales[i].vaccinated) {
                    printf("Animal vaccinated\n");
                } else {
                    printf("Animal not vaccinated\n");
                }


            }


        }



        break;
    
    default:
        break;
    }


}

 

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

   /*

   for(int i = 0; i < 4; i++) {

    printf("Nombre animal: ");
    fgets(all_animals[i].full_name, MAX_CHARS, stdin);
    all_animals[i].full_name[strlen(all_animals[i].full_name)-1] = '\0';

    all_animals[i].vaccinated = 1;

    printf("Nombre dueño: ");
    fgets(all_animals[i].owner.full_name, MAX_CHARS, stdin);
    all_animals[i].owner.full_name[strlen(all_animals[i].owner.full_name)-1] = '\0';

    all_animals[i].owner.special_discount = 0;

    printf("Tipo animal: ");
    fgets(all_animals[i].type.tipoAnimal, MAX_CHARS, stdin);
    all_animals[i].type.tipoAnimal[strlen(all_animals[i].type.tipoAnimal)-1] = '\0';

    printf("Raza animal: ");
    fgets(all_animals[i].type.breed, MAX_CHARS, stdin);
    all_animals[i].type.breed[strlen(all_animals[i].type.breed)-1] = '\0';

   }
    

    n_animals = 4;

    */



   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;
}