Programming C

Tasks studies - laboratory


Project maintained by dawidolko Hosted on GitHub Pages — Theme by dawidolko

Exam 4

Create an object MY_STUDENT, which contains the student’s name (use dynamic memory allocation) and the year of commencement of studies. Place the student support in the files my_student.h and my_student.cpp. The object MY_STUDENT does not know how it will be used, so it should anticipate use in any mode. This means that the deallocator of this object should free all the memory, allocated dynamically.

Create a dynamic array MY_STUDENT_GROUP, each element of which contains a void * pointer for storing data.

Array - CONTAINER MY_STUDENT_GROUP is created with dynamic memory allocation and does not depend on the type of stored data. Place the array support in the files my_array.h and my_array.cpp.

Table - container does not depend on data, so this means that the table deallocator should completely free the memory, dynamically allocated for each object. At the same time, freeing data objects that were added to the table should not damage the data stored in the table, and vice versa. For example, we create an object MY_DATA *ptrdat = CreateData(.....); and add it to the table-container. Now they should have two independent copies of data - in the table element and the ptrdat object. Freeing an array element does not damage ptrdat, and freeing ptrdat does not damage an array element.

The objects MY_STUDENT and MY_STUDENT_GROUP are created dynamically.

In the main function:

1. Create a dynamic table, with the initial size assumed to be 1.

2. Create three MY_STUDENT objects and add them to the dynamic table.

3. Free up memory for three MY_STUDENT objects. This freeing up memory should not damage the data in the CONTAINER.

4. Output data from the CONTAINER to the monitor.

5. Free up memory for the dynamic array. We do not change the order of tasks 1, 2, 3, … . The specification for the task should be strictly followed!