Pascal Programming: Week 7 Notes Assignment #1 and #2 Read Chapter 9, Chapter 13 pg.515-537, Chapter 14 pg. 559-565 Team discussion: System Breakdown and Unit Development Ordinal Types In Pascal, a type whose values are specified by a list is called an ORDINAL type; e.g. Integer, Boolean and Character where the list of values for these types are system defined. Ordering and use of relational operators Ascii ordering - Uppercase precedes lowercase characters. Functions: Pred() - returns predecessor Succ() - returns successor Ord() - returns ordinal position in list for the "char" given Chr() - returns "char" value of the ordinal (inverse of Ord() ) Enumerated Types - User defined list of values of an Ordinal type. A list of identifiers that are the "values" for that variable. Subrange Types A new type whose values are a subrange of the values of some existing ordinal type. The "R" Compiler Directive for range checking. Turbo pascal will not always give an error message if your program assigns an illegal value to a variable of a subrange type so {&R+} e.g. Type Grade = 'A' .. 'F'; Random Number Generators Pseudo random number generators System RNG: random() Range of values Initializing the RNG - Random Seed and Randomize Pg. 559-565 More on ARRAYS No dynamic array lengths in Turbo Pascal Partially filled arrays require special care to prevent OVERFLOW errors Need to know where the array ends Need to define the array as the largest size you might need. Array expansion allowed by changing the bounds of the array Empty array handling must be done. e.g. the code on pg. 343 Must initialize the array index AND the array contents. Storage Issues: (arrays and parameter passing) pg.347 Procedure Recursion Pgs. 515-537 Example: Procedure to check for valid input on account number Designing for recursion. Tower of Hanoi Example. - Recursion is not absolutely necessary. It can reduce the lines of code but also can create confusion when following the code or debugging. - Some programming languages do not allow it. Others, like LISP, thrive on it. - Any task that can bbe accomplished by recursion, can also be done in a non-recursive version, typically this is an iterative version. - They may use more storage and run slower depending upon the system environment and programming language. Complex Array Types and Record Types Read Chapters 10-11 for next week Assignment #3: Team Units (due next week)