Question
Using C++ You will be reading in a file of integers (called input.txt). The file may be quite large and we will be storing all
Using C++
You will be reading in a file of integers (called input.txt). The file may be quite large and we will be storing all numbers into a vector.
Please perform the following tasks in order. You should verify that each step is working correctly before moving on to the next step.
Please create functions at least 4 extra functions beyond the those specified in this document.
Input text file is below in google drive
https://drive.google.com/open?id=0Bz7mRWBNmOLZWnZGVnBxMnBUeWM
Task 1
Write a program that opens the file, called input.txt, and reads in all of the integers in the file and stores them in a vector. All you need to do for the first part is to display the count of the intger numbers that you have read in.
Here is sample output from task 1. For all sample outputs, the provide the correct output for the file indicated.
Numbers read in: 100009
Task 2
Write a function, called isEven() that takes in an integer using pass-by-value and returns a boolean value. The return value should be true if the number passed in is even, and false if the number is odd.
Inside the main() create a loop that processes the vector read into memory above, you should call isEven for each number, count the even numbers, and than output the number of even numbers.
Here is sample output from task 2.
Numbers read in: 100009
Even numbers: 49868
Task 3
Expand the main function so that a file called evens.txt is opened for writing. Write all of the even numbers that you detect to this output file, 1 number per line.
The output printed to the screen should be the same as task 2.
You can verify that the number of lines in the evens.txt file using the unix command wc
$ wc -l evens.txt
49868evens.txt
Task 4
Add a new function called isOdd. IsOdd should function similarly to isEven. In fact, isOdd should call isEven to determine the answer to that question.
Also add here an output file called odds.txt that contains all of the odd numbers that you discover.
Sample output after task 4:
Numbers read in: 100009
Even numbers: 49868
Odd numbers: 50141
Task 5
Add a new function, called isPrime(), that takes in a number and returns true if the number is a prime number. Just like with the others, create an output file called primes.txt that contains all of the prime numbers you find.
Here is the sample output for the full input.txt file. I have also used the unix time command, to show long long it took to run the program over the large input file.
Numbers read in: 100009
Even numbers: 49868
Odd numbers: 50141
Prime numbers: 6774
real 1m12.695s
user 1m12.292s
sys 0m0.376s
Task 6:
Finally, add in the necessary functions to display the maximum, minimum, mean, standard deviation, and sum of these numbers.
Expected Output:
Numbers read in: 100009
Even numbers: 49868
Odd numbers: 50141
Prime numbers: 6774
Min number: 27
Max number: 9999930
Sum: 780886019
Mean: 7808.16
Standard Deviation: TBD
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started