Homework 5

Seeking a Sieve.

This homework is worth 15 points.

Goals

When you finish this homework you should:

Assignment

For this assignment, create a series programs which allow the user to explore prime numbers.

The first program, PrimeMaker should take two command line arguments, the first is the output file name, filename, and the second is the maximum search value, n, an integer. A typical command is PrimeMaker primefile 10. You should report an error and fail if n is less than 10.

This program should use the Sieve of Eratosthenes to find all primes between 2 and n.The twist is that you may not use an array to do this, you are to use filename. Specifically, positions within the file should be used in place of an array.

The format of the file is as follows

A file, (primefile) corresponding to the above command should contain:
0000000appcpcpccc

Write a second program, PrimeDumper, which given the name of a file as the first argument, will print out all prime numbers identified in the file. You may assume that the file, if it exists, is in the above format. This program should produce a single line of output which contains the primes, separated by commas. The last prime should not be followed by a comma, but should be followed by a new line.

PrimeDumper primefile after the previous command should produce:

2,3,5,7

Write a third program, PrimeExplorer which, given the name of a file as the first argument, allows the user to interactively explore the primes identified in the file. The file will be in the above format, if it exists. This program should allow the user to type in a number and the program will display if that number is prime or not. The program should perform bounds tests on the user input and report an error if the number is less than 2 or greater the maximum given size.

Discussion

Submission

Email a copy of the C code to complete the final task to your instructor by class time. If your code consists of a single file, the source code will be sufficient, if the code is in multiple files, you should submit a tar file containing the source code and a make configuration file required to build the project.