note_08 - ORDINAL TYPES A Type whose values are specified...

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

View Full Document Right Arrow Icon
141 ORDINAL TYPES A Type whose values are specified by a list is called an Ordinal Type. Integer – Char – Boolean Given a value( e.g. ‘D’ , 10 , False) in an ordinal type ,we can specify the one unique value which proceeds or follows the value. Real and String are NOT ordinal . For Letter := ‘A’ to ‘Z’ do write(Letter);
Background image of page 1

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

View Full DocumentRight Arrow Icon
142 Ordinal Functions 1. Pred (18) 17 Value Preceeding 2. Succ (18) 19 Value Succeeding 3. Pred (‘L’) k 4. Succ (‘b’) c
Background image of page 2
143 ord returns number indicating the ordinal position of the argument. Its collating value in the ASCII data set. charvar:= ‘D’; writeln ( ord (charvar) ); 68 chr returns the character which has the ordinal position of the argument. writeln ( chr (68) ); D
Background image of page 3

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

View Full DocumentRight Arrow Icon
144 Subrange Type It is an user-defined ordinal type . • We define a new user defined type whose valid values are a subrange of some ordinal type. •W e m u s t create a name for the new type. Type Clause - Type RatingScale = 1. .5 ; Type Name Subrange Values
Background image of page 4
145 ? – How much memory have we created ? Answer: None . We have created the Type Name Only . Var Response: RatingScale ; Response A variable which can hold only integer values 1 thru 5. Integer is the Host Type. The subrange 1-5 are Integer Values. Compiler Directive : { $ R + } will insure that you get an Error message if not store a 1 thru 5 value.
Background image of page 5

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

View Full DocumentRight Arrow Icon
146 DATA VALIDATION Type validscore = 0. .100; validgrade = ‘A’. .’F’; Var Score: integer; ScoreTest: validscore; LetterTest: validgrade; Score:=126; ScoreTest:=75; ScoreTest:=Score; Score:=ScoreTest; valid? valid? NO YES Readln (LetterTest); only accept ‘A’ thru ‘F’
Background image of page 6
147 Subrange Type 1. var score:0. .100; caplet:’A’. .’Z’ SHORT CUT WAY 2. Type Scorerange = 0. .100; CapLetters = ‘A’. .’Z’; var score: Scorerange; caplet: CapLetters; *NOTE : IF Need To Declare A Parameter As Having A Subrange Type – must create as in 2. You will need the TYPENAME to use when you are coding the Formal parameter that you are passing an ACTUAL parameter of TYPE NAME .
Background image of page 7

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

View Full DocumentRight Arrow Icon
148 Reasons For SubRange Type: 1. Help clarify use of certain variables 2. Permit the computer to Detect an out-of-range error when an assignment statement is used to assign a value to a sub-range variable
Background image of page 8
149 {$R+} – place where ______________ ?
Background image of page 9

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

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

This note was uploaded on 03/27/2008 for the course CPSC 110 taught by Professor Logan during the Spring '07 term at Texas A&M.

Page1 / 39

note_08 - ORDINAL TYPES A Type whose values are specified...

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

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