// 3/27/2014 // we typed this together in class to practice using functions and arrays #include #include using namespace std; //prototypes int sum2nums(int, int&); void printarray(int[],int); int sumarray(int[], int); bool comparearrays(int[], int[], int); double avgarray(int [], int); int findmax(int[], int); int findmin(int [], int); void findmaxmin(int [], int, int&, int&); void multby2(int [], int); void readdata(int [], int); /* LAB 1 for today: Write a function that accepts an integer array and a size, and returns the sum of all the elements in the array. */ /* time permitting: Write a function called compare that will accept 2 arrays and a size, and will return true or false. true if the 2 arrays are identical and false if any value differs. LAB 2 for today: Write a function that returns the range of values in an array. note: the range is a positive number which equals max-min */ int main() { int num1=10, num2=12; int numelts; const int SIZE=10; int arr[SIZE]; cout << "How many elements do you want to input? "; cin >> numelts; readdata(arr, numelts); cout << "The sum of num1 and num2 is: " << sum2nums(num1,num2) << endl; // passing individual array elements to a function if (numelts>1) cout << "The sum of elt 0 and elt 1 is: " << sum2nums(arr[0],arr[1]) << endl; // function call passing an array -- NO BRACKETS -- just name of array printarray(arr, numelts); cout << "The average of the array is: " << avgarray(arr, numelts) << endl; int m1, m2; findmaxmin(arr, numelts, m1, m2); cout << "min is: " << m2 << " max is: " << m1 << endl; multby2(arr, numelts); cout << "Values after they are multiplied by 2: " << endl; printarray(arr, numelts); return 0; } void printarray(int nums[], int n) { // nums is an integer array, n is the number of elt in nums cout << "In function printarray: "; for (int i=0;imax) max=arr[i]; return max; } int findmin(int arr[], int n) { // finds the minimum value of the array arr and returns the value int min=arr[0]; for (int i=0; i max) max=arr[i]; } return; } void multby2(int arr[], int n) { // multiply every value in the array by 2 // THIS CHANGES THE ACTUAL VALUES IN THE ARRAY IN THE CALLING FUNCTION for (int i=0;i> arr[i]; } } int sum2nums(int x, int &y) { // this function returns the sum of its 2 integer parameters // we use it here to illustrate passing individual array elements as parameters return x+y; }