100 likes | 318 Views
Ordinal Data Types. CSCE 110. Data Types. structured. simple. pointer. ordinal. real. array. record. set. file. predefined. programmer-defined. predefined. programmer-defined. integer. char. boolean. enumerated. subrange. text. Type Declarations. type name-1 = type-1 ;
E N D
Ordinal Data Types CSCE 110
Data Types structured simple pointer ordinal real array record set file predefined programmer-defined predefined programmer-defined integer char boolean enumerated subrange text
Type Declarations type name-1 = type-1; name-2 = type-2; . . . name-m = type-m;
Type Declaration Examples type filename_type = array[256]; logical_type = boolean; var filename: filename_type; p, q, r: logical_type;
Enumerated Type • Purposes • More _____________________ code • _______ prevention ( ident-1, ident-2, … ident-n )
Enumerated Type Example type daysOfWeek = (Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday ); var day:daysOfWeek;
Enumerated Type Example for day:=Sunday to Saturday do case day of Sunday: writeln('Sunday'); Monday: writeln('Monday'); Tuesday: writeln('Tuesday'); Wednesday: writeln('Wednesday'); Thursday: writeln('Thursday'); Friday: writeln('Friday'); Saturday: writeln('Saturday'); end
Ordinal Type Operations • Enumerated types, integer, char, & boolean • _____ • _____ • _____ • <, <=, =, >=, <>
Subrange Type • Purposes • _______ prevention • Generalization of _________________ type (i.e. simpler to write) first-value..last-value
Subrange Type Example type digit_type = '0'..'9'; capitalLetters_type = 'A'..'Z'; lowerCaseLetters_type = 'a'..'z'; var cents: 0..99; daysInMonth: 28..31; bigLetter: capitalLetters_type; smallLetter: lowerCaseLetters_type;