Reference no: EM13166647
Write a program using C++ that sets up an int array which has available positions with subscripts 0 through 199. We wish to enter quite a few integers into this array, but want to fill the array starting in the center, according to the rule: if the new integer is negative it should go in the position with subscript 99 (just left of the center), after moving over to the left by one positional the other integers already stored to the left of center. If the new integer is positive it should go in the position with subscript 100 (just right of the center), after moving over to the right by one position all the other integers already stored to the right of center.
We know the array is large enough to absorb all the new numbers fed in.
One way to write the program uses two functions. The first function accepts the array, the new negative integer, and the number of integers already stored to left of center. The function does the shifting over and puts in the new negative integer, so the array gets changed; it also adds 1 to howmanyonleft. The second function accepts the array, the new positive integer, and the number of integers already stored to right of center. The function does the shifting over and puts in the new positive integer, so the array gets changed; it also adds 1 to howmanyonright.
Write the program that incorporates these two functions, as described. You will notice that the two functions have very similar statements, so you are doing some repetitive C++ code.
Then write a second program that uses just one function that efficiently will handle either situation. Make the one function as concise and elegant as possible. It should not have repetitive code.
Have your program read the data in from a file. Sample data files of various lengths. The program has to read the data from a text file called "InsertNos1.text" and "InsertNos2.txt"
The information on "InsertNos1.text" is
102 34 34 -85 86 -28 -51 -105 71 69 85 -72 -50 -39 12 56 6 4 -23 -79 116 -32 -55 -66 104 104 47 -19 112 -75 -80 -10 117 -108 31 -48 104 -81 -47 -71 49 117 -50 -109 65 37 -55 89 41 14 -110 109
The information on "InsertNos2.text" is
79 66 57 26 -23 50 99 5 -67 -97 -55 -56 -11 -104 -16 58 -82 43 -107 -95 119 -118 117 -31 91 113 -118 9 71 23 -71 -27 -113 98 28 -29 12 -110 -6 -32 -38 66 -119 -120 -93 6 14 93 6 26 33 -94
The ouput is to print out the array at the end of the program, and print out the value of howmanyonleft and the value of howmanyonright.