Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please use c++ for the code and use comments and please do not hand write the code thanks in advance Program #1-Finding Prime Numbers This

image text in transcribedPlease use c++ for the code and use comments and please do not hand write the code thanks in advance
image text in transcribed
Program #1-Finding Prime Numbers This program asks you to determine a set of prime numbers, given some input from the user Your program should ask the user to enter an integer between 1 and 100. For purposes of discussion, let's call that number num If num is outside that range, your program should print out an error message and re-prompt for another number (i.e., have an input validation loop). Your program should then calculate the first num prime numbers and print them both to the screen and to an output file, PrimeOut.txt. Your output should be neatly formatted, 10 numbers per line, and should look like the following examples. For the first example, let's assume num20 The first 20 primes: 2 3 711 13 1719 23 29 31 37 41 43 4753 59 61 77 or if num25: The first 25 primes: 7 11 13 17 19 23 29 1 37 414347 53 59 61 771 73 79 83 8997 Here we are using a 5 byte field just as we did in a previous assignment. Since the 100th prime is a three digit number, that should work well (Other spacing's are obviously possible; just make sure there are 10 numbers per line.) CS1336- Programming Fundamentals page: 2 To solve this problem, your program should have a function called isPrime) that takes an integer as an argument and returns true if the argument is prime or false otherwise. (This is a boolean returning function as described in the book in Section 6.9. The prototype for the function should be: bool isPrime (int number) Using this function can significantly simplify your main processing loop. Its use is a perfect example of functional decomposition, also called modular programming. In modular programming, we move the solution of a specific task (in this case: determining if an individual number is prime or not) to a function and then use that function to create the overall solution to our problem. Functional decomposition is an excellent programming technique and should be used in all of your programs from now on. (Note: an example of a boolean returning function and how to use it is given on p.333 of the book. There the boolean returning function is s Even( 1nt), and it is called inside an "if" statement. You can use your is Prime [int) function in the same way.)

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

Step: 3

blur-text-image

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

Time Series Databases New Ways To Store And Access Data

Authors: Ted Dunning, Ellen Friedman

1st Edition

1491914726, 978-1491914724

More Books

Students also viewed these Databases questions