Question
Using C++ add the following tasks to the following code already written Task 5 Add a new function, called isPrime(), that takes in a number
Using C++ add the following tasks to the following code already written
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.
Determine if a number is prime can be quite time consuming. You will probably want to test your program using the short.txt input file, found here:
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. You have already completed most of these functions in previous assignments.
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
#include
using namespace std;
// Function to check if a number is even bool isEven(int num){ if(num%2 == 0) return true; else{ return false; } } // Function to check if a number is odd bool isOdd(int num){ if(isEven(num)) return false; else{ return true; } }
int main () { int num, count = 0; vector
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