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

just do the second part of the asssignment, please include commentary in c++ Wri

ID: 3684803 • Letter: J

Question

just do the second part of the asssignment, please include commentary

in c++

Write a program that allows an unlimited number of values to be entered and stored in an array allocated in the free store. The program should then output the values, five to a line, followed by the average of the values entered. The initial array size should be five elements. The program should create a new array with five additional elements, when necessary, and copy values from the old array to the new.
Repeat the previous exercise but use pointer notation throughout instead of arrays.

Thanks.

Explanation / Answer

#include<iostream>

#include<iomanip>

using std::cin;

using std::cout;

using std::end1;

using std::setw;

int main()

{

int* pArray = nullptr;

int* resize_pArray = nullptr;

int size = 5;

int counter = 0;

char input = 'y';

pArray = new int[size];

while('y' == input)

{

cout<< "Enter a value: " ;

cin>>pArray[counter];

if(counter == (size - 1))

{

size = (size + 5);

resize_pArray = new int[size];

for(int i = 0; i < size; i++)

resize_pArray[i] = pArray[i];

delete[ ] pArray;
pArray = nullptr;

pArray = new int[size];

pArray = resize_pArray;

counter = (size - 6);

}

++counter;

cout<<"Do you want another value? (y/n) ";

cin>> input;

}

cout<<end1<<"Your values are : " <<end1<< end1;

for(int i = 0 ; i < counter; i++)

{

if(i%5 == 0)

cout << end1;

cout<<setw(5) << *(pArray + i);

}

int total = 0

for(int j = 0; j < counter; j++)

{

total += *(pArray+j);

}

double average = 0.0;

average = (static_cast<double>(total) / static_cast<double>(counter));

cout<<end1<<end1<<"The average of your values is: " << average <<end1<<end1;

delete[ ] pArray;

pArray = nullptr;

pArray = new int[size];

pArray = resize_pArray;

return 0;

}