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

COP 2220 (Answer in C, not C++) 1a. Declare a structure whose tag name is Emp an

ID: 3825115 • Letter: C

Question

COP 2220 (Answer in C, not C++)

1a. Declare a structure whose tag name is Emp and that contains these fields (in the following order): adouble field named  d, a character pointer named  str, and an array of eleven integers  named  arr.

In addition, declare a array  named  emp of 30 of these structures. Assign the value 12 to the lastelement of the arr field of the last element of emp. Assign 3.5 to the d field of the first emp element . Assign the string  Hello to the k'th element of emp (assume  k has been declared as an integer variable and assigned a value in the range of the array  elements ).

1b. Write the definition of a function, isReverse, whose first two parameters are arrays of integers ofequal size, and whose third parameter is an integer indicating the size of each array . The function returns true if and only if one array is the reverse of the other. ("Reverse" here means same elements but in reverse order.)

1c. Write the definition of a function reverse, whose first parameter is an array of integers and whose second parameter is the number of elements in the array . The function reverses the elements of thearray . The function does not return a value .

1d.

Reversing the elements of an array involves swapping the corresponding elements of the array : the first with the last, the second with the next to the last, and so on, all the way to the middle of the array .

Given an array  a, an int  variable  n containing the number of elements in a, and two other int variables , k and temp, write a loop that reverses the elements of the array .

Do not use any other variables besides a, n, k, and temp.

1f. You are given an int  variable  k, an int  array  zipcodeList that has been declared and initialized , anint  variable  nZips that contains the number of elements in zipcodeList, and an int  variable duplicates.

Write some code that assigns 1 to duplicates if there are two adjacent elements in the array that have the same value , and that assigns 0 to duplicates otherwise. Use only k, zipcodeList, nZips, andduplicates.

Explanation / Answer

Hi, I have answered first 3 Questions.

Please repost others in separate post.

Please let me know in case of any issue in first 3.


1a.)

struct Emp{
   double d;
   char *str;
   int arr[11];
};

//declare a array named emp of 30 of these structures
struct Emp emp[30];

//Assign the value 12 to the lastelement of the arr field of the last element of emp
emp[29].arr[10] = 12;

//Assign 3.5 to the d field of the first emp element
emp[0].d = 3.5;

//Assign the string Hello to the k'th element of emp
   emp[k-1].str = "Hello";

1b. Write the definition of a function, isReverse, whose first two parameters are arrays of integers ofequal size, and whose third parameter is an integer indicating the size of each array . The function returns true if and only if one array is the reverse of the other. ("Reverse" here means same elements but in reverse order.)

bool isReverse(int arr[], int reverse[], int n){
  
   for(int i=0; i<n; i++){

       if(arr[i] != reverse[n-1-i])
           return false;
   }

   return true;
}

1c. Write the definition of a function reverse, whose first parameter is an array of integers and whose second parameter is the number of elements in the array . The function reverses the elements of thearray . The function does not return a value .

void reverse(int arr[], int n){
  
   int i = 0, j = n-1;
   while(i < j){
       int temp = arr[i];
       arr[i] = arr[j];
       arr[j] = temp;

       i++;
       j--;
   }
}