Sale!

COP3223C Small Program 8 Solved

Original price was: $35.00.Current price is: $30.00.

Download Details:

  • Name: smallprogram8-evfxxk.zip
  • Type: zip
  • Size: 150.60 KB

Category:

Description

5/5 - (1 vote)

Problem 1

Write the definition of the user-defined function insert. The function takes three arguments.
The first argument is the reference to a heap of record_t. The function will insert a new record
into the heap. Make sure to take into consideration if malloc doesn’t work! Once the heap is
updated, the reference is returned.

Also, make sure to take into consideration if the array is full!
If it is full, you will display Array is full…Need to doubleIt… to the terminal and
call doubleIt which you will implement in problem 2. The following figure shows the output.
Figure 2: Sample output for problem 1.

Problem 2

Write a user defined function called doubleIt that will double the size of the dynamic array. For
example, if the dynamic array initially holds at max 5 elements, then doubleIt will create a new
dynamic array that holds 10 elements (it will also copy the content from the initial dynamic array).
The user defined function takes two arguments in the call.

The first argument is a pointer to the
heap that contains your initial dynamic array. The second argument is an integer that holds a
primitive integer value representing the size. The function returns a reference to the heap that
contains the new dynamic array.

You cannot use realloc or any built in memory function for
this question. If realloc or any built in memory function is used, then no credit is given for
the question. Note you will need to modify the insert function bit as doubleIt should be
called from insert. Think about when the function would be invoked! Make sure to take into
consideration if malloc doesn’t work!

Problem 3

Write a user defined function called removeRecord that delete a specific content of the dynamic
array. The function takes three arguments. The first argument is the reference to the dynamic
array, the second argument represents the current size of the array (meaning valid entries it
holds), and the last argument is the index of the value to be remove.

Make sure to consider
the scenario if the index is out of bounds. The function returns a primitive value that represents
the new current size of the dynamic array. Otherwise display the message Invalid Index
and return the current size if the remove cannot happen due to invalid index. Hint: Use the shift
technique for removing.
Small Program 8 Page 11

Problem 4

Write a user defined function called freeRecords. The function takes two arguments. The
first argument is the reference to the dynamic array and the second is the current size of the
array. The function gives back memory from the heap. Nothing is returned from the function.
Small Program 8 Page 12