Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a function definition called add. It takes a 1000 element integer array an

ID: 3837810 • Letter: W

Question

Write a function definition called add. It takes a 1000 element integer array and an integer n as its parameters. It adds n to each element of the array. add does not return a value. Your function must use only pointers. You are not allowed to use indexes into the array. a. Consider our array implementation of a queue as discussed in class (see attached code on page 6). What are the values of the private data variables front, rear, and queue_size for the following queue (the whole data array is shown, blank spots in the array are not in the queue): b. What will be the value of rear after enqueueing a new value onto the queue? c. Show the formula used for computing the value of rear. Then show by plugging in numbers how this formula computes your answer to 3b. Formula: Formula with numbers plugged in:

Explanation / Answer

2. Function definition called add. It takes 1000 integer array, and n as its parameters.
It adds n to each element of the array.
add does not return a value.
void add(int* array, int n)
{
    for(int i = 0; i < 1000; i++)
        *(array + i) += n;
}

3a. What are the values of the private data variables front, rear, and queue_size.
front = 2, rear = 5, and queue_size = 6.

3b. What will be the value of rear after enqueuing a new value onto the queue?
rear value will become 0.

3c. Show the formula used for computing the value of rear. Then show by plugging in numbers
how this formula computes your answer to 3b.
rear = (rear + 1) % queue_size;
rear = (5 + 1) % 6 = 6 % 6 = 0.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote