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

Functional Requirements: Create a program in Object Oriented with C++ that will

ID: 3755981 • Letter: F

Question

Functional Requirements: Create a program in Object Oriented with C++ that will dynamically create new arrays.

Programming Requrements:

In main, create an int array of SIZE 10

1. Call a function that will accept the array and the SIZE, and then dynamically create a new array of the same size. Double the numbers from the original array and then put them into the new array. For example, if the received array was 9, 8, 7, 6, then the new array would be 18, 16, 14, 12. Return a pointer to the new array.

2. Call a display function that will accept the new array and the SIZE and display it.

3. Call a function that will accept the array created in step 1 and SIZE, and then dynamically create a new array that is 3 times as large. Arrange the numbers from the array that was received into the new array so that there are two 0's between each number. For example, if the received array was 18, 16, 14, 12, then the new array would be 18,0,0,16,0,0,14,0,0,12,0,0. Return a pointer to the new array.

4. Call the display function from step 2 and pass it the array created in step 3.

5. Call a function that will accept the array created in step 3. That function will then dynamically create a new array that is the same size. Arrange the numbers from the array that was received into the new array so that they are in numerical order. In the example above, they would be 0,0,0,0,0,0,0,0,12,14,16 ,18. Return a pointer to the new array.

6. Call the display function from step 2 and pass it the array created in step 5.

You cannot just display the dynamically-created arrays in the functions that created them. You MUST display the arrays after the functions have returned their pointer to main.

Make sure code is modular in design, well documented and that the output is professional in appearance. No menu required in this program.

To help us grade, let's initialize the firstArray to 105, 95, 85, 75, 65, 55, 45, 35, 25, 15

Explanation / Answer


Given below is the code for the question.
Please do rate the answer if it was helpful. Thank you


#include <iostream>
using namespace std;
int* doubleNums(int *arr1, int size1); //doubles each element and stores in new array , returns the new array (same size)
void display(int *arr, int size); //displays the array of given size
int* insert2Zeros(int *arr, int size); //creates a new array (size tripled)with 2 zeros in between every 2 numbers, returns new array
int* arrangeAscending(int *arr, int size); //creats a new array (same size), with the numbers in ascending order
int main(){
const int size1 = 10;
int size2, size3,size4;
int arr1[size1] = {105, 95, 85, 75, 65, 55, 45, 35, 25, 15};
int *arr2, *arr3, *arr4;
cout << "Orignal array: " << endl;
display(arr1, size1);
arr2 = doubleNums(arr1, size1);
size2 = size1;
cout << "The numbers after doubling are: " << endl;
display(arr2, size2);
arr3 = insert2Zeros(arr2, size2);
size3 = 3 * size2;
cout << "The numbers after inserting 2 zeros between the numbers are: "<<endl;
display(arr3, size3);
arr4 = arrangeAscending(arr3, size3);
size4 = size3;
cout << "The numbers after arranging in ascending order are:" << endl;
display(arr4, size4);
}
int* doubleNums(int *arr1, int size1) //doubles each element and stores in new array , returns the new array (same size)
{
int* arr2 = new int[size1];
for(int i = 0; i < size1; i++)
arr2[i] = 2 * arr1[i];
return arr2;
}
void display(int *arr, int size) //displays the array of given size
{
for(int i = 0; i < size; i++)
cout << arr[i] << " ";
cout << endl << endl;
}
int* insert2Zeros(int *arr, int size) //creates a new array (size tripled)with 2 zeros in between every 2 numbers, returns new array
{
int *arr2 = new int[3 * size];
for(int i =0, j = 0; i < size; i++, j+= 3){
arr2[j] = arr[i];
arr2[j+1] = 0;
arr2[j+2] = 0;
}
return arr2;
}
int* arrangeAscending(int *arr, int size) //creats a new array (same size), with the numbers in ascending order
{
int *arr2 = new int[size];
for(int i = 0; i < size; i++){
int current = arr[i];
int index = 0;
//find a place in the sorted array where to insert the ith elment from input array
for(int j = 0; j < i; j++){
if(current < arr2[j]){
index = j;
break;
}
}
//move all others to make place for new elements
for(int j = i - 1; j >= index; j--)
arr2[j+1] = arr2[j];
arr2[index] = current;
}
return arr2;
}

output
-------
Orignal array:
105 95 85 75 65 55 45 35 25 15
The numbers after doubling are:
210 190 170 150 130 110 90 70 50 30
The numbers after inserting 2 zeros between the numbers are:
210 0 0 190 0 0 170 0 0 150 0 0 130 0 0 110 0 0 90 0 0 70 0 0 50 0 0 30 0 0
The numbers after arranging in ascending order are:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 30 50 70 90 110 130 150 170 190 210