So i am supposed to be creating a program that will create two sets of arrays. Each array will have a randomly generated amount of numbers between 2-50 that are also randomly generated between 1-100. We then have to sort the array and display that as well. I have some code so far but I know that it does not do the random generation or sorting part. Our professor has cancelled class every day for nearly the last two weeks which was when we were supposed to cover this but he still expects us to turn it in. And the TAs are gone when he is and that is our only source of help. I have what i do based on previous classes and what ive been able to teach myself from googling non stop for hours. We have to use arrays not vector and we must use srand(7). Can anyone help me please get my code to output something similar to the following:
There are 14 values in the first array.
Unsorted Random Numbers
------------------------------------------------------------
53.2 46.4 21.5 47.4 19.9 92.0 36.0 84.6 62.1 14.7
86.7 76.4 54.3 36.8
Sorted Random Numbers
------------------------------------------------------------
14.7 19.9 21.5 36.0 36.8 46.4 47.4 53.2 54.3 62.1
76.4 84.6 86.7 92.0
There are 43 values in the second array.
Unsorted Random Numbers
------------------------------------------------------------
0.2 73.8 48.3 47.3 7.9 28.0 86.8 28.9 68.3 40.3
43.3 58.8 43.2 34.0 71.6 53.3 0.2 6.1 30.4 36.5
16.0 30.8 35.8 95.5 72.4 82.7 52.3 20.5 99.0 22.7
99.9 95.1 64.8 34.2 6.1 52.1 72.9 52.5 81.5 61.4
60.6 76.7 45.4
Sorted Random Numbers
------------------------------------------------------------
0.2 0.2 6.1 6.1 7.9 16.0 20.5 22.7 28.0 28.9
30.4 30.8 34.0 34.2 35.8 36.5 40.3 43.2 43.3 45.4
47.3 48.3 52.1 52.3 52.5 53.3 58.8 60.6 61.4 64.8
68.3 71.6 72.4 72.9 73.8 76.7 81.5 82.7 86.8 95.1
95.5 99.0 99.9
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
|
using namespace std;
double print(int *array);
double produce(int *array);
int main()
{
int array[2];
produce(array);
print(array);
}
double produce(int *array)
{
srand(7);
for(int i=0; i<2; i++)
{
array[i] = (rand()%10)+1;
cout << array[i] << endl;
}
return *array;
}
double print (int *array)
{
for(int i=0; i<2; i++)
{
cout << array[i] << endl;
}
getchar();
return *array;
}
|