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 alse read the number when an EOL is found, and only then process the string.

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

1. A well commented listing of 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 and Applied Mathematics Department
2. A floppy disk (3.5") which contains the source file(s) for your program, a DOS executable named snf.exe and a README file indicating what the program does, how to build the executable, the platform it's been tested on, and how to run it, plus any other information you consider useful - like the name of the author, etc. Also include a file (use the extension .din for the name), containg numbers you have used to test your program.
3. 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. A hardcopy of the program will be attached to the memo. Also attach the state transition diagram of the FA you have used to solve the problem.

1. 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.
2. 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.
3. Multiply the above two marks to get the mark for this programming assignment.

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.

 (c) 1999, Virgil Bistriceanu Last update: March 22, 1999 The cs330 home page