EECS168 09:Homework2
| Navigation | 
|---|
| Home | 
| Information | 
| Classwork | 
Overview
In this homework you will learn to use nested loops, by writing a program to calculate all the prime numbers between 3 and a user-defined value.
DUE DATE: The electronic submission of your homework must be received before 11:59 pm, Tuesday, 10th of February.
Problem Description
This program takes any integer greater than 3 as input. It outputs a list of all the prime numbers between 3 and the number supplied by the user.
Program Requirements
Name your source code file PrimeCalc.cpp In writing the program, you have to satisfy the following requirements:
- Properly comment each loop, and the logic within the loop.
 - Use at least one for loop, not only while loops. It is probably best to use only for loops in the prime calculation potion of the program.
 - It is the responsibility of the programmer to check for incorrect input of the user and handle it correctly. For example, you need to make sure that a user enters an integer greater than 3. The user should be prompted to re-enter incorrect input. The program should not hang or give ugly error messages, or worse proceed and produce incorrect output.
 
To write the Prime Calculator program, proceed as follows:
Get input from the user as you have done in previous exercises.
You should use a doubly-nested loop. The outer loop can iterate from 3 to the user supplied value, while the inner loop checks to see if the iterator value for the outer loop is prime. One way to test n for primality is to loop from 2 to n/2 and if any of these number evenly divides n, then n cannot be prime. If none of the values from 2 to n/2 evenly divide n, then n must be prime.
Example Execution
The formatting of the program's output should exactly match the following (user's input is shown in bold):
Please enter the highest value you wish to check for primality: 100
List of prime numbers between 3 and 100: 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97
Notes
- Your source code files should have comments at the top with:
- your name
 - the class ("EECS 168")
 - the assignment name (i.e., "Homework 2")
 - the date
 - an explanation of what the code is supposed to do
 
 - You should have comments in the code that explain what the code is doing.
 - You should test your program including incorrect input handling. Show your testing output in a file called testing.txt, like you did in Homework 1.
 
Additional Requirements For EECS 169 Students
In addition to all the requirements for EECS168 students, students enrolled in EECS169 must also do the following:
- Ask the user to input the lower bound or the prime calculations as well as the upper bound, i.e. not always start checking numbers from 3.
 - Allow the user to do as many prime number calculations as desired before exiting.
 
Submission
The files you should tar and submit electronically are:
- PrimeCalc.cpp: Your source code.
 - testing.txt: The testing you did on your finished program.
 - Your tarball and the directory inside it should be named like Smith-1234567-Homework-02
 
- The subject of your e-mail should be '[EECS 168] Homework 02'