Hello, so I needing some help with creating a program for my class. The lab requires us to use pointers.
This is the description of what we have to do...
-Write a function that accepts an int array and the array’s size as arguments.
-The program should ask the size of the array and lets the users enter some integer values.
-The function should create a new array that is one element larger than the argument array.
-The first element of the array should be set to 0.
-Element 0 of the argument array should be copied to element 1 of the new array.
-Element 1 of the argument array should be copied to element 2 of the new array, etc.
-The function should return a pointer to the new array.
-There should be three other functions: getMode, getMedian and getAverage. 8.1.These functions should get Mode, Median and Average of the values within an array.
-You should display the argument array and the new array as well as the mode, median and the average.
This is what I have so far I'm not sure if its right. Any help is greatly appreciated.
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <string>
int* addToSize (int*, int, int);
using namespace std;
int main()
{
int userSize=0;
int userInts;
int *memory; //dynamically allocate an array
//int *intptr;
//int *arrayNew;
//int newA;
cout << "Please enter the array size!" << endl;
cin >> userSize;
memory = new int [userSize];
for (int count = 0; count < userSize; count ++)
{
cout << "Please enter the value for " << count+1 << endl;
cin >> userInts;
}
for (int index = 0; index < userSize; index ++)
{
cin >> memory[index];
}
memory = addToSize(memory, userSize);
for(int index=0;index< (userSize + 1);index++)
cout<<memory[index]<<endl;
delete[] memory; //Used to delete memory
memory = 0;
return 0;
}
int* addToSize(int* arrayNew, int newSize, int userSize)
{
int* expandSize= new int [userSize +1];
for (int index = 0; index < newSize; index++)
{
expandSize[index]= arrayNew[index];
}
for (int index = newSize; index < (newSize+1); index ++)
{
expandSize[index]=0;
}
return expandSize;
}