next up previous contents
Next: Concepts Up: Congregates Previous: How to submit?   Contents


Records

Arrays represent one of the two congregates that are useful in programming. As a quick reminder, an array contains multiple elements of the same type. This means it is impossible for an array to contain some integers, some real numbers and som booleans. Furthermore, each element in an array is selected by its index, which is an integer. In most languages, elements in an array must start with index 0 and use consecutive integers thereafter.

Sometimes, however, it is helpful to group items of different types together into a single unit. For example, consider a real student record. On a student record, the firstname, lastname and address are ``text'' fields. The GPA, however, is a real number. The student number is an integer field, while the birthdate is a data field. It is helpful to see the entire record as one single object sometimes. For example, it is convenient to say ``make a copy of Joe's student record''. The alternative is to specify making a copy of every field that applies to Joe, which is tedious and error prone.

This chapter discusses the general concept, syntax and uses of records in Pascal. Most of the conceptual discussions apply to Pascal and most other modern programming languages, while the syntax and sample programs are more Pascal specific.



Subsections
next up previous contents
Next: Concepts Up: Congregates Previous: How to submit?   Contents
Tak Auyeung 2003-12-03