Starting from:
$35

$29

Computer Assignment 03 Sieve of Eratosthenes Solution

For this computer assignment, you are to write and implement a C++ program to find and print all prime numbers within a range `[lower upper]` using the algorithm known as the *Sieve of Eratosthenes*. The program will have basic interactive user interface to take input values of `lower` and `upper` and allow the user to continue or quit the game. A prime number **p** is an integer greater than 1 that is divisible only by **1** and **p** (itself). The algorithm begins by initializing a set to contain all of the integers in the range `lower` to `upper`. Note that the smallest prime number is `2`. If the value of `lower` is less than `2`, you need to adjust that. A loop makes multiple passes over the elements in the set, using successive integer key values `2, 3, 4, shakes freefilter through the sieve. 2`. The multiples cannot be prime numbers, because they are divisible by `2`. At the end of the pass, we have removed all of the even numbers except `2`. Next, look at the integer `m = 3`, which is a prime number. As with value `2`, remove all multiples of `3`, having the form `3 * k` for `k m`. The numbers that remain in the sieve are the prime numbers in the range `lower` to `upper`. The algorithm uses an optimization feature by looking at the key values for `m upper`, rather than computing the square root of `upper`.




Starter code for `assignment03.cc` is provided to you as part of this repository. In this file, the main function is already implemented. You are required to implement the following functions:




* `void sieve(set<int& s, const int lower, const int upper)` This routine can be used to apply the *Sieve of Eratosthenes* algorithm to remove all nonprime numbers from the integer `set s = {lower, o assignment03.exe`. This will create the executable file assignment03.exe. To test your program, execute `./assignment03.exe < assignment03.in & assignment03.out`, which will take redirected input from the text file `assignment03.in` and put the output (including any error messages) in file `assignment03.out`. You can find the sample input file `assignment03.in` and the correct output of this program in file `results03.out` are included within this repository. * Add documentation to your source file (e.g. https://google.github.io/styleguide/cppguide.html#Comments). * Prepare your Makefile (**included**) so that the TA only needs to invoke the command `make` to compile your source file and produce the executable file `assignment03.exe`. Make sure you use exactly the same file names specified here, i.e. `assignment03.cc` and `assignment03.exe`, in your `Makefile`. Otherwise your submission will get 0 points. This semester you will need to make at least ***three commits*** to your local repository and ***three pushes*** to your master repository for each assignment. This will show the evolution of your assignments over time and the thought process behind the code. You will need to make sure your final ***push*** to your master repository is completed before the assignment is due (the system time stamps actions), if the assignment is late the TA will mark off points.




When your program is ready for grading, ***commit*** and ***push*** your local repository to remote git classroom repository and follow _**Assignment Submission Instructions**_.

More products