CIS 067 Section 1
Assignment Number 03-F2001

Prime Numbers and Palindromes

Reading: Parts B and C of the Syllabus.

Programming: Write a program to read in a sequence of integers, one at a time, and decide whether or not each positive integer read is a prime number or a palindrome. For each positive integer, p, that is read, first decide whether p is prime and print an appropriate message. Then determine if p is a palindrome and print a message. Your data should be read from the keyboard until the program reaches the end of the input file. The lab assistant will give you instructions for testing for EOF when reading from the keyboard.

If your program reads a negative integer or 0, it should print an error message and ignore this value (and go immediately to read another integer). At the end, the program should print the number of positive integers read and the total number of integers read.

Be sure to thoroughly test your program -- carefully choose a set of test cases to test each possible execution path through the program. This will be a lot easier to do if the is_palindrome and is_prime steps are each implemented as separate functions.

NOTE: For the purposes of this assignment, a palindrome is an integer that reads the same forwards as backwards.

Some example messages that your program might print:

For a value of p = 272, the program might print the messages

p is not prime
p is a palindrome

For a value of p = -3, the program might print

p is not a valid input value and has been skipped

For a value of 37 the program might print

p is prime
p is not a palindrome

Turn In: A Structure Chart (See the Case Studies, Sections 3.4 and 6.3 of the Friedman/Koffman text) illustrating

Also turn in Data Requirements Tables for the main function and complete Function Interface Descriptions for each additional function. Be sure to clearly define the function interfaces (function name, arguments list, and return value) a illustrated in Section 6.3 of the text. For the Function interfaces you may use either a C++ function prototype declaration or a table representation as shown in the text.

Due Date: All documentation should be turned in to me in class Monday, Sept, 17. The working assignment should be e-mailed to the lab instructor by Friday, Sept. 21, noon (but no later than Monday, Sept. 24 if credit is expected).