Lecture 3: I/O Investigation of Rational Numbers
I/O Investigation and Pseudo-code of Rational Numbers
Notes:
1. If we consider the user interface, we might want to think about how users enter information via keyboard. If the program acts friendly, it must carry more work for itself. Convenience for users might be not simple for programmers.
2. We are aware that users can enter a rational number as an example 123/45. It is a mixed between numbers and characters. Hence it is treated as a string. We must learn how to extract the sub-string before slash and another after slash. Looking for all possible cases with examples will help us do classify this kind of input.
I/O Investigation:
Input: from keyboard as string.
Output: Extract numerator and denominator as integers.
Here are the typical cases:
Case # Input Expected Output Simplest forms
1 "4/14" 4 14 2 7
"-2/-7" -2 -7 2 7
2 "125" 125 1 125 1
3 "-125" -125 1 -125 1
4 "+125" 125 1 125 1
5 "+125/-12" 125 -12 -125 12
6 "+125/0" "ERROR"
Note 3. In this section, we choose to work from input to Expected Output. The next step from Expected Output to Simplest Forms" can be considered later. This technique of divide and conquer would help us to focus on a narrow solid subject matter.
Strategy to handle these cases, pseudo-code:
Phase 1: The simplest normal case (Case 2) : StrToNum will convert a string-number to a number.
Phase 2: Expension of Phase 1 to cover more cases: Case 3, 4. Theses cases are Case 2 with a sign either + or – in front. Here is the pseudo-code with input as inputString and output as outputNum
Pseudocode: StrToInt (input: inputString; output: outputNum)
Get the firstChar from inputString
Case firstChar is
‘+’: sign is set positive
reduce inputString by firstChar
‘-’: sign is set negative
reduce inputString by firstChar
others: sign is set positive;
Do not reduce inputString
OutputNum ................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- section 4 2 direct proof and counterexample ii rational
- chapter review rational and real numbers
- rational and irrational numbers 1
- 1 2 the integers and rational numbers university of utah
- 5 integers whole numbers and rational numbers
- the rational number system worksheet 1
- adding and subtracting rational numbers
- number theory rational numbers and expressions
- rational numbers 28 07 2010 final
- the rational number sub constructs as a
Related searches
- rational numbers between fraction calculator
- rational numbers operations worksheet pdf
- operations with rational numbers pdf
- rational numbers to decimal expansion calculator
- repeating decimals to rational numbers calculator
- rational numbers least to greatest calculator
- put rational numbers in order calculator
- multiply rational numbers calculator
- identify rational numbers worksheet
- operations with rational numbers worksheet
- fractions rational numbers calculator
- rational numbers answer key