Question: Task: Dynamic memory management (8 points) In this activity you will write a program to dynamically manage a hamster cage. a) A hamster can be

Task: Dynamic memory management (8 points) In this activity you will write a program to dynamically manage a hamster cage. a) A hamster can be represented by a data structure. It is well known that hamsters have the following properties: Name (char-Array1) Age (floating point number) Fluffiness factor (integer) Music taste (enumeration type: rock, classical, metal, rap) Define a structure for a hamster. (0.5 points) In the enclosed code you will find, among other things, the structure of a hamster cage (dynamic Array with hamsters and number of hamsters) as well as all required method heads. A hamster cage now dynamically manages data structures of hamsters. Add the following functionalities: b) Dynamic addition of hamsters to the cage. The reserved memory for the cage (array) adapts according to the added hamster. (1 point) c) Dynamic removal / deletion of a hamster from the cage. If there is no hamster with the handed over index, the program reacts with an error message. The reserved memory for the array adapts to the hamster that may be removed. (1 point) The Federal Statistical Office asked for your help. Useful statistical information about your hamster population (hamster array) is required. d) The function removeUnfluffyHamsters removes all hamsters from the cage that have a fluffiness value of less than 5. Remember to reallocate the hamster array's memory. (1 point) e) The function mostFluffyHamster returns a structure of the hamster with the greatest fluffiness factor in the cage (array) of all hamsters. (0.5 points) 1 The size of the char array may be static.

f) The function potentialMetalbandMembers shows all hamsters on the screen formatted and human readable, whose musical taste corresponds to the metal music genre and whose age is greater than 2.0 years. (1.5 point) g) The function write HamstersToFiles saves all hamsters of the cage in a file hamsters.txt. If the file does not exist, it will be created. If the file already exists, all hamsters present in the file will be removed. One hamster is deposited per line. The file format is as follows: (1.5 points) h) Demonstrate and test all functions extensively in a main program. (1 point) Pads: The enclosed main.c file must be used as a template. The existing method heads of the Template can be used. You can add further auxiliary functions.

Task: Dynamic memory management (8 points) In this activity you will write

#include typedef enum { ROCK, CLASSIC, METAL, RAP } MUSICTASTE; typedef struct { // TODO: a) } Hamster; typedef struct { Hamster* array: size_t count; } HamsterCage; HamsterCage createEmptyHamsterCage() { HamsterCage cage; cage.array = NULL; cage.count = 0; return cage; } void addHamster (HamsterCage* cage, Hamster* hamster) { // TODO: b) } void removeHamster (HamsterCage* cage, unsigned int index) { // TODO: C) } void removeUnfluffyHamsters (HamsterCage* cage) { // TODO: d) } Hamster mostFluffyHamster (HamsterCage* cage) { // TODO: e) } void potentialMetalbandMembers (HamsterCage* cage) { // TODO: f) } void writeHamsters ToFile(HamsterCage* cage, const char* filename) { // TODO: 9) } int main() { // TODO: a), b), c), d), e), f), g) return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!