write a program that will read files of numbers into a vector, compute statistics relating to these numbers and distribute a vector of numbers into two vectors with approximately equal totals. The user should be allowed to repeat these tasks.
Main Input Loop
The program should allow the user to repeatedly perform one of the following tasks until he/she wishes to quit.
Read a file of numbers into int_vec
Print the contents of int_vec
Print the sum of int_vec
Print the mean of int_vec
Print the standard deviation of int_vec
Distribute the values stored in int_vec into two vectors where the sums of the values in two vectors are approximately equal, then print these sums
When the program starts the user should be prompted to read data from a file (as the user can't perform any of the other tasks until there is data to deal with). Thereafter the user should be prompted to perform one of the options noted above, or to quit.
Each of the tasks should be controlled by a separate function, and each of these functions, except for the read file function, should have a constant vector reference parameter. The read file function should return a vector of ints, which should be assigned to int_vec.
Write a function that prints the instructions, gets user input (a character) and then returns it. The instructions are shown in the screen-shot above starting with Please select one of the following options, and ending with q - Quit.
In addition to printing the instructions the function is also going to get user input. So the entire instructions function will look something like this, except it will, of course, be written in C++.
char instructions() declare char input variable print instructions using cout read user input using cin return inputStub Functions
A stub function is a placeholder function for work you haven't done yet. This allows a programmer to work on part of a project that needs to call a function even when that function hasn't been written yet (because someone else is writing it, or because it is very hard to write, etc.). The function is declared with the appropriate parameters and return value, but returns a default value. The default value will eventually be replaced with the correct calculation.
In the context of the assignment this will allow you to write the entire input loop and interface, and then plug in the functions as you complete them, and use the interface to test each function.
Here are a couple of sample stub functions for the first two tasks.
First, the read file activity stub function (which when finished will call another function to actually read the file, this one is mainly responsible for asking the user for the file name and dealing with errors).
// Performs the following tasks// - Requests a file name from the user// - Assigns the result of calling the readFile function to result// - Handles any errors from readFile// - Returns the result vectorvector <int> readFileTask(){ vector <int> result; // TO DO - read file into result return result;}And here is the print vector activity, this one doesn't need a calling function, as it is just going to print int_vec.
// Prints a vector of ints// PARAM: v is the vector to be printedvoid printVector(const vector<int> & v){ // TO DO - print v}Part 1 Summary
There is quite a lot to do here, but if you implement Part 1 like this you should be able to then handle each of the other tasks one at a time, and independent from each other. Pseudo-code for your main function will look something like this. This is a fairly high level description so I've let out variable declarations, which would include a vector for the data, and a character for the input.
int_vec = readFileTask() (a stub function at this point)input = instructions()while input is not 'q' if input is 1 int_vec = readFileTask() else if input is 2 printVector(int_vec) else if // ... options 3, 4, 5 and 6 end if statement input = instructions()end while loopprint goodbye
Part 2 - Reading Data From Files
Write a function that reads numeric data from a file of unknown length into a vector of ints. The vector should be returned by the function. The function should have one string parameter for the name of the file to be opened. The function should throw an invalid_argument error if the file could not be opened, and should ignore any lines in the file that cannot be inserted into the vector of ints (because they contain non numeric characters).
Now complete the stub function that calls your readFile function. This function should prompt the user for the name of the file to be opened and handle invalid_argument errors by requesting a new file name, or allowing the user to quit.
Part 3 - Printing a Vector
Write a void function with a constant vector reference parameter that prints its single constant vector<int> reference parameter, with one value per line. You can now replace your stub function with this function, using int_vec as its argument.
Part 4 - Calculating the Sum
Write a function returns an int which is the sum of the values in its constant vector<int> reference parameter.
Example - if the vector contains {3,4,4,6,10}Sum = 3+4+4+6+10 = 27Now complete the stub function for this task. The stub function should call your sum function and print the result. The stub function should be void and should have a constant vector reference parameter which it will pass to the sum function.
Part 5 - Calculating the Average
Write a function that returns a double which is the average of the values in an int vector. Your function should return (not print) the average, and should have a single constant vector<int> reference parameter.
Example - if the vector contains {3,4,4,6,10}Average = (3+4+4+6+10)/5 = 27/5 = 5.4Now complete the stub function for this task. The stub function should call your average function and print the result. The stub function should be void and should have a constant vector reference parameter which it will pass to the average function.
i am sorry i wasn't really intending to do that this is my first time here and due to some problem it updated my question twice i am not sure why i am sorry for inconvenience