Question: Rewrite the program by grouping the code into functions. Change the program so it takes the input from a file input.txt instead of the terminal.

Rewrite the program by grouping the code into functions. Change the program so it takes the input from a file input.txt instead of the terminal. In particular, your program should include the following functions:

1. A void function named readFile. The parameter should be a string passed by reference. This function reads a set of numbers from a text file as a single string.

2. A function named countInt that returns an integer. The parameter should be one string containing the set of numbers taken from the file and counts the integers in the string.

3. A function named fillArray that takes a string, an integer array, and the arrays size as parameters and returns nothing. This function fills the integer array with the integers from a string. Query: are arrays passed by reference automatically?

4. A function named bubbleSort() that returns nothing (void). The parameter should be an integer array and its size. The array is sorted by the function.

5. A function named calcMean()that returns a double. The parameters should be an integer array and the size of the array. Calculates the mean of the set of integers in the array.

6. A function named calcMedian() that returns a double. The parameters should be an integer array and the size of the array. Calculates the median of the set of integers in the array.

7. A function named calcMode() that returns an integer. The parameters should be an integer array, the size of the array, and a Boolean value. Calculates the mode of the set of integers in the array and sets the Boolean value to false if mode is not found. Hint: pass Boolean by reference.

8. A function named calcStdDev() that returns a double, The parameters should be an integer array, the size of the array, and a double. Calculates the standard deviation of the set of integers in the array.

As you introduce each function, replace the code in main() by calls to your new functions as appropriate. In particular, note that some of these new functions may be called from within the bodies of some of the other functions. Remember that this program was already working. You should not alter the output of the program in any way and No Global Variables.

This is the code that needs to be rewritten:

#include  ///cin, cout #include /// istringstream #include  /// pow, sqrt int main() { std::string input; int counter=0; int inum=0; double mean=0.0; double mode=0.0; double median=0.0; double stddev=0.0; int i,j,temp; ///take a set of numbers as string input std::cout<<"Enter a set of numbers separated by spaces for analysis:"<>inum){ counter++; } ///clear the flags on the string stream and refill with the input string ss.clear(); ss.str(input); ///create array of size counter(the number of integers) and fill it from the string stream int intArray[counter]; for( i=0; i>inum; intArray[i]=inum; } ///sort the numbers in the array smallest to largest for( i=1; i< counter; i++){ for( j=0; j< counter-i; j++){ if(intArray[j]>intArray[j+1]){ temp=intArray[j]; intArray[j]=intArray[j+1]; intArray[j+1]=temp; } } } ///calculate the mean of the numbers for(i=0; imaxi){ maxi=mocount; mode=intArray[i]; modefound=true; } else if(mocount==maxi){ modefound=false; } } else{ if(mocount>maxi){ maxi=mocount; mode=intArray[i]; modefound=true; } mocount=1; temp=intArray[i]; } } ///calculate the standard deviation double sum=0.0; double avg=0.0; for(i=0; i 
 Thank you for your help! I want to understand how the rewritten code can be written simpler and easier than the original code. 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!