Pascal Programming: Week 8 Notes Assignment #3 due Reading Assignment Chapters 10 Chapter 11 pgs. 407-424 Assignment #4: Team Projects (due in two weeks) Code Reviews Data Structures Versus Data Types A Data Type is a collection of values and the operators that manipulate them. A Data Structure is a super set of data types. They are any construct used to store and manipulate data in a program or algorithm. Complex Arrays Parallel Arrays Arrays of Arrays Multi-Dimensional Arrays Parallel arrays are used when you want the equivalent of two different component values for each indexed variable of an array. The component type of an array can be any Pascal type even other arrays, so you may have arrays of arrays. Anything that can be done with an array of arrays can also be done with two dimensional arrays. Storage considerations are important when dealing with arrays which are stored as stacks. More on Strings No string type in Standard Pascal. Turbo handles them like arrays of Char. You can access individual characters within a string. e.g. string[2] := 'a'; String types, like array types, must be declared in a type declaration before they can be used as parameter types. They are considered to be type definitions much like subrange type definitions. Type String10 = string[10]; Function ChangeName(name: string10): string10; Turbo String Procedure (not in Standard Pascal) concat() - joins any number of strings pos() - finds the starting position of a string literal delete() - deletes from a string with a start position to length insert() - inserts a string into an existingstring variable at a start point length() - returns the string length copy() - copies out of a string variable a substring, from start position to length upcase() - convert to upper case Typed Constants Exists in Turbo Pascal and not Standard Pascal. Typed constants are not really constants at all. Tney are initialized variables. But serve many of the same functions that constants do. Pg. 398 e.g. CONST max: integer = 5; num: real = 1.2; Records A collection of values, synonymous to tables in databases. The individual components of a record are commonly referred to as fields or components. e.g. PROGRAM TestRecord (input, output); TYPE StreetAddress = RECORD HouseNumber: integer; StreetName: String[20]; City: String[20]; State: String[2]; Zip: integer; end; EmployeeRecords = RECORD Name: String[40]; Address: StreetAddress; IDNumber: integer; Department: integer; Salary: real; end; VAR Employees: Array[1..100] of EmployeeRecords; BEGIN Employees[1].Name:= 'Fred Smith'; Employees[1].Address.HouseNumber:= 123; Employees[1].Address.StreetName:= 'Main St.'; Employees[1].Address.City:= 'Orlando'; Employees[1].Address.State:= 'FL'; Employees[1].Address.zip:= 12345; END. Read: remainder of Chap. 11 for next week