$30.00
Description
Objectives:

Designing and implementing procedures

Designing and implementing loops

Writing nested loops

Understanding data validation
Problem Definition:
Write a program to calculate composite numbers. First, the user is instructed to enter the number of composites to be displayed, and is prompted to enter an integer in the range [1 .. 400]. The user enters a number, n, and the program verifies that 1 ≤ n ≤ 400. If n is out of range, the user is reprompted until s/he enters a value in the specified range. The program then calculates and displays all of the composite numbers up to and including the n^{th} composite. The results should be displayed 10 composites per line with at least 3 spaces between the numbers.
Requirements:

The programmer’s name must appear in the output.

The counting loop (1 to n) must be implemented using the MASM loop instruction.

The main procedure must consist (mostly) of procedure calls. It should be a readable “list” of what the program will do.

Each procedure will implement a section of the program logic, i.e., each procedure will specify how the logic of its section is implemented. The program must be modularized into at least the following procedures and subprocedures :


introduction



getUserData




validate




showComposites




isComposite




farewell


The upper limit should be defined and used as a constant.

Data validation is required. If the user enters a number outside the range [1 .. 400] an error message should be displayed and the user should be prompted to reenter the number of composites.

The usual requirements regarding documentation, readability, userfriendliness, etc., apply.

Submit your text code file (.asm) to Canvas by the due date.
Notes:
1) For this program, you may use global variables instead of passing parameters. This is a onetime relaxation of the standards so that you can get accustomed to using procedures.
2) A number k is composite if it can be factored into a product of smaller integers. Every integer greater than one is either prime or composite. Note that this implies that
a. 1 is not composite.
b. The number must be positive.
3) There are several ways to make your isComposite procedure efficient. (I recommend discussing this in your groups!)
4) See next page for an example execution
page 1 of 2
Programmed by Euclid 

Composite 
Numbers 

Enter the 
number of composite numbers you would 
like to see. 

I’ll accept orders for up to 400 composites. 

Enter the 
number of composites to display [1 .. 400]: 501 

Out of range. Try again. 

Enter the 
number of composites to display [1 .. 400]: 0 

Out of range. Try again. 
to display [1 .. 400]: 31 

Enter the 
number of composites 

4 
6 
8 
9 
10 
12 
14 
15 
16 
18 
32 

20 
21 
22 
24 
25 
26 
27 
28 
30 

33 
34 
35 
36 
38 
39 
40 
42 
44 
45 

46 
Results certified by Euclid. Goodbye.
Extra Credit:
1) Align the output columns.
2) Display more composites, but show them one page at a time. The user can “Press any key to continue …” to view the next page. Since length of the numbers will increase, it’s OK to display fewer numbers per line.
3) One way to make the program more efficient is to check against only prime divisors, which requires saving all of the primes found so far (numbers that fail the composite test). It’s easy in a highlevel language, but you will have to look ahead in the textbook to figure out how to do it in assembly language.
To ensure you receive credit for any extra credit options you did, you must add one print statement to your program output PER EXTRA CREDIT which describes the extra credit you chose to work on. You will not receive extra credit points unless you do this. The statement must be formatted as follows…
–Program Intro–
**EC: DESCRIPTION
–Program prompts, etc—
page 2 of 2