Review Session 4

Note:  Saturday's Review Session is NOT cancelled

Recording

Example

Arrays


Practice Exercise 4

Email only the source code for each practice exercise as an email attachment.  There is no due date.  Use "Practice Exercise 4" as the email subject.   Add (a) comment(s) at the top of your program with your name, practice exercise 4, your compiler and operating system.

Complete the following program.  You will need to write 3 functions:

  1. populate assigns a random number between 1 and 100 to each element of the array
  2. print prints each element of the array in a left justified field of width 3
  3. indexOfMaxValue returns the index of the maximum element in the array.
const int ArraySize = 20;

int main()
{
    int a[ArraySize];
    populate(a);
    print(a);
    cout << "The maximum value is " << a[indexOfMaxValue(a)];
}

The output should look something like this:

42 68 35 1  70 25 79 59 63 65 6  46 82 28 62 92 96 43 28 37
The maximum value is 96