help :(

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
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <iostream>
#include <cstdlib>

using namespace std;

// parameters: pointer to an array, size of an array
void initialize(int *arr, const int 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(const int *arr, const int N, const int 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(const int *arr1, const int N1, const int *arr2, const int N2)
{
	if(N1 != N2)   // sizes are not equal => arrays are not equal
	{
		return false;
	}
	
	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 
		{
			return false;
		}
	}

	return true;
}


int main()
{
	srand(time(NULL));  // initialization of random number generator 	
	
	const int 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;
}
Last edited on
@Rich1

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.
closed account (NUj6URfi)
SlothFan wrote:
@Rich1

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.


+1
Topic archived. No new replies allowed.