// pgm40 // 12/12/16 // Sample Final Spring 2016 Part III 25pts #include #include using namespace std; // prototypes void readin(int[], int&); int changeNeg(int[], int, int); void printArr(int[], int); void sortIt(int[], int); // bubble sort void sortIt2(int[], int); // selection sort const int SIZE=50; int main() { int numbs[SIZE], n=0, newval=5, counter=0; readin(numbs, n); cout << "Read in " << n << " data values. " << endl; printArr(numbs, n); counter = changeNeg(numbs, n, newval); cout << "Number of changed values is: " << counter << endl; printArr(numbs, n); sortIt2(numbs, n); cout << "Here is the sorted array: " << endl; printArr(numbs, n); return 0; } // read in accepts 2 parameters, an array, and a reference // to an int -- which is number of values read in. // reads in values from the keyboard until there are no // more. Values go into the array parameter. No more than // SIZE values are read in. // ^Z or ^D are used as EOF symbols. void readin(int vals[], int &lim) { lim=0; cout << "Enter a number, EOF to finish: "; cin>>vals[lim]; while (lim>vals[lim]; } } // add somenum to negative numbers in the array // and return number of changes int changeNeg(int arr[], int n, int somenum) { int cnt=0; for (int i=0; ivals[i]) { // swap temp=vals[i]; vals[i]=vals[j]; vals[j]=temp; } }