Data types - Datatypes Enumeratedtypes...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
Data types  Enumerated types   You can declare your own ordinal data types.  You do this in the type section of your  program: type      datatypeidentifier   =   typespecification ;   One way to do it is by creating an  enumerated type. An enumerated type  specification has the syntax:  ( identifier1 ,   identifier2 ,   ...   identifiern )
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Data types  Enumerated types   For example, if you wanted to declare  the months of the year, you would do a  type:  type     MonthType = (January, February,   March, April,           May, June, July, August, September,           October, November, December); 
Background image of page 2
Data types  Enumerated types   You can then declare a variable:  var     Month : MonthType;  You can assign any enumerated value  to the variable:  Month := January; 
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Data types  Enumerated types   All the ordinal functions are valid on the enumerated  type. ord(January) = 0, and ord(December) = 11.  A few restrictions apply, though: enumerated types  are internal to a program -- they can neither be read  from nor written to a text file. You must read data in  and convert it to an enumerated type. Also, the  idenfier used in the type (such as January) cannot be  used in another type.  One purpose of an enumerated type is to allow you,  the programmer, to refer to meaningful names for  data. In addition, enumerated types allow functions  and procedures to be assured of a valid parameter,  since only variables of the enumerated type can be  passed in and the variable can only have one of the  several enumerated values. 
Background image of page 4
Data types  Subranges   A subrange type is defined in terms of  another ordinal data type. The type  specification is: lowest_value   ..   highest_value   where  lowest_value   <   highest_value  and the  two values are both in the range of another  ordinal data type. 
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Data types  Subranges   For example, you may want to declare the  days of the week as well as the work week:  type     DaysOfWeek = (Sunday, Monday, Tuesday, Wednesday,                             Thursday, Friday, Saturday);     DaysOfWorkWeek = Monday. .Friday You can also use subranges for built-in  ordinal types such as char and integer. 
Background image of page 6
1-dimensional arrays   Suppose you wanted to read in 5000 integers  and do something with them. How would you  store the integers?  You could use 5000 variables, lapsing into:       aa, ab, ac, ad, . .. aaa, aab, . .. aba, . .. But this would grow tedious (after declaring 
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/02/2012 for the course CHEM E 101 taught by Professor Mr.yuswan during the Spring '11 term at Universitas Indonesia.

Page1 / 26

Data types - Datatypes Enumeratedtypes...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online