Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using C++ with the following code already written Task 5 Add a new function, called isPrime(), that takes in a number and returns true if

Using C++ with 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 #include #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 integers; std::ifstream inputFile; std::ofstream evenFile; std::ofstream oddFile; inputFile.open("input.txt"); // Open the file input.txt // Reads in all of the integers in the file while (inputFile >> num) { integers.push_back(num); //Stores data in a vector count++; } cout<<"Numbers read in: "< :: iterator i; for (i = integers.begin(); i != integers.end(); ++i){ if(isEven(*i)){ evenFile << *i <

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Driven Web Sites

Authors: Joline Morrison, Mike Morrison

2nd Edition

? 061906448X, 978-0619064488

More Books

Students also viewed these Databases questions