PROJECT 3: Array of integers

  • Create an array of integers.
  • Display the values of each element.
  • Display the sum total and mean average -- IF available.

    Write a function to add up all of the numbers in an array and return the total:
      float sum( int[] a, int m ) {
      	float result=0;
    		// +++ ADD YOUR CODE HERE ++++//
      	return result;
      } 
    The following functions are called
    • when the specified key is pressed, OR . . .
    • when the corresponding button is clicked.
    Action Key Button

    reset( int a[], int m )
    // Replace all numbers with random values.
    r RESET

    calc( a[], int m )
    // Calculate total and average.

    Also add some functions to do the following:

    big( int a[], int m )
    // Move biggest number to end of the array.
    // (Swap array elements, to keep all numbers.)

    small( int b[], int m )
    // Move smallest to beginning of array
    // (Swap, to keep all numbers.)

    inc( int d[], int n )
    // Increase each of the numbers by one.

    dec( int a[], int m )
    // Decrease each of the numbers by one.

    dbl( int a[], int m )
    // Double each of the numbers.

    half( int a[], int m )
    // FReduce each by half. NOTE:    Do not use global values in these functions; use the arguments.

    Write code in keyPressed()
    to call each function when a key is pressed, with the first letter of that function.
    
        r	reset()		// Replace with random values.
        a	calc()		// Calculate sum and average.	(*)
    
        b	big()		// Move biggest to end of array.
        s	small()		// Move smallest to beginning.	(*)
        +	inc()		// Increase each by one.	(*)
        -	dec()		// Decrease each by one.	(*)
        d	dbl()		// Double each of the numbers.	(*)
        h	half()		// Reduce each by half.		(*)
    

    BUTTONS
    create buttons with names for each of these,
    and add mousePressed() code to call these functions when button is pressed.