Finite Automata and the Recognition Problem
Recognizing Numbers in Scientific Normal Form
Introduction
A number is said to be represented in scientific notation if it is in the form of:
number = s * (r^exp)
where number is the number in scientific notation,
s is called the significand, r is the radix (or base),
and exp is the exponent. The number is said to be in
normal form when the significand meets the criteria:
1 <= s < r
This rule implies that, for decimal numbers with no leading zeros,
the decimal point always occurs at the right of the first significant
symbol.
Example:
Number
|
Comment
|
23.24 |
Not in scientific normal form (SNF) since the
base and the exponent are missing. |
23.24*10^0 |
Not in SNF since the significand (23.24) is larger than the base |
2.324*10^1 |
Is a number in SNF: the significand (2.324) is larger than 1 and
smaller than 10, and it is multiplied by the base (10) raised at
some power (1). |
For practical and historical reasons, numbers in scientific notation are
entered in computers in a slightly different format: the base (understood
to be 10) is replaced by a e or a E, and the caret
sign (^) is omitted.
For computer purposes, a number like
23.24 will be represented as 2.324e1 in SNF. Note that the number
may have a leading sign (+ or -), and that
the exponent itself can have a sign. The same number (23.24) can also be
represented as +2.324e+1 where both the sign of the number and
the sign of the exponent are present.
Your program will read a string from standard input and will decide whether
the string represents a number in SNF or not. Note that your program
must make the decision regardless of whether the number is actually
representable in the computer or not.
For instance 1.41421356237309504880168872420969807856963176679737e0
would be a perfectly valid input to your program; however, you never get
this many significant bits in any common computer representation.
Depending on how you write your program you may be able to indicate an error
as soon as the character is entered, or else read the number when an EOL is
found, and only then process the string.
You must provide a table driven implementation using C or C++. The useage of regular expression libraries
is not allowed for this project.
|
If you like to think of programs as being something useful (beyond the learning
experience), then you can imagine your program is part of a package which
is used to train students in Computer Science: your program will then do
part of the training which refers to number formats.
What you'll turn in
-
A floppy disk (3.5") which contains:
- the source file(s) for your program. Note that grading,
as described below, considers both the functionality and the readability
of your code.
You must follow the
coding style and documentation standards
used in the Computer Science Department.
- DOS executable named assign2. If you prefer to use UNIX instead, then you
shall turn in an executable made for one of the following, Solaris 8, Irix 6.3, or Linux.
- README file indicating what the program does, how to build the executable,
the platform it's been tested on, and how to run it, known limitations, plus any other information
you consider useful - like the name of the author, etc.
- a memo describing your work. You will indicate what you have looked
for and how you solved the problem. Direct the memo to your class instructor.
Attached to the memo will be a document that introduces the necessary theoretical background.
-
Hardcopies:
- the memo with the attached theoretical background.
- a listing of the source code.
-
the state transition diagram of the FA you have used to
solve the problem.
A professional look of your work is expected. Loose items will be rejected.
A binder (or an envelope) to hold your work together is required.
Grading
- A mark between 0 and 10 for functionality. The mark basically indicates
in what measure your program works properly and how well you have followed
the initial specification.
- A mark between 0 and 10 for readability. This mark indicates how well
documented your program is; it also considers the general appearance of
your final report.
- Multiply the above two marks to get the mark for this programming assignment.
For each business day you turn in your project earlier you receive a
5% bonus. However, penalties increase by 5% as well. You can turn in your
assignment up to five business days ahead of the deadline.
Example:
- You turn in your assignment three days earlier: a 3*5=15% bonus will
be added to your assignment mark
- We find a single mistake in the functionality section and the penalty
for that mistake is 0.5 points. Since you have turned the assignment three
days earlier than the deadline, the penalty becomes 0.5*(1+3*5%)=0.5*(1+3*0.05)=0.575
- We calculate the mark by multiplying the marks for the functionality
and readability; in your case the mark for functionality is 10-0.575=9.425,
and the mark for readability is 10. The result is 9.425*10=94.25
- We add the bonus to this mark: 94.25+94.25*15%=108.38 which we round
to 108. This is your final mark.
You may be asked to do a code review with your instructor.
$Id: assign2.1.html,v 1.1 2001/10/20 10:53:43 virgil Exp $
|