can someone help me with thses qs :( tomorrow is my final lab :(
A function initialize(…) of type void that takes as parameter a one dimensional array of size n, randomly generates n elements (in the range -3 to 7) and stores them in the array.
A function count(…) of type integer that takes as parameters a one dimensional array of size n, and an integer value V. This function then computes and returns the number of times this value V was found in the array and their sum.
A function isSame(…) of type bool that takes as parameters two arrays and returns true if the two arrays are the same otherwise returns false
#include <iostream>
#include <cstdlib>
usingnamespace std;
// parameters: pointer to an array, size of an array
void initialize(int *arr, constint N)
{
for(int i = 0; i < N; i++)
{
*(arr + i) = rand() % 11 - 3;
}
}
// parameters: pointer to an array, size of an array, value we're looking for
int count(constint *arr, constint N, constint V)
{
int number = 0; // how many equal values we've found
for(int i = 0; i < N; i++)
{
if(arr[i] == V)
{
number++;
}
}
return number;
}
bool isSame(constint *arr1, constint N1, constint *arr2, constint N2)
{
if(N1 != N2) // sizes are not equal => arrays are not equal
{
returnfalse;
}
for(int i = 0; i < N1; i++) // N1 can be replaced with N2
{
if(arr1[i] != arr2[i]) // if one non-equal element is found, arrays are not equal
{
returnfalse;
}
}
returntrue;
}
int main()
{
srand(time(NULL)); // initialization of random number generator
constint size = 10;
int arr[size];
initialize(arr, size);
for(int i = 0; i < size; i++)
{
cout << (*(arr + i)) << ' ';
}
cout << count(arr, size, 5) << endl;
return 0;
}
This isn't going to teach OP anything at all. He'll most likely copy and paste this code and hand in the assignment, understanding none of it, then be faced with even more confusion when he is given his next assignment. It's good practice to at least make the poster attempt the problem so that he can learn where he is going wrong.
This isn't going to teach OP anything at all. He'll most likely copy and paste this code and hand in the assignment, understanding none of it, then be faced with even more confusion when he is given his next assignment. It's good practice to at least make the poster attempt the problem so that he can learn where he is going wrong.