Pregunta 2 · Fundamentos de Programación UOC 2018
Tema: Esquemas de recorrido y búsqueda sobre tablas · Del examen Prueba de Síntesis. Enero 2018 (2018)
Enunciado
Pregunta 2 (50% de la nota total). Algoritmos de recorrido y conteo sobre vectores
A fin de almacenar y administrar la colección de todos los animales que acoge una protectora determinada, se ha formalizado la estructura siguiente para albergar como máximo a 1000 ejemplares:
const
MAX_ANIMALS: integer = 1000;
end const
type
tAnimalShelter = record
animals: vector[MAX_ANIMALS] of tAnimal;
numAnimals: integer;
end record
end type
Tomando como base esta estructura, resuelva en lenguaje algorítmico los dos apartados siguientes:
a)
[30%] Diseñe e implemente la función animalCatCounting, la cual recibe una estructura de tipo tAnimalShelter y calcula el número total de gatos con vacunas al día. Es imperativo declarar e implementar también la función auxiliar isVaccinatedCat planteada en el ejercicio anterior y realizar su llamada dentro del bucle.
b)
[20%] Desarrolle la función animalCounting, a la cual se le suministran la estructura tAnimalShelter y un tipo específico de animal (parámetro de clase tAnimalType), devolviendo la cantidad de ejemplares registrados que coinciden con dicho tipo.

Solución
Según los criterios oficiales de corrección
a. [30%] Diseñe e implemente la función animalCatCounting , la cual recibe una estructura de tipo tAnimalShelter y calcula el número total de gatos con vacunas al día. Es imperativo declarar e implementar también la función auxiliar isVaccinatedCat planteada en el ejercicio anterior y realizar su llamada dentro del bucle.
Solución: ```pseudocode function isVaccinatedCat(animal: tAnimal): boolean var found: boolean; end var found := (animal.typeID = cat) and animal.isVaccinated; return found; end function function animalCatCounting(animalsShelter: tAnimalShelter): integer var i: integer; animalsFound: integer; end var animalsFound := 0; for i := 1 to animalsShelter.numAnimals do if isVaccinatedCat(animalsShelter.animals[i]) then animalsFound := animalsFound + 1; end if; end for; return animalsFound; end function ```
b. [20%] Desarrolle la función animalCounting , a la cual se le suministran la estructura tAnimalShelter y un tipo específico de animal (parámetro de clase tAnimalType ), devolviendo la cantidad de ejemplares registrados que coinciden con dicho tipo.
Solución: ```pseudocode function animalCounting(animalsShelter: tAnimalShelter, typeOfAnimal: tAnimalType): integer var i: integer; animalsFound: integer; end var animalsFound := 0; for i := 1 to animalsShelter.numAnimals do if animalsShelter.animals[i].typeID = typeOfAnimal then animalsFound := animalsFound + 1; end if; end for; return animalsFound; end function ```
La explicación paso a paso, hecha con IA, es Premium. Premium
Resuélvelo aquí mismo: corrección automática, pistas y solución paso a paso.
‹ Ejercicio 2.b - Esquemas de recorrido y búsqueda · Juny 2022