Reference no: EM132194650
Write a C++ program:
Assume all input and output is made to and from the console. In the main program, declare an array numbs with room for 50 integers, and an integer n, which will hold the number of filled positions in the array. The main program will call the functions readin, changeNeg, and sortit, described below.
The main program will send to readin the array numbs and n; it will send to changeNeg the array, n and an integer newval; and it will send to sortit the array numbs and n.
After calling changeNeg, the main program should print the count returned by the function, together with an appropriate message. The main program should also print the changed array.
Write a function readin which receives two parameters and does not return a value. The first parameter is the array (which the function calls vals) and the second integer reference parameter (which the function calls lim). The function will read in a series of integer values from the keyboard and store them in the array vals.
Assume there will be no more than 50 numbers read in. The function will read values until there is no more input. The function will place the number of values read in into the parameter lim.
Write a function changeNeg, which receives three parameters and returns an integer. The first parameter is the array, which the function calls arr, the second is the number of filled positions in the array, which the function calls n, and the third is an integer which the function calls somenum. The function should add somenum to each negative value in the array arr.
The function should also count the number of changes made and return that count to main. For example, if the array contains 28 -12 68 -9 the function would change -12 and -9 and return 2.
Write a function sortit that receives two parameters and does not return a value. The first parameter is an array which the function calls vals, and the second is an integer which the function calls n. The function sorts the first n elements in array vals into descending order (highest value first). For example, if the numbers in vals are 28 -12 68 -9 and n is 4, the sorted array will contain 66 28 -9 12.