ITEC 320: Program 1

Due Date: 11:59:59 p.m. Monday 9/18/17 Thursday 9/14/17

Submit Command: submit itec320-01 numbers.adb

Last modified:

  1. 2017 Sep 11 11:14:40 AM: Extended due date.

Your program will determine whether a number, n, is prime or composite, and for composite n your program will list both all positive factors of n as well as the prime factorization of |n|. For this assignment, we will allow negative numbers to be prime.

Sample Run: Assume that you have an input file, called myData.txt, that contains the following:

-1 -3 -16
-12 150
The output from executing your program (ie executing numbers < myData.txt) will look like the following:
rucs@/home/nokie> numbers < myData.txt
12 is composite
     All positive factors of 12: 1, 2, 3, 4, 6, 12
     Prime factorization of 12: 2 ** 2 * 3
3 is prime
0 neither prime nor composite
1 neither prime nor composite
-1 neither prime nor composite
-3 is prime
-16 is composite
     All positive factors of 16: 1, 2, 4, 8, 16
     Prime factorization of 16: 2 ** 4
-12 is composite
     All positive factors of 12: 1, 2, 3, 4, 6, 12
     Prime factorization of 12: 2 ** 2 * 3
150 is composite
     All positive factors of 150: 1, 2, 3, 5, 6, 10, 15, 25, 30, 50, 75, 150
     Prime factorization of 150: 2 * 3 * 5 ** 2

Output: Output from your program should be formatted and printed as shown in the sample run.

Input: Your program will read and process a sequence of integers from standard input until it reaches end of file. You can assume that all integers will be representable as a 32 bit signed number. White space can appear anywhere in the input file, except after the final integer. Your program should not have any prompts. Do not get input from a file whose name is coded in your program.

Standard input: Your program is to read from what is known as Standard Input. If you don't specify otherwise, a read from standard input comes from the keyboard. To cause standard input come from a file, you must use input redirection. For example, to cause the program numbers to get standard input from a file named myData.txt, you would enter the following on the command line:

   numbers < myData.txt

If you are using AdaGIDE, you must tell it to use redirection and to specify the file: use Run/Run Options, check the Redirect box, and enter the name of the file that contains the data. As far as I know, GPS does not allow redirection. Instead you must use a command line.

To read from standard input, your program can simply use a get such as get(x).

Errors: If an invalid value is input, then your program can simply halt with an appropriate error message.

Efficiency: You also do not need to be overly concerned with efficiency.

Creating input files: Your data file can be created with any editor, but don't use an editor (such as wordpad) that stores characters using 16 rather than 8 bits. Make sure that your editor is not creating a RTF (ie rich text) file. You will want to make sure that you create your data file using the same OS that you use to test your program. When a data file is created on a different OS, the I/O routines may not correctly detect the end of file or end of line white space. You do not need to submit your data file.

End of File on Interactive Input: If you want to test your program by giving it input from the keyboard, then you will need some way of signaling the end of the input, that is, signaling end of file (though there is no real file in this case). The way you signal end of file differs depending on the operating system. On unix/linux systems, the Ada function end_of_file returns true when you enter ^D (ie hold down control and press D, aka control-D) on a separate line. On MS Windows systems, end_of_file returns true when you enter, on a separate line, ^Z followed by an enter. Please remember that when reading from a file, the OS recognizes when the input is at the end of file, and so you do NOT put a control-D or control-Z into the file!

Style: Your program should follow my style guide. In particular, please note the use of consistent indentation, named constants, and descriptive constant and variable names. Please remember that the first thing in any program file should be a comment that gives a brief overview of what the file contains (and should do). Also remember to keep your lines less than 80 characters long. Not only does this mean that printouts won't run off the side of the page, but it also makes your programs look neater on an 80 column wide xterm window (a popular size). Please ask if you have questions about style.

Submission: Use the submit command to turn your program in for grading. You may submit as many times as you like, but only the last submission is kept. In particular, be aware that since only the last submission is kept, if the last one is late, then your assignment is late and will thus receive a late penalty. Also remember that you must be on rucs for submit to work. To submit your work for grading do the submit command given at the top of the assignment.