197k views
4 votes
Can you explain arrays in c++ using examples, can you explain what size is as well, and then can you explain how to code these examples? Using function fRandomBetween, assign 10 random numbers between 50 and 100 to scores[] array. Print the array. Find the maximum number stored in the scores[] array from above. Use fMaxArray defined previously Continue with the previous example. Create a new function fMinArray to find the MIN of an array?

User Antonis S
by
7.6k points

1 Answer

4 votes

Final answer:

An array in C++ allows you to store multiple values of the same data type in a sequential manner. The size of an array is determined by the number of elements it can hold. You can assign random numbers to an array using a function and find the maximum and minimum numbers in the array using other functions.

Step-by-step explanation:

An array in C++ is a data structure that allows you to store multiple values of the same data type in a sequential manner. It provides a way to access and manipulate a collection of data as a single entity. In C++, the size of an array is determined by the number of elements it can hold.

Here's an example of how to declare and initialize an array in C++:

int scores[10]; // declares an array named scores that can hold 10 integer values
for (int i = 0; i < 10; i++) {
scores[i] = fRandomBetween(50, 100); // assigns a random number between 50 and 100 to each element of the array
}
for (int i = 0; i < 10; i++) {
cout << scores[i] << " "; // prints each element of the array
}

To find the maximum number stored in the scores[] array, you can use the fMaxArray function that is defined previously. Similarly, you can create a new function called fMinArray to find the minimum number in the array using a similar approach.

User VOX
by
7.5k points