$29
Objectives
1. Designing and implementing procedures
2. Designing and implementing loops
3. Writing nested loops
4. 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 .. 300]. The user enters a number, n, and the program verifies that 1 ≤ n ≤ 300. If n is out of range, the user is re-prompted until they enter a value in the specified range. The program then calculates and displays all of the composite numbers up to and including the nth composite. The results should be displayed 10 composites per line with at least 3 spaces
between the numbers.
Requirements
1. The programmer’s name must appear in the output.
2. The counting loop (1 to n) must be implemented using the MASM loop instruction.
3. The main procedure must consist (mostly) of procedure calls. It should be a readable “list” of what the program will do.
4. 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 sub-procedures:
introduction
getUserData
validate
showComposites
isComposite
goodbye
5. The upper limit should be defined and used as a constant.
6. Data validation is required. If the user enters a number outside the range [1 .. 300] an error message should be displayed and the user should be prompted to re-enter the number of composites.
7. Each procedure must have a procedure header that follows the format discussed during lecture.
8. The usual requirements regarding documentation, readability, user-friendliness, etc., apply.
Notes
1. For this program, you may use global variables instead of passing parameters. This is a one-time relaxation of the standards so that you can get accustomed to using procedures. In future homework, global variables will not be allowed.
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
1 is not composite.
The number must be positive.
3. If you choose to use the LOCAL directive while working on this program be sure to read section 8.2.9 in the Irvine textbook. LOCAL variables will affect the contents of the system stack!
Example Program Operation
Welcome to the Composite Number Spreadsheet
Programmed by Author Name
This program is capable of generating a list of composite numbers.
Simply
let me
know how
many you
would like to see.
I’ll accept orders for
up to 300 composites.
How
many composites do
you want to view? [1 .. 300]: 400
Out
of
range. Please try again.
How
many composites do
you want to view? [1 .. 300]: 0
Out
of
range. Please try again.
How
many composites do
you want to view? [1 .. 300]: 23
4
6
8
9
10
12
14
15
16
18
20
21
22
24
25
26
27
28
30
32
33
34
35
Thanks for using my program!
Extra Credit Option (original definition must be fulfilled)
(2 pts) When the program runs, give the user the option to display only composite numbers that are also odd numbers. The user should get a choice when the program first starts (e.g. enter 0 to view all composite numbers or enter 1 to view only odd composites). For example, if the user chooses to view only odd composites, they would see the numbers 9, 15, 21, 25, 27, 33, 35, 39, 45...
Remember, in order to ensure you receive credit for any extra credit work, 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--
Please refer back to the documentation for Program 1 to see a sample of the extra credit format.
Program 4 Rubric
Criteria
Ratings
Pts
Files Correctly Submitted
1 pts
0 pts
Submitted file is correct assignment and is an individual .asm file.
Full Marks
No Marks
1 pts
Program Assembles & Links
1 pts
0 pts
Submitted program assembles and links without need for clarifying work for TA and/or
Full Marks
No Marks
messages to the student. This assumes the program is actually an attempt at the
assignment. Non-attempts which compile/link earn no points.
1 pts
Documentation - Identification Block - Header
1 pts
0 pts
Name, Date, Program number, etc as per syllabus are included in Identification Block
Full Marks
No Marks
1 pts
Documentation - Identification Block - Program Description
1 pts
0 pts
Full Marks
No Marks
Description of functionality and purpose of program is included in identification block.
1 pts
Documentation - Procedure Headers
4 pts
2 pts
0 pts
Procedure headers describe functionality and implementation of program flow. Should
Full
Headers without Conditions
No
also list pre- and post-conditions and registers changed.
Marks
Descriptive headers but lacking
Marks
4 pts
pre- and post-conditions and
'registers changed'
Criteria
Ratings
Pts
Documentation - In-line Comments
2 pts
0 pts
In-line comments contribute to understanding of program flow (from section comments)
Full Marks
No Marks
but are not line-by-line descriptions of moving memory to registers.
2 pts
Verification - Program Executes
3 pts
0 pts
Program executes and makes some attempt at the assigned functionality.
Full Marks
No Marks
3 pts
Completeness - Displays Title & Programmer Name
1 pts
0 pts
Program prints out the programmer's name and Program Title
Full Marks
No Marks
1 pts
Completeness - Displays Introduction
1 pts
0 pts
Displays program introduction. Program introduction should describe functionality of
Full Marks
No Marks
program.
1 pts
Completeness - Prompts for Input (with Bounds)
1 pts
0 pts
Prompts user to enter data, specifying bounds of acceptable inputs.
Full Marks
No Marks
1 pts
Criteria
Ratings
Pts
Completeness - Gets data from User
1 pts
0 pts
Utilizes ReadInt or ReadDec to receive user input. Saves values in appropriately-named
Full Marks
No Marks
1 pts
identifiers for validation.
Completeness - Validates User Data
2 pts
1 pts
0 pts
Validates that user-entered values are within the advertised limits.
Full
Partial validation
No
2 pts
Marks
Neglects to check edge
Marks
cases.
Completeness - Displays Results
2 pts
0 pts
2 pts
Full Marks
No Marks
Completeness - Displays closing message
1 pts
0 pts
1 pts
Full Marks
No Marks
Correctness - Displays correct number of composite numbers
4 pts
3 pts
0 pts
Full
Mostly Correct
No
Marks
Edge cases are neglected or
Marks
4 pts
display incorrectly.
Correctness - Calculations are Correct
6 pts
0 pts
All displayed values are in fact composites, beginning with the number '4' (if running in
Full Marks
No Marks
extra credit mode, the numbers should start with '9')
6 pts
Criteria
Ratings
Pts
Correctness - Numbers are displayed 10 per line
2 pts
0 pts
2 pts
Full Marks
No Marks
Correctness - Partial lines displayed correctly
1 pts
0 pts
1 pts
Full Marks
No Marks
Requirements - Limit is a CONSTANT
1 pts
0 pts
Max number allowable is defined and used as a CONSTANT.
Full Marks
No Marks
1 pts
Requirements - Program is well-modularized
10 pts
8 pts
2 pts
0 pts
Program is divided into logical sections based on function. Program implements all
Full
Lacking some
No
No
required procedures with good logical flow according to class lectures.
Marks
Procedures
procedures
Marks
Note: as a reminder, the required procedures are introduction, getUserData, validate,
Well
Well
showComposites, isComposite, goodbye.
modularized,
modularized,
10 pts
Adding extra procedure is allowed.
but lacking all
but fails to
required
utilize
procedures
procedures
Requirements - Counted loop uses LOOP instruction when displaying the correct number
1 pts
0 pts
of composite numbers
Full Marks
No Marks
1 pts
Criteria
Ratings
Pts
Coding Style - Uses appropriately named identifiers
1 pts
0 pts
Identifiers named so that a person reading the code can intuit the purpose of a variable,
Full Marks
No Marks
constant, or label just by reading its name.
1 pts
Coding Style - Readability
1 pts
0 pts
Program uses readable white-space, indentation, and spacing as per the Indentation Style
Full Marks
No Marks
Guide. Logical sections are separated by white space.
1 pts
Output Style - Readability
1 pts
0 pts
Program output is easy to read
1 pts
Full Marks
No Marks
Extra Credit
0 pts
0 pts
Program has an extra mode that will only display composite numbers that are also odd
Full Marks
No Marks
numbers (+2).
For example, if the user chooses to operate in extra credit mode and asks to view 3
0 pts
composite numbers, they will see "9, 15, 21".
Late Penalty
0 pts
0 pts
Remove points here for late assignments. (Enter negative point value)
Full Marks
No Marks
0 pts
Total Points: 50