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

#12 & #13 using C++ tion should create a new array that is twice the size of the

ID: 3865543 • Letter: #

Question

#12 & #13 using C++

tion should create a new array that is twice the size of the argument array. The func- tion should copy the contents of the argument array to the new array and initialize the unused elements of the second array with 0. The function should return a pointer to the new array 4 626 12. Element Shifter rite a function that accepts an int array and the array's size as arguments. The function should create a new array that is one element larger than the argument array The first element of the new array should be set to 0. Element 0 of the argument array should be be copied to element 2 of the new array, and so forth. The funct pointer to the new array copied to element 1 of the new array, element 1 of the argument array should ion should return a 9124 13. Movie Statistics Write a program that can be used to gather statistical data about the number of mov ies college students see in a month. The program should perform the following steps: A) Ask the user how many students were surveyed. An array of integers with this any elements should then be dynamically allocated B) Allow the user to enter the number of movies each student saw into the array. C) Calculate and display the average, median, and mode of the values entered. (Use the functions you wrote in Problems 8 and 9 to calculate the median and mode.) Input Validation: Do not accept negative mumbers for input

Explanation / Answer

12.

#include<iostream>

using namespace std;

int *makelarge( int a[], int size){


    int *b = new int[size+1];
    b[0] = 0;
    for (int i = 0; i<size; i++)
        b[i+1] = a[i];

    return b;   
   
}

int main(){

    int *q;
    int a[] = {1,2,3,4,5,6};
   
    q = makelarge(a,6);
    for (int i = 0; i<7; i++)
        cout << *(q+i) << " ";
    cout << endl;  
    return 0;
}

13.

#include<iostream>

using namespace std;

int main(){

   int n;
   int *stu;
   int sum = 0;
   double avg;
   double median;
   int mode;
   int *freq;
   int count;
   int max;
   int found;

   do {
      cout << "Enter number of students:" << endl;
      cin >> n;
   } while (n < 0);
   stu = new int[n];
   freq = new int[n];

  
   for (int i = 0; i<n; i++){
      do {
         cout << "Enter for student " << i+1 << endl;
         cin >> stu[i];
      } while (stu[i] < 0);
      sum = sum + stu[i];
   }
  
   max = 0;
   for (int i = 0; i<n; i++){
      count = 0;
      found = 0;
      for (int j = 0; j<i; j++){
          if (stu[j] == stu[i])
             found = 1;
      }
      if (found == 1)
         continue;
      for (int j = 0; j<n; j++){
          if (stu[i] == stu[j])
             count++;
      }
      freq[i] = count;
      if (max < count)
         max = count;
   }

   avg = sum/n;  
   cout << "Average:" << avg << endl;
   if (n%2 == 0)
       cout << "Median:" << (stu[n/2] + stu[n/2+1])/2 << endl;
   else
       cout << "Median:" << stu[n/2] << endl;

   cout << "Mode:";
   for (int i = 0; i<n; i++){
      if (freq[i] == max)
         cout << stu[i] << " ";
   }
   cout << endl;
        
   return 0;
}