Question: Objective Your goal is to write a program to find prime numbers using the sieve of Eratosthenes. 2 . Problem You are to create a
Objective
Your goal is to write a program to find prime numbers using the sieve of Eratosthenes.
Problem
You are to create a C project called sieve, a C source file called sieve.cpp and class
inside it called PrimesSieve that finds prime numbers. The program asks the user for a limit
and then finds primes up to and including that limit When there is only one line of prime
numbers in the output, the numbers should be displayed with one space between each
and no space at the end When there are multiple lines of output, the numbers should be
rightaligned to the width of the largest prime. See below.
Sieve of Eratosthenes
Search for primes up to:
Number of primes found:
Primes up to :
Sieve of Eratosthenes
Search for primes up to:
Number of primes found:
Primes up to :
Tips
a Use the template file found in Canvas. The framework for the program is there, and you
will need to fill in the methods.
b If a functionmethod is inline, the compiler places a copy of the code of that
functionmethod at each point where it is called at compile time. inline is used for
efficiency with short oneline functionsmethods
c Look up setw in the iomanip library to set the width of a field that is to be outputted.
d #include for the sqrt function.
e You may have up to characters on a line. If you cannot fit all the primes on one line,
you should wrap around to the next line. To find the width of the maximum prime value
and how many primes you can fit on a row, use the following code:
const int maxprimewidth numdigitsmaxprime
primesperrow maxprimewidth ;
Before printing each prime, determine how many spaces are needed to rightalign the
number, and set the field width accordingly.
f Be sure to comment your code and put your name and Stevens pledge at the top.
g Make sure your code works with the test.sh autograder shell script.
h The algorithm for the sieve is found in pseudocode below.
Sieve of Eratosthenes
Input: an integer n
Let isprime be an array of bool values, indexed by integers to n
initially all set to true.
for i while i :
if isprimei is true:
for j i i i ii while j n:
isprimej false
Now all i such that isprimei is true are prime.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
