Hi, so I am having some trouble with this program we have to make. This is the description of what we have to do, any help is greatly appreciated. Thank you.
1. Write a function that accepts an int array and the array’s size as arguments.
2. The program should ask the size of the array and lets the users enter some integer values.
3. The function should create a new array that is one element larger than the argument array.
4. The first element of the array should be set to 0.
5. Element 0 of the argument array should be copied to element 1 of the new array.
6. Element 1 of the argument array should be copied to element 2 of the new array, etc.
7. The function should return a pointer to the new array.
8. 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.
9. 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 got step 1 & 2 and I created the addToSize function and I call it but it doesn't do anything...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <string>
int* addToSize (int*, int);
using namespace std;
int main()
{
int userSize;
int userInts;
int userArray[userSize] = {};
int *intptr;
int *arrayNew;
cout << "Please enter the array size!" << endl;
cin >> userSize;
for (int count = 0; count < userSize; count ++)
{
cout << "Please enter the value for " << count+1 << endl;
cin >> userInts;
}
addToSize(arrayNew, userSize);
return 0;
}
int* addToSize(int* arrayNew, int userSize)
{
int* expandSize= new int [userSize +1];
for (int index = 0; index < userSize; index++)
{
expandSize[index]= arrayNew[index];
}
for (int index = userSize; index < (userSize+1); index ++)
{
expandSize[index]=0;
}
return expandSize;
}
|